Java Interview Questions and answers 2021

Spread the love

Can you list some of the features of Java 15? Java Interview Questions

  • Text blocks
  • Hidden classes
  • Foreign memory access API
  • Z Garbage Collector
  • Pattern Matching
  • Records
  • Cryptographic SignaturesDisabling biased locking
  • RMI Activation Mechanism
  • Helpful nullpointerexception
Java Interview Questions

Can you list some of the features of Java 14?

  •  pattern matching for instance of
  •  Records
  • helpful null pointer exception
  •  foreign  memory access API
  •  packaging tool
  • hotspot feature like ZGC on windows and macOS
  • deprecated or  removed features like  solaris and SPARC Ports,  serial old GC combination,  CMS etc.

Can you list some of the features of Java 13?

  •  Text blocks  instead of RAW string literals
  • ZGC  Returns unused storage
  •  renewed socket API 

Can you list some of the features of Java 12?

  • Switch expressions
  • Default CDS Archives
  • Microbenchmark suite
  • JVM castant AP
  • Raw string literals removed from JDK 12
  • String class new methods
  • File::mismatch method
  • Teeing Collector
  • Compact number formatting

Can you list some of the features of Java 11?

  • New string methods
  • New file methods
  • Collection to an array
  • Teh not predicate method
  • Local variable syntax for Lambda
  • HTTP Client
  • Nest Based Access control
  • Running java files
  • Dynamic Class file constants
  • Improved Aarch64 intrinsics
  • A No-op garbage collector
  • Flight recorder
  • Removed and Deprecated modules
  • Java EE and Cobra
  • JMC and Java FX

Can you list some of the features of Java 10?

  • Unmodifiable collections like copyOf(), toUnmodifiable*(),
  • Performance improvements
  • Container awareness 
  • Root Certificates

Core Java Interview Questions and Answers

Can you list some of the features of Java 9?

  • Modular system Jigsaw project
  • A New HTTP Client
  • Quick GET Request
  • Process API
  • Process Information
  • Destroying Processes
  • JCMD Sub-Commands
  • Multi-resolution Image API
  • Variable Handles
  • Publish-Subscribe Framework
  • Unified JVM Logging
  • New API’s like Immutable Set, Optional to stream

Can you list some of the features of Java 8?

  • Interface default and Static methods like producer()
  • Reference to a static method
  • Optional<T> creation and Usage

What are the important oops concepts in Java?

  • Object
  • Class
  • Abstraction
  •  Encapsulation
  •  Polymorphism
  •  Inheritance
  • Coupling
  • Cohesion
  • Association
  • Aggregation
  • Composition

Tell us something about JIT compiler.

  • JIT stands for Just-In-Time and it is used for improving the performance during run time. It does the task of compiling parts of byte code having similar functionality at the same time thereby reducing the amount of compilation time for the code to run.
  • The compiler is nothing but a translator of source code to machine-executable code. But what is special about the JIT compiler? Let us see how it works:
    • First, the Java source code (.java) conversion to byte code (.class) occurs with the help of the javac compiler.
    • Then, the .class files are loaded at run time by JVM and with the help of an interpreter, these are converted to machine understandable code.
    • JIT compiler is a part of JVM. When the JIT compiler is enabled, the JVM analyzes the method calls in the .class files and compiles them to get more efficient and native code. It also ensures that the prioritized method calls are optimized.
    • Once the above step is done, the JVM executes the optimized code directly instead of interpreting the code again. This increases the performance and speed of the execution.

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

In Java, the final keyword is used as defining something as constant /final and represents the non-access modifier.

  • final variable:
    • When a variable is declared as final in Java, the value can’t be modified once it has been assigned.
    • If any value has not been assigned to that variable, then it can be assigned only by the constructor of the class.
  • final method:
    • A method declared as final cannot be overridden by its children’s classes.
    • A constructor cannot be marked as final because whenever a class is inherited, the constructors are not inherited. Hence, marking it final doesn’t make sense. Java throws compilation error saying – modifier final not allowed here
  • final class:
    • No classes can be inherited from the class declared as final. But that final class can extend other classes for its usage.

Explain public static void main(String args[]) in Java Interview Questions

main() in Java is the entry point for any Java program. It is always written as public static void main(String[] args).

  • public: Public is an access modifier, which is used to specify who can access this method. Public means that this Method will be accessible by any Class.
  • static: It is a keyword in java which identifies it is class-based. main() is made static in Java so that it can be accessed without creating the instance of a Class. In case, main is not made static then the compiler will throw an error as main() is called by the JVM before any objects are made and only static methods can be directly invoked via the class. 
  • void: It is the return type of the method. Void defines the method which will not return any value.
  • main: It is the name of the method which is searched by JVM as a starting point for an application with a particular signature only. It is the method where the main execution occurs.
  • String args[]: It is the parameter passed to the main method.

Why Java is platform independent?

Java is called platform independent because of its byte codes which can run on any system irrespective of its underlying operating system.

What are wrapper classes in Java?

Wrapper classes convert the Java primitives into the reference types (objects). Every primitive data type has a class dedicated to it. These are known as wrapper classes because they “wrap” the primitive data type into an object of that class. Refer to the below image which displays different primitive type, wrapper class and constructor argument.

What are constructors in Java?

In Java, constructor refers to a block of code which is used to initialize an object. It must have the same name as that of the class. Also, it has no return type and it is automatically called when an object is created.

There are two types of constructors:

  1. Default Constructor: In Java, a default constructor is the one which does not take any inputs. In other words, default constructors are the no argument constructors which will be created by default in case you no other constructor is defined by the user. Its main purpose is to initialize the instance variables with the default values. Also, it is majorly used for object creation. 
  2. Parameterized Constructor: The parameterized constructor in Java, is the constructor which is capable of initializing the instance variables with the provided values. In other words, the constructors which take the arguments are called parameterized constructors.

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

JVM

JVM is an acronym for Java Virtual Machine; it is an abstract machine which provides the runtime environment in which Java bytecode can be executed. It is a specification which specifies the working of Java Virtual Machine. Its implementation has been provided by Oracle and other companies. Its implementation is known as JRE.

JVMs are available for many hardware and software platforms (so JVM is platform dependent). It is a runtime instance which is created when we run the Java class. There are three notions of the JVM: specification, implementation, and instance.

JRE

JRE stands for Java Runtime Environment. It is the implementation of JVM. The Java Runtime Environment is a set of software tools which are used for developing Java applications. It is used to provide the runtime environment. It is the implementation of JVM. It physically exists. It contains a set of libraries + other files that JVM uses at runtime.

JDK

JDK is an acronym for Java Development Kit. It is a software development environment which is used to develop Java applications and applets. It physically exists. It contains JRE + development tools. JDK is an implementation of any one of the below given Java Platforms released by Oracle Corporation:

  • Standard Edition Java Platform
  • Enterprise Edition Java Platform
  • Micro Edition Java Platform

What is classloader?

Classloader is a subsystem of JVM which is used to load class files. Whenever we run the java program, it is loaded first by the classloader. There are three built-in classloaders in Java.

  1. Bootstrap ClassLoader: This is the first classloader which is the superclass of Extension classloader. It loads the rt.jar file which contains all class files of Java Standard Edition like java.lang package classes, java.net package classes, java.util package classes, java.io package classes, java.sql package classes, etc.
  2. Extension ClassLoader: This is the child classloader of Bootstrap and parent classloader of System classloader. It loads the jar files located inside $JAVA_HOME/jre/lib/ext directory.
  3. System/Application ClassLoader: This is the child classloader of Extension classloader. It loads the class files from the classpath. By default, the classpath is set to the current directory. You can change the classpath using “-cp” or “-classpath” switch. It is also known as Application classloader.

What is the size of the below array in memory?
int a[]=new int[10];

Each int block takes a size of 4 bytes and there are 10 such blocks in the array. Hence, the size the array takes in memory is 40 bytes.

How many data types does java support?

Java supports 8 primitive data types, namely byte, short, int, long, float, double, char, boolean.

How to find out the ASCII value of a character in java?

int c=char(‘A’) would give the ASCII value of A in java.

How to get a string as user input from the console?

We have to instantiate an input reader class first. There are quite a few options available, some of which are BufferedReader, InputStreamReader Scanner.
Then the relative functionality of the class can be used. One of the most prevalently used is nextLine() of Scanner class.

How to check the size of strings?

The size of strings in java can be checked by using the length() function.

How can we sort a list of elements in Java?

The built-in sorting utility sort() can be used to sort the elements. We can also write our custom functions but it’s advisable to use the built-in function as its highly optimized.

If we sort a list of strings how would be the strings arranged? The strings would be arranged alphabetically in ascending order.

To get instant updates on walk-ins and off-campus jobs into your mobile directly join our Telegram Channel

If you have any queries regarding the Java Interview Questions, please comment in the comment section. Help freshers team will respond to your query as soon as possible.

Other Similar Drives for 2021 and 2020 Batches:

Off-campus Jobs2020 Batch
Software Jobs2021 Batch

Free Online Courses:

Related Java interview Questions:

  • Java Programming Interview Questions

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top