Core java interview questions and answers for experienced professionals LEARNOVITA

[30+] Core Java Interview Questions

Last updated on 07th Dec 2022, Blog, Interview Question

About author

Sanjay (Sr Big Data DevOps Engineer )

Highly Expertise in Respective Industry Domain with 7+ Years of Experience Also, He is a Technical Blog Writer for Past 4 Years to Renders A Kind Of Informative Knowledge for JOB Seeker

(5.0) | 13265 Ratings 1691

1. What are the differences between a C++ and Java?


Concept: C++ is not a platform-independent; principle behind a C++ programming is “write once, compile anywhere.”In contrast, because the byte code generated by a Java compiler is platform-independent, it can run on any machine, Java programs written once and run everywhere.

Languages are Compatibility: C++ is a programming language that is based on a C programming language. Most other high-level languages are compatible with a C++.Most of languages of Java are incompatible. Java is a comparable to those of C and C++.

Interaction with a library: It can access native system libraries directly in a C++. As a result, it’s better for a programming at the system level.Java’s native libraries do not provide a direct call support. And can use a Java Native Interface or access the libraries.

Characteristics: C++ distinguishes itself by having a features that are similar to procedural and object-oriented languages. The characteristic that sets a Java apart is automatic garbage collection. Java doesn’t support a destructors at the moment.

The semantics of a type: Primitive and object types in a C++ have the same kind of semantics. The primitive and object and classes of Java, on a other hand, are not consistent.

2. List the features of a Java Programming language?


Easy: Java is the language that is considered simple to learn. One fundamental concept of an OOP Java has a catch to understand.

Secured Feature: Java has a secured feature that helps to develop a virus-free and tamper-free system for users.

OOP: OOP stands for an Object-Oriented Programming language. OOP signifies that, in Java, everything is a considered an object.

Independent Platform: Java is not compiled into the platform-specific machine; instead, it is compiled into a platform-independent bytecode. This code is interpreted by a Virtual Machine on which the platform runs.

3. What do get in a Java download file? How do they are differ from the one another?


    Abbreviation for a JavaDevelopment Kit. Abbreviation for a Java Runtime Environment.
    JDK is dedicated kit for the solely software development. JRE is the set of software and library designed for an executing Java Programs.
    Unlike JVM, JDK is a Platform Dependent. Unlike JVM, JRE is also a Platform Dependent.
    JDK package is a set of tools for the debugging and Developing. JRE Package is one that only supports a files and libraries for the runtime environment .
    JDK package will be provided with the installer file. JRE Package does not get installer but has only a runtime environment.

4. What is ClassLoader?


A classloader in Java is the subsystem of Java Virtual Machine, dedicated to a loading class files when a program is executed; ClassLoader is a first to load the executable file.Java has a Bootstrap, Extension, and an Application classloaders.

5. What are the Memory Allocations available in a JavaJava?


  • Class Memory.
  • Heap Memory.
  • Stack Memory.
  • Program Counter-Memory.
  • Native Method Stack Memory.

6. What are the differences between the Heap and Stack Memory in Java?


Stack memory in a data structures is the amount of memory allocated to every individual programme. It is a fixed for memory space. Heap memory, in contrast, is portion that was not assigned to a Java code but will be available for use by Java code when it is required, which is generally during a program’s runtime.

7. Will the program run if write a static public void main?


Yes, a program will successfully execute if written so. Because, in a Java, there is no specific rule for order of specifiers.

8. What is the default value stored in a Local Variables?


Neither a Local Variables nor any primitives and Object references have any default value stored in them.

9. Explain the expected output of a following code segment?


  • public class Simplilearn
  • {
  • public static void main (String args[])
  • {
  • System.out.println(100 + 100 +“Simplilearn”);
  • System.out.println(“E-Learning Company” + 100 + 100);
  • }
  • }

The answers for a two print statements are as :

  • 200Simplilearn
  • E-Learning Company100100

10. What is Association?


An Association can be explained as a relationship that has no ownership over another. For example, a person can be associated with the multiple banks, and a bank can be related to a various people, but no one can own other.

11. What is mean by aggregation?


The term aggregation refers to a relationship between two classes best described as a “whole/part” and “has-a” relationship. This kind is most specialized version of an association relationship. It contains a reference to another class and is said to have a ownership of that class.

12. Define Copy Constructor in a Java?


A Copy Constructor in a Java is a constructor that initializes an object through the another object of the same class.

13. What is Marker Interface?


An empty interface in a Java is referred to as a Marker interface. Serializable and Cloneable are some famous examples of a Marker Interface.

14. What is a Object Cloning?


An ability to recreate an object entirely similar to the existing object is known as Object Cloning in Java. Java offers a clone() method to clone a current object offering a same functionality as the original object.

15. Can Java be said to be a complete object-oriented programming language?


No, a Java cannot be treated as complete object-oriented programming language.

16. What is object-oriented paradigm?


A Paradigm that is based on a concepts of “Objects.” It contains a data and code. Data that is in form of fields, and regulation, that is in the form of procedures. The exciting feature of this paradigm is that an object’s procedures can access and often modify a data fields themselves.

17. Define a Wrapper Classes in Java?


In Java, when declare a primitive datatypes, then Wrapper classes are responsible for a converting them into the objects(Reference types).

18. What is singleton class in a Java? And How to implement singleton class?


A class that can possess the only one object at a time is called a singleton class. To implement singleton class given steps are to be followed:

  • Make sure that a class has only one object.
  • Give a global access to that object.

19. Define a package in Java?


The package is a collective bundle of the classes and interfaces and also necessary libraries and JAR files. The use of packages helps in a code reusability.

20. Can implement pointers in Java Program?


Java Virtual Machine takes care of a memory management implicitly. Java’s primary motto was to maintain programming simple. So, accessing memory directly through the pointers is not a recommended action. Hence, pointers are eliminated in a Java.

21. Differentiate between a instance and local variables?


  • For instance, variables are declared as inside a class, and scope of variables in a javascript is limited to only specific object.
  • A local variable can be anywhere inside the method or a specific block of code. Also, a scope is limited to the code segment where variable is declared.

22. Explain a Java String Pool?


A collection of strings in a Java’s Heap memory is referred to as a Java String Pool. In case try to create the new string object, JVM first checks for presence of the object in a pool. If available, the same object reference is shared with variable, else a new object is to be created.

23. What is Exception?


An Exception handling in a Java is considered an unexpected event that can disrupt a program’s normal flow. These events can be fixed through a process of an Exception Handling.

24. What is a final keyword in Java?


The term final is a predefined word in a Java that is used while declaring values to the variables. When a value is declared using a final keyword, then variable’s value remains constant throughout a program’s execution.

25. What happens when a main() isn’t declared as static?


When the main method is not declared as a static, then the program may be compiled correctly but ends up with the severe ambiguity and throws run time error that reads “NoSuchMethodError.”

26. What is a JDK? Mention the variants of a JDK?


JDK is abbreviation for a Java Development Kit. It is the combined Package of JRE and Developer tools used for a designing Java Applications and Applets.JDK Standard Edition:

  • JDK Enterprise Edition.
  • JDK Micro Edition.

27. What is the difference between the JDK, JRE, and JVM?


  • JVM has a Just in Time (JIT) compiler tool that converts all Java source code into a low-level compatible machine language. Therefore, it runs faster than a regular application.
  • JRE has a class libraries and the other JVM supporting files. But it doesn’t have any tool for a java development such as compiler or debugger.
  • JDK has tools that are need to write Java Programs and uses JRE to execute them. It has compiler, Java application launcher, and an applet viewer.

28. What is JIT compiler?


JIT compiler refers to a Just in Time compiler. It is the simplest way of executing a computer code that takes in compilation during the execution of the program rather than before performance. It commonly uses a bytecode translation to machine code. It is then executed directly.

29. What are Brief Access Specifiers and the Types of Access Specifiers?


Access Specifiers are predefined keywords used to help a JVM understand the scope of variable, method, and class.Public Access Specifier:

  • Private Access Specifier .
  • Protected Access Specifier .
  • Default Access Specifier.

30. How many types of a constructors are used in Java?


There are two types of constructors in a Java:

Parameterized Constructors: Parameterized constructor accepts a parameters with which users can initialize an instance variables. Users can initialize a class variables dynamically at time of instantiating the class.

Default constructors: This type doesn’t accept at any parameters; rather, it instantiates a class variables with their default values. It is used mainly for the object creation.

31. Can a constructor return value?


Yes, A constructor can return value. It replaces a class’s current instance implicitly; and cannot make a constructor return the value explicitly.

32. Explain ‘this’ keyword in a Java?


The term “this” is a specific keyword designated as reference keyword. The “this” keyword is used to refer to a current class properties like method, instance, variable, and constructors.

33. Explain ‘super’ keyword in a Java?


The term “super” is a specific keyword designated as reference keyword. The “super” keyword refers to an immediate parent class object.

34. Explain a Method Overloading in Java?


The process of creating a multiple method signatures using one method name is called a Method Overloading in Java. Two ways to achieve a method overloading are:

  • Varying a number of arguments.
  • Changing a return type of the Method .

35. Can we overload static method?


No, Java does not support a Overloading of a static method. The process would throw the error reading “static method cannot be referenced.”

36. Define a Late Binding?


Binding is a process of unifying a method call with the method’s code segment. Late binding happens when method’s code segment is unknown until it is called during a runtime.

37. Define a Dynamic Method Dispatch?


The Dynamic method dispatch is the process where the method call is executed during a runtime. A reference variable is used to call super-class. This process is also known as a Run-Time Polymorphism.

38. Why is delete function faster in a linked list than an array?


Delete Function is a faster in linked lists in Java as the user needs to make a minor update to a pointer value so that the node can point to next successor in the list.

39. Give a briefing on a life cycle of a thread?


  • New Born State
  • Runnable State
  • Running State
  • Blocked State
  • Dead State

40. Explain difference between >> and >>> operators?


Although they both look similar, there is massive difference between both:

  • >> operator does a job of right shifting a sign bits.
  • >>> operator is used in a shifting out of zero-filled bits.

41. Brief life cycle of an applet?


  • Initialization
  • Start
  • Stop
  • Destroy
  • Paint

42. Why are generics used in a Java Programming?


Compile-time type safety is provided by a using generics. Compile-time type safety allows users to the catch unnecessary invalid types at compile time. Generic methods and classes help programmers specify the single method declaration, set of related methods, or related types with an available in class declaration.

43. Explain an Externalizable interface?


The Externalizable interface helps with a control over process of a serialization. An “externalisable” interface incorporates a readExternal and writeExternal methods.

44. What is a Daemon Thread?


The Daemon thread can be explained as a thread with the least priority. This Daemon thread is designed to run in a background during the Garbage Collection in a Java.The setDaemon() method creates the Daemon thread in Java.

45. Explain a term enumeration in Java?


Enumeration or enum is interface in Java. Enum allows a sequential access of the elements stored in the collection in Java.

46. Why is a Java is Dynamic?


Java is designed to an adapt to an evolving environment. Java programs includes the large amount of runtime information that is used to resolve access to the objects in real-time.

47. Can run a code before executing a main method?


Yes, can execute a any code, even before a main method will be using a static block of code when creating a objects at the class’s load time. Any statements within this static block of code will get executed at a once while loading the class, even before creating a objects in the main method.

48. How many times is a finalize method called?


The finalize method is a called Garbage collector. For an every object, the Garbage Collector calls a finalize() method just for one time.

49. Can “this” and “super” keywords be used to together?


No, “this” and “super” keywords should be used in a first statement in the class constructor:

  • public class baseClass {
  • baseClass() {
  • super();
  • this();
  • System.out.println(” baseClass object is created”);
  • }
  • public static void main(String []args){
  • baseClass bclass = new baseClass();
  • }
  • }

50. What is JSP page?


JSP is abbreviation for a Java Servlet Page. The JSP page consists ofa two types of text:

  • Static Data
  • JSP elements

51. What is a JDBC?


  • JDBC is an abbreviation for a Java Database Connector.
  • JDBC is abstraction layer used to establish a connectivity between an existing database and Java application.

52. Explain different directives in JSP?


Directives are instructions processed by a JSP Engine. After a JSP page is compiled into the Servlet, Directives set page-level instructions, insert an external files, and explain a customized tag libraries. Directives are defined using a symbols below:

  • start with “< %@" and end with "% >”

The various types of a directives are shown:

Include directive: It includes file and combines a content of the whole file with currently active pages.

Page directive: Page Directive explains a specific attributes in the JSP page, like a buffer and error page.

Taglib: Taglib declares the custom tag library, which is used on a page.

53. What are observer and observable classes?


  • Objects that an inherit the “Observable class” take care of list of “observers.”
  • When an Observable object a gets upgraded, it calls update() method of each of its in observers.
  • After that, it notifies all observers that there is a change of a state.
  • The Observer interface gets an implemented by a objects that observe Observable objects.

54. What is a Session Management in Java?


A session is essentially explained as the random conversation’s dynamic state between a client and the server. The virtual communication channel includes a string of responses and requests from the both sides. The popular way of implementing a session management is establishing a session ID in a client’s communicative discourse and the server.

55. Briefly explain a term Spring Framework?


Spring is an essentially defined as an application framework in a Java and inversion of a control containers for Java. The spring framework creates enterprise applications in a Java. Especially useful to keep to mind that the spring framework’s central features are an essentially conducive to any of Java application.

56. How to handle an exceptions in a Spring MVC Framework?


Exception handler method: In this kind of an exception handling, the user will get @ExceptionHandler annotation type used to annotate a method to handle an exceptions.

XML Configuration: The user can used the SimpleMappingExceptionResolver bean in a Spring’s application file and map the exception.

57. What is a JCA in Java?


  • Java Cryptography Architecture gives a platform and offers an architecture and application programming interfaces that enable a decryption and encryption.
  • Developers use a Java Cryptography Architecture to combine application with a security applications. Java Cryptography Architecture helps in implementing a third party security rules and regulations.
  • Java Cryptography Architecture uses a hash table, encryption message digest, etc. to implement a security.

58. Explain JPA in a Java?


  • Java Persistence API.
  • Query Language.
  • Java Persistence Criteria API.
  • Object Mapping Metadata.

59. Explain the different authentications in a Java Servlets?


Authentication options are available in a Servlets: There are 4 different options for authentication in a servlet:

Basic Authentication: Usernames and passwords are given by a client to authenticate the user.

Form-based an authentication: In this, the login form is made by a programmer by using HTML.

Digest Authentication: It is similar to a basic authentication, but the passwords are encrypted using a Hash formula. Hash Formula makes a digest more secure.

Client certificate Authentication: It requires that each client accessing a resource has a certificate that it sends to an authenticate itself. Client Authentication requires SSL protocol.

60. Explain a FailFast iterator and FailSafe iterator along with the examples for each?


  • FailFast iterators and FailSafe iterators are used in a Java Collections.
  • FailFast iterators do not allow the changes or modifications to a Java Collections, which means they fail when latest element is added to the collection or an existing element gets removed from a collection. The FailFast iterators tend to fail and throw an exception called a Concurrent Modification Exception.
  • Ex: Array List, HashMap
  • Whereas, on other hand, FailSafe iterators allow the changes or modifications to be done on a Java Collections. It is possible, as a FailSafe iterators usually operate on a cloned copy of the collection. Hence, they do not throw the any specific exception.
  • Ex: CopyOnWriteArrayList

61. How do reverse a string?


  • package simplilearnJava;
  • public class StringReverse {
  • public static void main(String args[]) {
  • String str = “Simplilearn”;
  • String reverse = new StringBuffer(str).reverse().toString();
  • System.out.printf(“Actual a Word %s, Word after a reversing %s”str, reverse);
  • }
  • public static String reverse(String source) {
  • if (source == null || source.isEmpty()) {
  • return source;
  • }
  • String reverse = “”;
  • For (int i = source.length() – 1; i >= 0; i–) {
  • reverse = reverse + source.charAt(i);
  • }
  • return reverse;
  • }
  • }
  • Expected Output:
  • An Actual Word: Simplilearn, Word after a reversing nraelilpmiS

62. Explain about a Map and its types?


Map cares about an unique identifier. can map a unique key to the specific value. It is key/value pair. And can search a value, based on the key. Like the set, a map also uses the “equals ( )” method to find whether two keys are same or different.

63.What is ‘IS-A ‘ relationship in OOPs Java?


‘IS-A’ relationship is related to an Inheritance property of OOPs Java. It is a kind of a parent-child relationship that is established between the two classes.

64.How does Java enable a high performance?


Java uses a Just In Time compiler to enable a high performance. It is used to convert an instructions into bytecodes.

65. Name the Java IDE’s?


Eclipse and NetBeans are IDE’s of JAVA.

66. What is mean by Constructor?


  • When a new object is created in program a constructor gets invoked corresponding to a class.
  • The constructor is method which has a same name as the class name.
  • If a user doesn’t create constructor implicitly a default constructor will be created.
  • The constructor can overloaded.
  • If user created a constructor with a parameter then should create a another constructor explicitly without a parameter.

67. What is difference between a System.out, System.err, and


System.out and System.err represent a monitor by default and thus can be used to send data or results to a monitor. System.out is used to display normal messages and results. System.eerr is used to display an error messages. represents InputStream object which by default represents a standard input device, i.e., keyboard.

68. Could provide some implementation of a Dictionary having large number of words?


The simplest implementation that can be given is that of List wherein one can place ordered a words and perform a Binary search. The other implementation with better search a performance is HashMap where the key is used as a first character of the word and the value as a LinkedList.

69. What are OOPs concepts?


  • Inheritance
  • Encapsulation
  • Polymorphism
  • Abstraction
  • Interface

70. What is a Polymorphism?


Polymorphism means a many forms.A single object can refer to a super-class or sub-class depending on a reference type which is called polymorphism.

71. What is meant by an Exception?


  • An Exception is a problem that can occurred during the normal flow of an execution. A method can throw exception when something wails at runtime. If that exception couldn’t be handled, then execution gets a terminated before it completes a task.
  • If handled the exception, then a normal flow gets continued. Exceptions are subclass of java.lang.Exception.

72. Explain a Priority Queue?


  • Linked list class has been enhanced to an implement the queue interface. Queues can be handled with the linked list. The purpose of a queue is a “Priority-in, Priority-out”.
  • Hence elements are ordered in either naturally or according to a comparator. The elements of ordering represents their relative priority.

73. A single try block and a multiple catch blocks can co-exist in Java Program. Explain?


One or more catch blocks can follow try block. Every catch block must have a unique exception handler. So, if want to perform a multiple tasks in response to a various exceptions, use a Java multi-catch block.

74. Do final, finally and finalize a keywords have the same function?


  • No, final, finally and finalize keywords have a different functionalities.
  • Final is used to a restrict classes, variables, or methods, a final keyword.
  • Finally is used to execute a code written inside a block without handling any exceptions.
  • Finalize is used to call function of the implementation of cleaning a garbage collection of an object.

75. When can use the “super” keyword?


Basically, the super keyword is used to refer to a parent class. When there are the same fields in both the parent and child classes, then one can use a super keyword to access a data members of the parent class.

76. What are shallow copy and deep copy in a Java?


In the case of shallow copy, primitive data types are be copied, whereas in the case of a deep copy along with the primitive data types the object references are also be copied.

77. Using a relevant properties highlight the differences between the interfaces and abstract classes?


An abstract class can have the combination of both abstract and non-abstract methods, whereas an interface has only an abstract methods in it.

78. What are the different ways of a thread usage?


There are two ways to explain and implement a thread in Java. They are by implementing runnable interface and extending a thread class.

79. What is the difference between a ‘throw’ and ‘throws’ keyword in Java?


The throw keyword is often used to an explicitly throw an exception. It can only throw a one exception at a time whereas throws can be used to declare a multiple exceptions.

80. What is meaning of Collections in Java?


Collection is framework that is designed to a store the objects and manipulate a design to store the objects:

  • Searching
  • Sorting
  • Manipulation
  • Insertion
  • Deletion
  • A group of objects is known as a collections. All the classes and interfaces for collecting are available in a Java util package.

81. If Java works as a “pass by value” or “pass by reference” phenomenon?


Java works as “pass by value” phenomenon, because “pass by reference” needs help of pointers. But there are no pointers in a Java.

82. How to not allow serialization of the attributes of a class in Java?


One approach to not allow serialization of the attributes of a class in Java is by using a writeObject() and readObject() methods in a subclass and throwing a not a Serializable exception.

83. What are the default values assigned to a variables and instances in Java?


By default, for a numerical value it is 0, for a boolean value it is false and for objects it is a NULL.

84. What is mean by data encapsulation?


Data encapsulation is one of the properties of an OOPS concepts, where all the data such as variables and the methods are enclosed together as a single unit.

85. Can tell the difference between a equals() method and equality operator (==) in Java?


Equality operator (==) is used to check a equality condition between the two variables. But the equals() method is used to check a equality condition between the two objects.

86. How is an infinite loop declared in a Java?


An infinite loop can be declared in a Java by breaking the logic in an instruction block.

87. Briefly explain concept of a constructor overloading?


The concept of constructor overloading refers to having a multiple methods in a class with their name being the same as a class name. The difference lies in a set of parameters passed to functions.

88. Explain the use of a final keyword in variable, method and class?


In Java, one can apply a final keyword to a variable, methods, and class. With help of the final keyword, a variable turns out to be a constant, the method cannot be an inherited and the class cannot be overridden.

89. Is it possible that a ‘finally’ block will not be executed? If yes then list the case?


Yes, there is a possibility that a ‘finally’ block cannot get be executed. Here are some of cases where the above situation occurs.

  • During a time of fatal errors such as a memory exhaustion, memory access error, etc.
  • During a time of using System.exit().

90. Difference between a static methods, static variables, and static classes in Java?


A variable, method, or class can be made static by using a static keyword. A static class cannot be an instantiated. When both objects or instances of a class share a same variables, this is referred to as a static variables. Static methods are simply methods that refer to a class in which they are written.

91. What is the main objective of a garbage collection?


The main goal of using a garbage collection is to free heap memory by an eliminating unnecessary objects.

92. Apart from a security aspect, what are the reasons behind making a strings immutable in Java?


Because of a security, synchronization, concurrency, caching, and class loading, a String is immutable in Java. The reason for making string final would be to destroy its immutability and help stop others from trying to an extend it. String objects are cached in a String pool, making them immutable.

93. What is Comparator in a Java?


A comparator is interface, which is used to sort objects.

94. How would differentiate between the String, StringBuffer, and a StringBuilder?


The string class is immutable but the other two are mutable in a nature. StringBuffer is a synchronous whereas the StringBuilder is asynchronous. String uses a string pool as memory storage whereas other two use heap memory for a storage purposes.

95. In Java, static as well as a private method overriding is possible?


In Java, could indeed override a private or static method. If create a similar method in the child class with a same return type and method arguments, it will hide a super class method; this is known as a method hiding. Similarly, cannot be override a private method in a subclass because it is not accessible from that.

96. What makes a HashSet different from TreeSet?


In HashSet, the elements are unsorted and work faster than Tree set. It is implemented using the hash table.

97. Why is character array preferred over a string for storing confidential information?


Because Strings are immutable, any change will result in creation of a new String, whereas char[] allows to set all of the elements to blank or zero. So storing a password in the character array clearly reduces a security risk of password theft.

98. What are differences between a HashMap and HashTable in Java?


    1. Asynchronous in a nature. 1. Synchronous in a nature.
    1. Not a thread-safe. 2. a Thread safe.
    1. It allows a one null key and null values. 3. It doesn’t allow a null keys and values.

99. What is the importance of reflection in a Java?


Reflection is a property of Java, enabling a Java code to inspect itself. A Java class, for example, can get names of all its members and showcase them.

100. What are the different types of a Thread Priorities in Java? And what is the default priority of thread assigned by JVM?


There are different types of thread properties in a Java. They are MIN_PRIORITY, MAX_PRIORITY, and NORM_PRIORITY. By default, a thread is assigned in NORM_PRIORITY.

Are you looking training with Right Jobs?

Contact Us

Popular Courses