Wednesday, March 26, 2008

Some more java interview questions

Is Vector is threadsafe ?

Ans : Yes, Vectors are threadsafe. Vectors are synchronized.


Why String objects are called immutable objects ?

String objects are called immutable because once you assign a value to a string object, you can never changes the value. String objects are immutable . String references are not.

If you redirect a String reference to a new String, the old String can be lost.

Can we override String methods ?

No...The String class is final—its methods can’t be overridden.

What is the difference between comparing two String objects and two StringBuffer objects using equals methods ?

String class overrides equal method of Object class but StringBuffer equals() is not overridden; it doesn’t compare values.

How many number of non-public class definition can a source file have
Unlimited
Can abstract class be instantiated

No.. abstract class cannot be be instantiated


What is a Java Virtual Machine (JVM)?


A Java Virtual Machine is a runtime environment required for execution of a Java application.Every Java application runs inside a runtime instance of some concrete implementation of abstract specifications of JVM.It is JVM which is crux of 'platform independent' nature of the language.

What is the difference between interpreted code and compiled code?


An interpreter produces a result from a program, while a compiler produces a program written in assembly language and in case of Java from bytecodes.The scripting languages like JavaScript,Python etc. require Interpreter to execute them.So a program written in scripting language will directly be executed with interpreter installed on that computer,if it is absent then this program will not execute.While in case of compiled code,an assembler or a virtual machine in case of Java is required to convert assembly level code or bytecodes into machine level instructions/commands.Generally, interpreted programs are slower than compiled programs, but are easier to debug and revise.

No comments: