Most of the time, the Interviewer is more interested in how you present it to the Interviewer in a practical and different approach rather than just answering straight and very short answers. The core java interview questions are listed below; you might understand them in a better way.
1. The primary difference between Java and C ++?
Answer: Here, the Interviewer doesn’t expect to answer in a theoretical way. He knows the bookish answer but to explain in a practical and understanding way depends upon you. But he expects the main points to be covered.
- C++ is platform-dependent, which means it can run only on one Operating System environment. While Java is platform-independent, it can run on all Operating systems.
- C++ is not portable. While Java is mobile since it converts code into bytecode, and bytecode is portable and can be executed on any platform.
- C++ supports method and operator overloading, while Java only supports method overloading.
- C++ has strong support for pointers, while Java has limited support.
- It doesn’t have in-built thread support, while Java has.
2. What is the meaning of Classloader?
Answer: In this question, the Interviewer is expected to explain the class loader, the typical definition. If you have some extra knowledge, then you might get brownie points.
Class loader in Java is a part of the JRE(Java runtime environment) that dynamically loads java classes into the java virtual machine (JVM) on demand.
Types of java class loader three.
- Bootstrap Class Loader – It loads JDK internal classes and typically loads rt.jar and other core classes, for example, Java and Lang package classes.
- Extensions Class Loader – It loads classes from the JDK extensions directory, usually the lib/ext. Directory of the JRE.
- System Class Loader –Loads classes from system classpath that can be set while invoking a program using -cp or -classpath command line options.
3. How is Java a platform independent?
Platform independent means the program’s execution is not restricted by the operating system installed; hence, we can execute the java program in any environment available.
How: Java is a platform-independent language because of the magic of Java which is bytecode.
When we execute the source code in Java, it generates the .class file, which contains the bytecodes. Bytecodes are interpreted by JVM, which is available with every type of OS we install.
On the other hand, the source code written in C or C++ gets converted into an object code that is machine and OS-dependent and hence is termed Platform dependent.
4. What is Dynamic polymorphism?
Dynamic polymorphism is the concept that makes the code flexible and extensible.
It is also called runtime polymorphism because the binding of the object to the function call happens at runtime when the object is instantiated.
In dynamic polymorphism, the reference type and object type are different. The reference variable is of the base class, and any derived class that extends the declared reference class can be assigned to the reference variable.
- What is the usage of the final keyword in Java?
The final keyword used in Java can be used in many contexts. A final can be a variable, class, or method.
If you make any variable final, the value of that variable cannot be changed at any cost (It acts as a constant).
You can declare or announce some or all of a class’s methods final. The final keyword for a method indicates that subclasses cannot override it. If you have a method that is critical and the implementation should not be changed by other subclasses which override it, then go for marking that method as final.
No other class can extend the final class by marking a class as final. It is practical, particularly when creating an immutable class like the String class.
The final keyword should not be called a constant.
- Who is the founder of Java?
Answer: Here, the Interviewer is testing your knowledge of Java.
Java was initially developed at Sun Microsystems, later acquired by Oracle by James Gosling, and released in 2005 as the core component at Sun Microsystems.
- Explain what string pool is in Java.
A string Pool is a part of memory space in heap memory. When you create a String object using a new Keyword, i.e., String strH=new String(“TestString”), the string object is created in Heap Memory. When You create a String object using literal, i.e., String strP=” TestString,” the string object is made in the String pool. You need to call stir. Intern () to add the thing to the String pool explicitly.
- What is the difference between overriding and overloading methods?
Overloading: When you have two or more methods in the same class with the same name but different signatures (ex: different params). You can consider the default constructor and another one with params as an example. Static binding
Overriding: When you have a superclass/interface with method A() and child classes that overrides the same method. (overrides means that every child class provides its proper implementation in the same way A(). Dynamic binding
- What is inheritance in Java?
Inheritance is one of the underpinnings of object-oriented programming.
It’s the ability of the class to allow “another class” to access its members. Here members could be instance variables and methods. The “another class” is called a subclass or child class. And the class from which “another class” got access is called a parent class or Super Class. Creating a superclass is called generalization, and creating a subclass is also known as specialization.
- What is the term “wrapper class” in Java?
The term “wrapper class” in Java refers to the classes representing the primitive types in Object form. For example, the class java. Lang. Integer wraps the primitive type int and Java. Lang. Double wraps, double. These classes allow primitives to be used where an Object is required, for instance, as a key to a Map or an element of a Collection.
Discover our Java training and certification programs, which Simplilearn’s experienced industry experts offer in real-time, if you are seeking in-depth knowledge of the Java programming language and information on how to become a certified professional developer. We recommend that you take a look at our Full Stack Java Developer Master’s Program.
The above listed basic and latest core interview questions from the Java interview. Simplilearn online learning is a platform that creates students to learn and grow. For more information, do connect with us.