Explore topic-wise InterviewSolutions in .

This section includes InterviewSolutions, each offering curated multiple-choice questions to sharpen your knowledge and support exam preparation. Choose a topic below to get started.

451.

List the different types of classloaders in java.

Answer»

There are 3 types of built-in Class Loaders:

  • Bootstrap Class LOADER: LOADS internal classes
  • EXTENSIONS Class Loader: Loads classes from extensions directory
  • System Class Loader: Loads classes from the current classpath
452.

What do you mean by Classloader in Java?

Answer»

Class loaders HELP in loading classes during RUNTIME to the Java VIRTUAL Machine. In ADDITION, they are part of the Java Runtime Environment. Hence, due to class loaders, JVM is not required to know the underlying files for running PROGRAMS.

453.

What do you mean by inner class in java? Explain

Answer»

It is a CLASS that is a MEMBER of ANOTHER class.

There are 4 TYPES of INNER classes:

  • Nested Inner class
  • Method Local inner classes
  • Anonymous inner classes
  • Static nested classes
454.

What do you mean by Java Annotations?

Answer»

Annotation is a tag in Java that represents metadata attached with a class, METHOD, interface, or field. It PROVIDES supplement information to be used by compiler and JVM. Annotations do not change a COMPILED program's action and they are not pure comments.

If you are preparing for interviews, you can check core java interview questions and answers for more insight.

455.

Explain the difference between abstract class and interface in Java?

Answer»
 Abstract ClassInterface
1.Can have members, constants, defined methods and method stubsCan only have methods stubs and constants
2.Methods and members can be defined with any visibilityMethods must be defined as public
3.May contain non-final variables.Variables declared are by DEFAULT final
14. What do you mean by Marker interface in Java?

It is an interfaces that has no FIELD or methods (empty interface). It helps in conveying to the JVM that the class that is implementing the interface of a category will have special BEHAVIOR. It is also known as TAG interface.

There are 4 major marker interfaces:

  • Searilizable interface
  • Cloneable interface
  • Remote interface
  • ThreadSafe interface
456.

What is an interface in Java? Explain

Answer»

It is a reference type that is similar to a CLASS in Java. It is a COLLECTION of abstract METHODS that is used for full abstraction. An interface may have methods and VARIABLES but the methods in interface are abstract by default.

457.

What is static import in Java? Explain

Answer»

The static import feature allows the static member of a CLASS to be accessed directly without USING the qualified NAME. The biggest advantage of this feature is that less coding will be REQUIRED if you have access to a static member.

458.

Explain access modifiers in Java.

Answer»

Access MODIFIERS HELP to restrict the SCOPE of a class, variable, constructor, method or data.

Four TYPES of access modifiers are available:

  • Default
  • Private
  • Protected
  • Public
459.

What is the purpose of main function in Java?

Answer»

From version JDK6 onwards, the MAIN method is mandatory to START code execution. If your program does not contain "main" method, you will get a run-time error. PLEASE note that in the absence of "main" method your entire program will SUCCESSFULLY COMPILE but it will throw an error at runtime.

460.

What is difference between classpath and path variables in Java?

Answer»
 ClasspathPATH
1.Used to FIND path of classesUsed to find executables
2.Refers to environmentRefers to SYSTEM
461.

Why Java is called not pure Object Oriented language?

Answer»

Java is not a pure OOP language as it USES PRIMITIVE datatypes such as int float char double. A pure OOP language should use nothing but OBJECTS, and everything should be a CLASS. But in Java, not everything is a class, such as byte, int, float, char, etc. This is the REASON Java is a not a pure OOP language.

462.

Why does Java does not support multiple inheritance? Explain

Answer»

Java does not support MULTIPLE inheritances because it may lead to overriding of methods when extended classes have the same METHOD names.

Also, supporting multiple inheritances through classes may give RISE to ambiguity errors. However, multiple inheritance is POSSIBLE through the INTERFACE.

463.

Explain the difference between JVM and JRE?

Answer»
 JVMJRE
1.Provides runtime ENVIRONMENT for Java apps and PROGRAMSStands for Java Runtime Environment
2.An INTEGRAL part of JDK and JREProvides an environment to run java programs only
3.Responsible for executing a java programPart of JRE DISTRIBUTION
464.

Explain the difference between JDK and JVM?

Answer»
 JDKJVM
1.Stands for JAVA Development KitStands for Java VIRTUAL machine
2.Provides environment for DEVELOPING and RUNNING Java programs.Interprets byte code into the machine code
3.Includes development ToolsAllows platform-independent coding
465.

What is JVM?

Answer»

A part of Java Run Environment (JRE), JVM is a virtual machine that provides runtime environment to drive Java programs or APPLICATIONS. It ASSISTS in converting bytecode into machine language and handles system memory.

466.

List some important features of Java 10 release?

Answer»

Here are some of the most important Java 10 FEATURES:

  • Local-Variable TYPE Inference
  • Consolidate the JDK Forest into a Single Repository
  • Garbage-Collector Interface
  • Parallel Full GC for G1
  • Application Class-Data Sharing
  • Thread-Local Handshakes
  • Heap ALLOCATION on ALTERNATIVE MEMORY Devices
  • Experimental Java-Based JIT Compiler
  • Root Certificates
  • Time-Based Release Versioning
467.

List some OOPS Concepts in Java?

Answer»

In JAVA, there are 10 OOPS CONCEPTS as FOLLOWS:

  • Abstraction
  • Encapsulation
  • Inheritance
  • Polymorphism
  • Association
  • Composition
  • Aggregation
  • Delegation
  • Coupling
  • Cohesion
468.

What is the substitute of Rhino Javascript engine in Java 8?

Answer»
469.

How to create a Base64 decoder in Java8?

Answer»
470.

What is type inference in Java8?

Answer»

Type inference is a FEATURE of Java that GIVES the CAPABILITY to the compiler to SEEM at each method invocation and corresponding announcement to determine the type of arguments. Java PROVIDES multiplied model of type inference in Java eight

471.

What do you mean by chromounits in java8?

Answer»

The Chrono UNIT was added in Java 8 to replace those integer VALUE that was USED in OLD API to represent the MONTH, day, year, etc. unit is defined in the java.time.temporal.ChronoUnit

472.

Explain local datetime API in Java8?

Answer»

In new data-time API, one of the CLASS is LOCAL Date-Time API where there is no problem of handling of the time-zones. PROGRAMMERS use this API where time zones are not REQUIRED. Local Date-Time API is defined in the package java.time

473.

What do you mean by collectors in Java 8?

Answer»

Collectors perform the reduction OPERATIONS. It combines the result of the PROCESSING ongoing on the elements of the STREAM like collecting the elements into collections, summarizing the elements according to the DIFFERENT CRITERIA. Collectors return the list or a string. As a result, the readability is increased. Static import used here is static import java.util.stream.Collectors.*;

474.

What is sequential and parallel stream in Java 8?

Answer»

Parallel streams divide the provided venture into many and run them in unique threads, MAKING use of a couple of cores of the computer. On the other hand, sequential streams WORK just like for-loop the use of a single core. The DUTIES supplied to the streams are generally the ITERATIVE operations PERFORMED on the factors of a series or array or from different dynamic sources. Parallel execution of streams run more than one iterations concurrently in extraordinary accessible cores.

475.

Write a program to print count of empty strings in java 8?

Answer»

The code to print the COUNT of empty strings in Java 8 is:-

List strings = Arrays.asList("abc", "", "bc", "EFG", "abcd","", "jkl");
//get a count of empty string
long count = strings.p
arallelStream().filter(string -> string.isEmpty()).count();

POINT to be NOTED: Go through this Q&A very thoroughly as this is ONE of the most asked java 8 interview questions.

Example List<String>strings = Arrays.asList("abc", "", "bc", "efg", "abcd","", "jkl"); int count = strings.stream().filter(string −> string.isEmpty()).count();
476.

Write a program to print 15 random numbers using forEach of java 8?

Answer»

RANDOM random = NEW Random();
random.ints().limit(15).FOREACH(System.out::PRINTLN);

477.

What are the difference between map and flatMap stream operation in Java 8?

Answer»
S.noMapFlat map
1.For one input VALUE, it gives one output valueFor one input value,e it produces the ARBITRARY number
16. What do you mean by stream pipelining in Java 8?

Stream Pipelining is done by dividing the operations which can happen on the flow into two categories. The first is Intermediate operations and the SECOND is TERMINAL operations. The common operations return the stream itself so that the result can be pipelined. The terminal operations remain at the END of the pipelining operation. It returns the final value, and the pipeline is terminated.

478.

What is Stream API in Java8?

Answer»

The Stream API is USED to process a group of objects. A stream is a series of objects which supports different methods that can be pipelined to produce the expected result.

The features of the stream are –
  • A stream takes the input from the Collections, an Arrays or the I/O channels.
  • Streams don’t alter the original data STRUCTURE; they only give the result according to the pipelined methods.
  • Each intermediate operation is executed in a lazy manner, and as a result, it RETURNS a stream. Hence various intermediate processes can be pipelined. The terminal operations remain at the end of the pipelining process. It replaces the final value, and the pipeline is terminated.
479.

What do you mean by JJS in Java8?

Answer»

JAVA 8 INTRODUCED a COMMAND TOOL jjs for the Nashorn to execute the javascript program codes at the console.

480.

What is Spliterator in Java 8?

Answer»

A Spliterator is a TYPE of Java8 Iterator in JAVA. util package that traverses and partitions the elements of a SOURCE in Java into ANOTHER Spliterator. A source can be a collection or an IO channel or a GENERATOR function

481.

What is the difference between collection and stream?

Answer»
S.noCollection APIStream API
1.Collection API is for storing the data in the DIFFERENT KINDS of data structures.Stream API is not a data STRUCTURE; it is used for computation of the data on the big set of objects
2.A FINITE number of elements can be STORED in a data structureAn infinite number of features can be stored
3.Consumption of elements is multiple timesConsumption of elements is only once.
482.

Define Nashorn in Java8.

Answer»

Along with JAVA 8, a new improved engine Nashorn was INTRODUCED. Nashorn gives very high performance because it STRAIGHTAWAY compiles the program code in the memory and then passes the bytecode to JVM. It uses the invoke DYNAMICS feature of Java 7 to improve the performance.

483.

What is the syntax and characteristics of a Lambda Expression in JAVA 8?

Answer»

The syntax for the Lambda expression is:-

parameter -> expression body

Characteristics of the Lambda Expression:-
  • No need to DECLARE the parameter TYPE as the compiler will get the STANDARD by the VALUE of the parameter.
  • For the multiple parameters PARENTHESIS has to be declared, but for the simple parameter, parenthesis need not be declared.
  • If a contains only a single parameter, then there is no need of curly braces.
Related Article: How should I start JSP and Servlet
484.

What is the use of default method in interface?

Answer»

The DEFAULT method implementation was introduced by Java 8 so that the OLD interfaces can use the lambda expression without implementing the methods in the implementation class.

Example

SYNTAX:-

public INTERFACE interview {

        default void print() {

System.out.println("Welcome Bestinterviewquestion.com");

             }

    }

485.

What is Optional in Java 8?

Answer»

In java there a NullPointerException which can crash the code. It is complicated to remove the null checks from the code. Java 8 INTRODUCED Optional class in java. util PACKAGE. Use of Optional class results in clean code WITHOUT null checks. By USING the Optional class, the programmer can specify the other value or other code to return. This MAKES the code more readable.

486.

What do you mean by of String::valueOf expression in Java 8?

Answer»

The VALUEOF() method converts data into human-readable form.So String valueOf() will return the string representation of the value. The valueOf() method is a static method.

  • String valueOf(inum)--this syntax will return the string representation of the integer inum.
  • String.valueOf(data, 0, 5)-- This syntax will return the string representation of the character ARRAY 0 to 5
  • String.valueOf(fNum) --this syntax will return the string representation of the FLOAT fNum
487.

What is method reference in Java 8?

Answer»

Method REFERENCES support in POINTING to the METHODS by their names. A method reference is denoted by USING "::" symbol. A method reference is used to indicate the following methods

  • Static methods
  • Instance methods
  • Constructors using new operator (TreeSet::new)

This is a fundamental QUESTION in java 8 interview questions.

488.

What is a Java Lambda Expression?

Answer»

Lamba expression is considered as the most significant feature of JAVA8. A Lambda expression PROVIDES functional programming, and that has simplified the CODE to a great extent. A lambda expression is fundamentally a function which can be created WITHOUT BELONGING to any class.

489.

What are the new features in Java 8?

Answer»

New FEATURES introduced in Java 8 are:-

  • Introduction of Lambda Expression- first step to functional programming
  • New STREAM API to support pipeline processing.
  • Optional − Emphasis on handling null VALUES properly.
  • Nashorn Engine- Provides BETTER performance than Rhino JAVASCRIPT engine.
Related Article: What are the new features of Java 8
490.

What is the purpose of functional interface in Java 8?

Answer»

FUNCTIONAL interfaces are those interfaces that have a SINGLE functionality.

Example
  • CompareTo--- This INTERFACE is only for comparison purposes.
  • Function---this interface accepts only one argument and GIVES the result.
  • This interface means that an object is tested to be either true or false.
491.

What is the difference between intermediate and terminal operations?

Answer»
S.noINTERMEDIATETerminal
1.The intermediate operation produces stream pipeliningTerminal operation TERMINATE the pipeline
2.Intermediate OPERATIONS can be CHAINED multiple times on a streamTerminal operations cannot be chained various times.
3.Intermediate operations cannot be evaluated independently; it NEEDS a terminal operation for evaluation.Terminal Operations can be evaluated independently.
492.

What is the purpose of the System class in Java?

Answer»

System class has useful fields, such as static MEMBERS, that are related to the environment. This class is PROVIDED with STANDARD STREAMS like input, output and error.

These streams can be used to access the properties and environment variables that are externally defined.

493.

Explain the difference between throw and throws in Java?

Answer»
 THROWThrows
1.Used to throw an exception.Used to DECLARE an exception
2.Followed by Exception class instanceFollowed by exception class names
3.Used in the method bodyUsed in method SIGNATURE
494.

What is Exception Handling in Java?

Answer»

Exception HANDLING allows developers to handle runtime ERRORS CAUSED by exceptions. One way to handle exceptions is to print a simple message for users that help them CORRECT the error that occurs due to bad data sent by the user.

Exception handling ensures the flow of the application does not BREAK.

495.

How we can create packages in Java?

Answer»

Here are the steps for creating a package:

  • Choose a name for the package
  • On top of every SOURCE FILE, put the package statement with the package name. Source file must contain CLASSES and types that you want in the package.
  • Package statement is the first LINE of source file.
  • You can only have one package statement in each file
  • It applies to all file types.
496.

How we can make a read-only class in Java?

Answer»

By Read-only CLASS we are referring to the "IMMUTABLE" CONCEPT. You can begin by defining a class so that no methods can CAUSE changes to the internal state.

In such classes, aliasing will have no impact because its internal state is read-only.

45. How we can make a write-only class in JAVA?
497.

What is instanceOf operator used in Java?

Answer»

INSTANCEOF operator is used in OBJECT REFERENCE variables. In this, the operator will check the class type or INTERFACE type of an object.

It is WRITTEN as follows:

( Object reference variable ) instanceof (class/interface type)

498.

What is finalize() function in Java?

Answer»

This is a good question concerning core java INTERVIEW QUESTIONS for experienced professionals. FINALIZE method is CALLED by the Garbage Collector before performing the clean-up activity. Clean-up activity refers to the process of de-allocating all the resources, such as database connection and NETWORK connection, associated with an object.

499.

Define an applet in Java?

Answer»

APPLET is a Java program that gets embedded into web PAGES using the APPLET or OBJECT tag and runs inside the browser.

It works at the client side, and is hosted on a web server. Applets MAKE WEBSITES dynamic and ENTERTAINING.

500.

What is JIT compiler in Java?

Answer»

JIT COMPILER is a COMPONENT of JRE that improves the performance of applications.

JIT compiler improve the performance of JVM by compiling bytecode into MACHINE code at runtime. Choosing the right compiler is ONE of the first and biggest decisions to be made when you are running a Java application.