Translate

Thursday, December 27, 2012

Core Java Interview Question part-1


Q) What is difference between Java and C++?

A) 
(i) Java does not support pointers. Pointers are inherently insecure and troublesome. 
           Since pointers do not  exist in Java. 
 (ii) Java does not support operator overloading.
 (iii) Java does not perform any automatic type conversions that result in a loss of 
         precision
 (iv) All the code in a Java program is encapsulated within one or more classes. Therefore, 
         Java does not have  global variables or global functions.
 (v) Java does not support multiple inheritance.Java does not support destruction, but 
       rather, add the finalize()  function.
 (vi) Java does not have the delete operator. 
(vii) The << and >> are not overloaded for I/O operations

Q) Class & object?

    Class   à class is a blue print of an object
    Object  à instance of class.

Q) Object creation?

     Object is constructed either on a memory heap or on a stack.

Memory heap

generally the objects are created using the new keyword. Some heap memory is allocated to this newly created object. This memory remains allocated throughout the life cycle of the object. When the object is no more referred, the memory allocated to the object is eligible to be back on the heap.

Stack 

During method calls, objects are created for method arguments and method variables. These objects are created on stack.

Q) System.out.println()

     à println () is a methd of java.io.printWriter.
     à “out” is an instance variable of java.lang.System class.

Q) Transient & volatile

Transient --> The transient modifier applies to variables only, the object are variable will not persist. Transient variables are not serialized.
    Volatile --> value will be changed unexpectedly by the other part of the program, "it tells the compiler a variable    may change asynchronously due to threads"

No comments: