Below is a list of the 15 most common Java interview questions part 1. Depending on experience, all of the questions below will get asked in 99% of cases.
Java is an object-oriented language because everything depends on objects.
Java helps us create robust, large, high-performance, and scalable applications.
Final is a java keyword used as a non-access modifier with Classes, attributes and methods. After making class as final will not allow us to inherit the class. Method as final will not allow us override in child class. Making any variable as final will not allow us to override the value.
Finally block used with try block to execute statement. It is mainly use for closing an open connections. Finally will always get call either exception is thrown or not. finally block can be used with or without catch block.
finalize() method used to perform cleanup activity and destroy objects. It will totally depend on the garbage collector when to run. An object will be ready for garbage collection if it is no longer in use. Anonymous objects are always ready for garbage collection.
When the JVM starts up, it creates a heap memory area, which is also called a dynamic and runtime data area. All the objects and instances will be stored in the heap area.
Garbage collection works well for managing heap memory effectively. The garbage collector collects all the unreferenced data, destroys it and frees the memory.
system.gc() can be use to request the garbage collector to run.
It is an empty interface having no fields and methods inside it and give a special definition to a class. Serializable and Cloneable interface are the example of marker interface. Cloneable
interface belongs to java.lang.Cloneable and and serializable interface belongs to java.io.Serializable.
Syntax:
Public interface {
// having no fields and methods
}
Lambda expression introduced in java 8 and as an anonymous function it helps us to write short and clean code. Functional interface having single abstract method helps us to implement lambda expression.
Below is the example of Lambda expression having no parameters and function return type.
OUTPUT:
Name Rida
This is an important question ask in most of the Java interview. Follow blog to read in detail.
A class contains abstract keyword in declaration known as Abstract class.
// abstract class
abstract class TestClass {
}
Java 8 introduces a new technique where it allows us to write implementation of default method in interfaces.
Single interface can have any number of default method implementation.
It provides us the backward compatibility to add some functionality for existing interfaces without changing existing logic of classes implementation the same interface.
For example, if we have an interface and same is
implementing by multiple classes. After adding a default method or methods will not force us to update the existing classes implementing the same interface.
Syntax:
Java also called as platform independent because of Bytecode.
The Bytecode gets generate in the form of .class file as soon as the Java program gets compiled. Bytecode is an instruction for JVM to covert it in to machine language. The
Bytecode makes java to write once, run anywhere (WORA).
Java is platform independent. Because the Java compiler converts the source code to bytecode, which is Intermediate Language called as bytecode which can be executed on any platform or operating system.
Bytecode alone is of no use and non-runnable as it requires an interpreter (JVM) to run on any machine.
It is also called as dynamic polymorphism or function overriding.
Function having same name with exactly same number and sequence of parameters defined in both parent and child class is called as function overriding.
Process where call to overridden method will get resolves only at dynamic or run time.
OUTPUT:
This is Audi car engine
List is an interface belongs to java.util package and it is a child interface of Collection interface. Elements maintain insertion order and can be access by using index. List items can be accessed in both forward and backward direction.
Map is an interface that belongs to java.util package and stores data as key value pair. It allows single null key and multiple null values. It doesn’t maintain any insertion order.
Set is an interface that belongs to java.util package. Set allows only single null value as well as unique value to store. It doesn’t maintain any insertion order.
Java is not 100% object-oriented because of primitive data types int, char, float, etc. as they are not object-oriented. The primitive data types are faster than objects, and to achieve faster execution of Java programs, they kept the primitive data types as it is !
Specialist Master (Architect) with a passion for cutting-edge technologies like AEM (Adobe Experience Manager) and a proven track record of delivering high-quality software solutions.
📝 Blogs
javadoubts.com © All rights reserved