Thursday, February 24, 2011
Java interview questions
http://www.javabeat.net/articles/33-generics-in-java-50-1.html
what is the common practice you do to reduce bugs?
what do you do to write thread safe code?
WildCard
Wednesday, February 23, 2011
Wednesday, February 9, 2011
Tuesday, February 8, 2011
transient variable
A transient variable is a variable that may not be serialized.
A variable that won't be allowed for object serialisation. so that the state of the value will always be defaulted after the deserialisation.
serialization
When the resulting series of bits is reread according to the serialization format, it can be used to create a semantically identical clone of the original object
Serialization provides:
- a method of persisting objects which is more convenient than writing their properties to a text file on disk, and re-assembling them by reading this back in.
- a method of issuing remote procedure calls, e.g., as in SOAP
- a method for distributing objects, especially in software componentry such as COM, CORBA, etc.
- a method for detecting changes in time-varying data.
Monday, February 7, 2011
O/R mapping
mapping Object to Relational databases
The easiest mapping you will ever have is a property mapping of a single attribute to a single column.
Shadow information is any data that objects need to maintain, above and beyond their normal domain data, to persist themselves. This typically includes primary key information
One type of shadow information that I have not discussed yet is a boolean flag to indicate whether an object currently exists in the database.
A common practice is for each class to implement an isPersistent boolean fla that is set to true when the data is read in from the database and set to false when the object is newly created. ( or isLocal() )
--
Shadow information doesn’t necessarily need to be implemented by the business objects, although your application will need to take care of it somehow. For example, with Enterprise JavaBeans (EJBs) you store primary key information outside of EJBs in primary key classes, the individual object references a corresponding primary key object. The Java Data Object (JDO) approach goes one step further and implement shadow information in the JDOs and not the business objects. (Do, DoImpl)
nts at an important part of the O/R impedance mismatch between object technology and relational technology. Classes implement both behavior and data whereas relational database tables just implement data.
Sunday, February 6, 2011
interview questions : distributed sorting
Wednesday, February 2, 2011
Memory in Java
http://www.vogella.de/articles/JavaPerformance/article.html
In the heap the Java Virtual Machine (JVM) stores all objects created by the Java application, e.g. by using the "new" operator. The Java garbage collector (gc) can logically separate the heap into different areas, so that the gc can faster identify objects which can get removed
The memory for new objects is allocated on the heap at run time. Instance variables live inside the object in which they are declared.
--
Stack is where the method invocations and the the local variables are stored. If a method is called then its stack frame is put onto the top of the call stack. The stack frame holds the state of the method including which line of code is executing and the values of all local variables. The method at the top of the stack is always the current running method for that stack. Threads have their own call stack.
Runtime runtime = Runtime.getRuntime();
// Run the garbage collector
runtime.gc();
// Calculate the used memory
long memory = runtime.totalMemory() - runtime.freeMemory();