Core JAVA Questions and Answers

Page 1

Showing 1 - 5 of 5 questions


1. What is the difference between JVM and JDK?


JVM stands for Java Virtual Machine. JVM acts as a run time engine to run Java applications. JVM is responsible for converting byte codes into machine readable codes. When you compile a Java program the output Java bytecode can then be executed by the any computer that has a native JVM.
While JDK stands for Java Development Kit. This is for development purpose and it provides all the tools, executables and binaries required to compile, debug and execute a Java Program. JVM handles the execution of the program and helps in coding machine independence program.

2. What is JVM (Java Virtual Machine)?


Java Virtual Machine (JVM) acts as a run time engine to run Java applications. JVM is responsible for converting byte codes into machine readable codes. When you compile a Java program the output Java bytecode can then be executed by the any computer that has a native JVM. Options like how much memory should we allocate to the JVM can be customized.

3. What is Java classloader?


A class loader is an object that is responsible for loading classes into java virtual machine (JVM). The class ClassLoader is an abstract class. Given the binary name of a class, a class loader should attempt to locate or generate data that constitutes a definition for the class. When a Java Class is compiled, it is transformed into bytecodes and stored as a .class file. When the program is executed, Java ClassLoader loads that class into memory.

4. What are the differences between Overloading and Overriding in Java?


Overloading is when you write two or more methods in one class with the same method name but with different parameters.
Overriding means writing two methods with the same method signature (name and parameters). One of the methods is in the parent class and the other is in the child class. Overriding allows a child class to override a specific implementation of a method that is already provided its parent class.
Differences:

1. Overloading is compile time activity while overriding is run-time activity.
2. You can overload a method in the same class, but you can only override a method in child classes. Inheritance is necessary for overriding.
3. Static methods can be overloaded. You can have more than one static method with the same name in a single class. But you cannot override a method which is declared as static.
4. Private and final methods can not be overridden but can be overloaded in Java.

5. What is the difference between StringBuffer and StringBuilder in Java?


1. StringBuffers are thread-safe. So it is save to use by multiple threads. StringBuilders are not safe for use by multiple threads.