1. What do you understand by Java?
- Java is an object-oriented computer language.
- It is a high-level programming language developed by James Gosling in Sun Microsystem in 1995.
- Java is a fast, secure and reliable language used for many games, devices and applications.
2. Outline the major Java features.
- Object-Oriented – java is based on object-oriented programming where the class and methods describe about the state and behavior of object.
- Portable – Java program gets converted into Java Byte Codes that can be executed on any platform without any dependency.
- Platform independent – java works on “write once and run anywhere” as it supports multiple platforms like Windows, Linux, Mac, Sun Solaris, etc.
- Robust – Java has a strong memory management as there is no pointer allocations. It has automatic garbage collection that prohibits memory leaks.
- Interpreted – java compiler converts the codes into Java Byte Codes which are then interpreted and executed by Java Interpreter.
3. What do you mean by Object?
An object consists of methods and class which depict its state and perform operations. A java program contains a lot of objects instructing each other their jobs. This concept is a part of core java.
4. What is class in Java?
Java encapsulates the codes in various classes which define new data types. These new data types are used to create objects.
5. Differentiate between JDK, JRE and JVM.
JVM stands for Java Virtual Machine which provides runtime environment for Java Byte Codes to be executed.
JRE (Java Runtime Environment) that includes sets of files required by JVM during runtime.
JDK (Java Development Kit) consists of JRE along with the development tools required to write and execute a program.
6. Define Inheritance.
Java includes the feature of inheritance which an object-oriented programming concept. Inheritance lets a derived class to inherit the methods of a base class.
7. Explain method overloading.
When a Java program contains more than one methods with the same name but different properties, then it is called method overloading.
8. Compare Overloading and Overriding.
Overloading refers to the case of having two methods of same name but different properties, but overriding occurs when there are two methods of same name and properties, but one is in child class and one is in parent class.
9. Explain the creation of a thread-safe singleton in Java using double-checks locking
Singleton is created with double checked locking as before Java 5 acts as an broker and it’s been possible to have multiple instances of Singleton when multiple threads creates an instance of Singleton at the same time. Java 5 made it easy to create thread-safe Singleton using Enum. Using a volatile variable is essential for the same.
10. Can we execute any code, even before the main method? Explain?
Yes, We can execute any code, even before the main method. We are using a static block of code in the class when creating the objects at load time of class. Any statements within this static block of code will get executed one time while loading the class, even before the creation of objects in the main method.
11. Are constructors inherited? Can a subclass call the parent's class constructor?
We cannot inherit a constructor. We create an instance of a subclass using a constructor of one of its superclass. Because override the superclass constructor is not our wish so that, we override a superclass constructor, then we destroy the encapsulation abilities of the language.
12. Define JSON?
13. Define content negotiation?
If we have visited website to searching the information, we will get the information in different languages and in different formats when a client makes an HTTP request to a server, the client can also specify the media types here. The client can specify what it can accept back from the host and on the basis of availability the host will return to the client. This is known as content negotiation because client and server negotiated on the language and format of the content to be shared.
14. Can we import same package/class two times? Will the JVM load the package twice at runtime?
A package or class can be inherited multiple times in a program code. JVM and compiler will not create any issue. Moreover JVM automatically loads the class internally once regardless of times it is called in the program.
15. Java doesn't use pointers. Why?
Pointers are susceptible and slight carelessness in their use may result in memory problems and hence Java basically manages their use.