Java is one of the most popular programming languages. It is a high-level, class-based, object-oriented programming language. It is used for development of web applications, including e-commerce sites, social media platforms, and enterprise-level systems. Java frameworks like spring boot are widely used in industry level software development. It is used in the top level companies like : Google, Amazon, PayPal, Airbnb, Uber, and Twitter. Let’s see top 5 interview questions asked on technical interviews :
Question 1 : What is the meaning of each public static void main(String[] args) ?
Answer : Each part of the public static void main(String[] args) declaration in Java serves a specific purpose:
- public : public keyword indicates that the method main is accessible from outside the class. It allows the JVM to call this method to start the execution of the program.
- static : static keyword allows the main method to be called without creating an instance of the class. It means the method belongs to the class itself, not to instances of the class.
- void : This keyword specifies that the main method does not return any value. It means the method will not produce a result when it finishes executing.
- main : This is the name of the method. In Java, the main method serves as the entry point for a program. It is the method that the JVM looks for when starting the execution of a Java program.
- String[] args : This part of the declaration is called the parameter list. It specifies the parameters that the main method accepts. In this case, String[] args indicates that the main method accepts an array of strings as arguments. These arguments can be passed to the program from the command line when it is executed. The name args can be any valid identifier, but it is a convention to use args to represent command-line arguments.
Question 2 : Why Java is considered as platform independent language ?
Answer : Java is considered platform-independent primarily because two reasons :
- Bytecode:
When you compile a Java source file, it’s not compiled directly into machine code for a specific platform. Rather, it’s compiled into bytecode, which is a platform-independent intermediate representation of the program. - Java Virtual Machine (JVM):
The JVM is an essential component of Java’s platform independence. It’s a runtime environment that interprets and executes Java bytecode. Each platform (Windows, Linux, macOS, etc.) has its own implementation of the JVM, but they all interpret the same bytecode in the same way. This means that once a Java program is compiled into bytecode, it can run on any platform with a compatible JVM without modificationJava uses a special kind of code called bytecode, and a tool called the Java Virtual Machine (JVM). These help Java programs work on any type of computer without needing to change the code. This is why people say you can “write once, run anywhere” in Java. It’s one big reason why Java is so popular for making all sorts of software, like websites, business programs, and phone apps.
Question 3 : What is JVM ?
How JVM Works ?
Question 4 : Why is Java not a pure object oriented language?
Answer : Java supports primitive data types like byte, boolean, char, short, int, float, long, and double, which are used for simple values and operations.
For instance:
int age = 25; // integer boolean isStudent = true; // boolean char grade = 'B'; // character double salary = 40000.30; // double
Despite this support for basic data types, Java also allows the creation and manipulation of objects, like in the following example:
String name = "Arjun Gautam"; // string object List<String> cars = new ArrayList<>(); // list object
This combination of primitive data types and objects shows Java’s versatility, but it means it’s not purely object-oriented.
Question 5 : What are the main features of OOPs? How you can implement using Java ?
Answer : The main features of Object-Oriented Programming (OOP) are:
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction