Friday, March 4, 2011

Java Interview Questions-I

Question: What is JVM
Answer: When we install a java package. It contains 2 things

* The Java Runtime Environment (JRE)
* The Java Development Kit (JDK)

The JRE provides runtime support for Java applications. The JDK provides the Java compiler and other development tools. The JDK includes the JRE.

Both the JRE and the JDK include a Java Virtual Machine (JVM). This is the application that executes a Java program. A Java program requires a JVM to run on a particular platform


Question: What is the main difference between Java platform and other platforms?
Answer: The Java platform differs from most other platforms in that it's a software-only platform that runs on top of other hardware-based platforms. The Java platform has two components:

1. The Java Virtual Machine (Java VM)
2. The Java Application Programming Interface (Java API)


Question: What is the Java Virtual Machine?
Answer: The Java Virtual Machine is a software that can be ported onto various hardware-based platforms.

Question: What is the Java API?
Answer: The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.


Question: Why do we need public static void main(String args[]) method in Java?
Answer: We need
public: The method can be accessed outside the class / package
static: You need not have an instance of the class to access the method
void: Your application need not return a value, as the JVM launcher would return the value when it exits
main(): This is the entry point for the application

Question: What is the difference between “= =” and “equals()”?
Answer: “= =” does shallow comparison, It retuns true if the two object points to the same address in the memory, i.e if the same the same reference
“equals()” does deep comparison, it checks if the values of the data in the object are same

Question: What would you use to compare two String variables - the operator == or the method equals()?
Answer: I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object


Question: What is an abstract method ?
Answer:An abstract method is a method that don't have a body. It is declared with modifier abstract.

Question: What is the difference between constructor and method?
Answer: Constructor will be automatically invoked when an object is created whereas method has to be called explicitly. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

Question: What is the difference between parameters and arguments?
Answer: While defining method, variables passed in the method are called parameters. While using those methods, values passed to those variables are called arguments.

Question: What is the difference between Overloading and Overriding?
Answer: Overloading : Reusing the same method name with different arguments and perhaps a different return type is called as overloading
Overriding : Using the same method name with identical arguments and return type is know as overriding

No comments:

Post a Comment