Your Ad Here

Wednesday, January 14, 2009

Core Java Interview Questions and Answers

What are the most important features of Java?

Java is object oriented, platform independent,secure,robust,simple,etc


Which one of them do you consider the best feature of Java?

Platform independence.


What do you mean by platform independence?

Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).


What is byte code?

Byte code is a set of instructions generated by the compiler. JVM executes the byte code.


How does Java acheive platform independence?

A Java source file on compilation produces an intermediary .class rather than a executable file. This .class file is interpreted by the JVM. Since JVM acts as an intermediary layer.


What is a JVM?

JVM is Java Virtual Machine which is a run time environment for the compiled java class files.


Are JVM's platform independent?

JVM's are not platform independent. JVM's are platform specific run time implementation provided by the vendor. A Windows JVM cannot be installed in Linux.


Who provides the JVM?
Any software vendor can provide a JVM but it should comply to the Java langauge specification.


What is the difference between a JDK and a JVM?

JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.


What is a pointer and does Java support pointers?

Pointer is a reference handle to a memory location. Improper handling of pointers leads to memory leaks and reliability issues hence Java doesn't support the usage of pointers.


How is an object reference different from a pointer?

Both object reference and pointer point to the memory location of the object. You can manipulate pointers but not object references.


Does Java support multiple inheritance?

Java doesn't support multiple inheritance.


Why Java doesn't support multiple inheritance?

When a class inherits from more than class, it will lead to the diamond problem - say A is the super class of B and C & D is a subclass of both B and C. D inherits properties of A from two different inheritance paths ie via both B & C. This leads to ambiguity and related problems, so multiple inheritance is not allowed in Java.


Is Java a pure object oriented language?

Java is a pure object oriented language. Except for the primitives everything else are objects in Java.


What is the difference between Path and Classpath?

Path and Classpath are operating system level environment variales. Path is used define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.


Why does Java not support operator overloading?

Operator overloading makes the code very difficult to read and maintain. To maintain code simplicity, Java doesn't support operator overloading.