The IoT Academy Blog

20+ Core Java Interview Questions and Answers for Freshers and Experienced in 2023

  • Written By  

  • Published on December 8th, 2022

Table of Contents [show]

 

Introduction

 

Java is described as an object-oriented, general-purpose programming language. One primary reason for the vast number of beginners and experts in the programming domain is the career possibility that Java knowledge comes with.

Here are some core Java interview questions for 2023.

 

 

Q.1. State the differences between C++ and Java.

 

Ans. The differences between C++ and Java are listed below:

  • C++ is not platform-independent; the reason behind C++ programming is to write once and run anywhere. In comparison, because the byte code developed by the Java compiler is platform-independent and can run on any device, Java programs are written once and run around.
  • C++ is a programming language that runs on the basis of the C programming language. Mostly every high-level language is compatible with C++ and is incompatible with Java. Java is comparable to both C++ and C.
  • Java refers to a compiled and interpreted language, whereas C++ is only a compiled language. The source code is the executed output of a platform-independent byte code in Java. In C++, the source program collects the object code and then runs it to produce it.

 

Q 2. Discuss the differences between the Java platform and other platforms.

 

Ans: The difference between the Java platform and other platforms is that Java is a software-based platform, whereas other platforms may be hardware or software-based. Java is run on top of the other hardware platforms, whereas other platforms can only have hardware components.

 

 

Our Learners Also Read: What is Semaphore in Java and its Use?

 

 

Q 3. List the various access specifiers in Java.

 

Ans: In Java, access specifiers are the keywords that depict the access scope of a technique, class, or variable. There are four access specifiers in Java:-

 

Public The classes, methods, or variables are defined as the public that can be accessed by any class or method.

 

Protected is accessed by the same package, by the sub-class of this class of the same class.

 

Defaults are accessible within the package only. By default, all the classes, methods, and variables are in the default range.

 

Private The private class, methods, or variables defined as private are accessed simply within the same class.

 

 

Q 4. What are the features of the Java programming language?

 

Ans: In Java Programming Language, the significant features are:-

 

  • Java is a language considered easy to understand.
  • Java has a safety attribute that helps generate a virus-free and tamper-free system for the users.
  • OOPs stands for Object-Oriented Programming. OOP represents that everything is considered an object in Java.

 

 

Q5: Why are multiple inheritances not supported in Java?

 

Ans-Java supports multiple inheritances via interfaces merely. A class can execute any number of interfaces but can open only one class. In Java, multiple inheritances are not supported because they direct to a deadly diamond difficulty.

 

 

Q.6. What is garbage collection in Java?

 

Ans: Java garbage collection is an automated technique. The garbage collection execution lives in the JVM( Java Virtual Machine). Each JVM can execute garbage collection however it pleases; the only condition is that it meets the JVM specification. It suggests a rich and mature set of garbage collection possibilities.

 

 

Q. 7. Differentiate between instance and local variables.

 

Ans: Variables, for example, are declared within a class, and the range of variables is limited to a single object. A local variable can be anywhere inside a technique or a detailed code. Also, the scope is restricted to the code segment where the variable is executed.

 

 

Q.8. What is JDK? Mention the variants of JDK.

 

Ans: JDK stands for Java Development Kit. It is a blended package of JRE and developer instruments for developing Java applications and applets. The following variants of JDK:-

 

  • JDK Standard Edition
  • JDK Enterprise Edition
  • JDK Micro Edition

 

 

Q.9: What is a pointer? Does Java support a Pointer?

 

Ans: An arrow that enables to access the memory location using the address directly is called a pointer. Java does not have the concept of a pointer because inappropriate handling of pointers results in memory leaks and other related issues. It makes Java a more powerful language than C or C++.

 

 

Q. 10: What is polymorphism?

 

Ans. Polymorphism is the capability to achieve single tasks in multiple ways and is separated into two parts in Java: compile-time and runtime polymorphism.

  • Compile time, also called a static method, is a procedure in which the call during the overloading method is fixed concurrently with the compilation.
  • Runtime polymorphism, also called dynamic dispatch, has a requirement to support the overriding of methods. It is achieved during the runtime.

 

 

Q. 11. Explain multithreading in Java.

 

Ans: Multithreading is a programming trait that permits multiple tasks to operate simultaneously within a single program. In simple terms, it allows the concurrent execution of two or more parts of a program for maximum CPU utilization. Every program is called a thread. In Java, threads are light operations within a process. They operate in parallel and support the performance modification of any program.

 

 

Q. 12. In Java, how can we access some classes in another class?

 

Ans: There are two methods to access a class in another class:-

 

  • By using the fully qualified name: To access a class in a separate package, either we must use the fully qualified name of that class or we must import the package including that class.
  • By using the relative path, we can manipulate the path of the class connected to the package that consists of our class. It can be the same or a subpackage.

 

 

Q. 13. State the use of an interface in Java.

 

Ans: It achieves complete abstraction. Since Java does not endorse multiple inheritances in the case of classes, by using an interface, it can acquire multiple inheritances. It also achieves loose coupling and implements abstractions.

 

 

Q. 14. What is "public static void main" in Java?

 

Ans: This is the access modifier of the main method. It has to be public so that the Java runtime can perform this method. Determinate that if you cause any method non-public, then it’s not permitted to be accomplished by any program. So it implies that the main method has to be public.

 

 

Q. 15. Why is Java platform-independent?

 

Ans: At the time of execution, the Java compiler transforms the source code into a JVM-interpretable set of medium forms, termed byte code. It is unlike the collected code developed by other compilers and is non-executable. The Java virtual machine interpreter processes the non-executable code and runs it on any exact device. Hence, the platform dependence is removed.

 

 

Q. 16. What do you mean by data encapsulation?

 

Ans: Data encapsulation is the procedure of blending data into a single unit. It controls the data from being accessed by the user. We suppress the data variables inside the class and determine the access modifiers so that they are not unrestricted to other classes. Encapsulation mostly negotiates with data. It is acquired by declaring all the variables in the class as private and public methods.

 

 

Q. 17. What is the difference between System.err, System.out and System.in?

 

Ans: System.out and System.err present the monitor by default and thus can be used to send data or outputs to the monitor. System.out displays ordinary notices and results. System.err displays error notifications. System.in conveys the InputStream object, which by default symbolizes the standard input gadget, i.e., the keyboard.

 

 

Q. 18. Why is the main method static?

 

Ans: The main method is static because the object is not needed to reach the static method. If we make the main method non-static, the JVM will have to first develop its object before reaching the main() method, which will result in additional memory allocation.

 

 

Q. 19: What is the interface?

 

Ans: The interface is a blueprint for a class with static constants and abstract techniques. It achieves abstraction and multiple inheritances in Java. There can only be abstract methods in the Java interface. In simple words, interfaces can have abstract methods and variables.

 

 

Q.20. What is the goal of using JavaP?

 

Ans: The javap command disperses a class file. The javap command demonstrates information about the fields, methods, and constructors in a class file. Syntax: javap fully_class_name.

 

 

 

About The Author:

logo

Digital Marketing Course

₹ 9,999/-Included 18% GST

Buy Course
  • Overview of Digital Marketing
  • SEO Basic Concepts
  • SMM and PPC Basics
  • Content and Email Marketing
  • Website Design
  • Free Certification

₹ 29,999/-Included 18% GST

Buy Course
  • Fundamentals of Digital Marketing
  • Core SEO, SMM, and SMO
  • Google Ads and Meta Ads
  • ORM & Content Marketing
  • 3 Month Internship
  • Free Certification
Trusted By
client icon trust pilot
1whatsapp