The Java Monologues [☝]

Saturday, May 04, 2013

I've been programming professionally in the Java Programming language for the past three years, but still there are aspects of my work that seems unfamiliar to me. I would be listing down below some concepts that I wanted to learn more about this OOP language (and if I mentioned something wrong, please do correct me!).

  • The purpose of implementing IClusterable and Serializable interfaces in Model objects (and even in forms)
We declare them Serializable because we want to keep the values of these variables in Forms as long as the session is alive. In some web pages when you press the Back button of the browser, the values that you input in the form is still there. What Serializable does is that it saves the values in a compressed file (I'm just not sure where this file is located) and the page just accesses it once the form is loaded again.

As of now, I still have to research the IClusterable part.

  • The differences of using protectedpublicprivate, and default Java classes/methods
This concept is best illustrated by this diagram (credits to this):

Modifier    | Class | Package | Subclass | World
————————————+———————+—————————+——————————+———————
public      |  ✔    |    ✔    |    ✔     |   ✔
————————————+———————+—————————+——————————+———————
protected   |  ✔    |    ✔    |    ✔     |   ✘
————————————+———————+—————————+——————————+———————
no modifier |  ✔    |    ✔    |    ✘     |   ✘
————————————+———————+—————————+——————————+———————
private     |  ✔    |    ✘    |    ✘     |   ✘

public - visible to any class
no modifier (default) - visible within its own package only
private - visible within its own class only
protected -  visible within its own package and to its subclasses in another package

These access level modifiers exist in Java to eliminate misuse of variables in classes.


  • What's the difference between a session id and a cookie? (credits to here)
A session is a store of data on the server containing state information on a user. A particular sessions is identified by its session id, ideally a large (i.e. unguessable) random number. For example, the session could hold a user's shopping cart.
A cookie is also a store. To create a cookie, the server sends a HTTP header to the client (i.e. the web browser). If the client supports and accepts the cookie, the cookie will be sent back to the server along with every request made to the server.
Cookies are often used to store a session id, binding the session to the user.

  • Implements and Extends declarations, Interface and Abstract classes
Implements is used for interfaces which means that that class is required to override the methods of that interface. You can implement multiple interfaces in a class

Extends means that you are making that class a subclass of that class, inherting all its variables and methods. You can extend one class only. 

The difference between an interface and an abstract class is that in an interface, the class that implements it is required to override all the methods of that interface. Meanwhile in implementing an abstract class, you can just override selected methods. Also, an abstract class can be extended, but not instantiated in a class.

  • Definition of Objects, and the Foundations of Object-Oriented Programming (OOP) (credits to this)
Objects are the representation of concepts in OOP. Objects interact with each other in designing logic for applications. The four foundations of OOP are Inheritance, Polymorphism, Abstraction, and Encapsulation.


  • What is a class?
A class is a blueprint of an object, which contains its qualities (variables) and its behaviours (methods).


  • How to make an infinite loop using a for loop: 
for ( ; ; ){}
  • The Model-View-Controller Architecture Concept
Model - database
View - User Interface
Controller - Logic

  • Java Collections Framework: Differences of Set, List, and Map (credits to this)
Set - unordered collection of unique objects (i.e. LinkedHashSet, TreeSet, HashSet)
List - ordered and indexed collection that can contain duplicates (i.e. ArrayList, LinkedList); it also allows null elements
Map - data structure based on key value pairing and hashing; keys must be unique, regardless if they contain duplicate values; it allows at most one null key (i.e. HashMap, HashTable, Treemap)
  • Differences of equals and ==
The equals method is recommended to use for Objects and == comparator is for primitive data types.


  • The essence of synchronization
This is used in implementation of threads, especially if the method does modification in database values to ensure consistency of data. 


  • Are Strings mutable or immutable?
Strings are immutable, because it actually cannot be instantiated. Whenever a String is assigned a new value, the old String is destroyed and a new String Object is declared containing the new value. 


  • Pass-By-Reference and Pass-By-Value
Pass-By-Reference is always implemented by Objects, while Pass-By-Value is for primitive data types. Read here for more details.



Suddenly, I had this urge to earn a Java certification in the future (is it really worth it though?). I'd work harder from now on.



  • Share:

You Might Also Like

0 (mga) komento

trazy.com