Professional Documents
Culture Documents
JAVA
INTERVIEW QUESTIONS
What is Java?
code can run on any platform with a Java Virtual Machine (JVM).
System.out.println("Hello, World!");
Question 2
System.out.println("Hello, World!");
Design MERN
can extend only one abstract class but implement multiple interfaces.
String name;
Animal(String name) {
this.name = name;
interface Flyable {
void fly();
From To
Placed with
System.out.println("Hello, World!");
Question 6
// Implementation
comparison logic.
Question 8
when an object is created and ensures that the object is in a valid state.
class Person {
String name;
// Constructor
Person(String name) {
this.name = name;
'this' refers to the current object within a class. It is often used to distinguish
between instance variables and method parameters with the same name.
class MyClass {
int value;
MyClass(int value) {
instance variable
Question 10
Method overloading is when multiple methods in the same class have the
superclass.
class MathOperations {
return a + b;
return a + b;
called using the class name and is often used for utility functions that
class MathUtils {
return a + b;
Question 12
class Parent {
void show() {
System.out.println("Parent class");
void show() {
method
System.out.println("Child class");
'try' is used to enclose code that might throw an exception, 'catch' is used
to handle exceptions, and 'finally' is used to specify code that will always
try {
int result = 10 / 0;
} catch (ArithmeticException e) {
} finally {
System.out.println("Cleanup code");
So far, the best course. This was the best decision I've ever made. When I
started, I knew the very basics of simple data structures, but after finishing
the course, I was confident that I could solve most problems. Because of
declared)
try {
FileInputStream("file.txt");
} catch (FileNotFoundException e) {
6 }
catch)
From To
Placed with
null object. To prevent it, ensure that object references are not null before
accessing them.
if (name != null) {
before accessing
Guaranteed
Hiring
Highest
I got rejected in the Amazon interview. When I started looking for a software
After that, I joined Tutort Academy for development course, I found Tutort
They fulfilled my all requirements and requirements. Apart from the content
Nikesh Bisen that is why I am in Microsoft right now. I Akansha Likhdhari and live classes that they provide,
highly recommend Tutort Academy for the mentorship program is the cherry
The 'finally' block is used to ensure that essential cleanup code executes,
try {
} catch (IOException e) {
} finally {
try {
if (file != null) {
file.close();
} catch (IOException e) {
Service Based
Sivani
Company
yadav
for working with collections of objects. It's essential for efficient data
Framework
import java.util.ArrayList;
import java.util.List;
6 names.add("Alice");
names.add("Bob");
names.add("Charlie");
System.out.println(names);
From To
Placed with
and deletions.
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
6
arrayList.add("A");
arrayList.add("B");
arrayList.add("C");
System.out.println(arrayList.get(1)); // Output:
deletions
linkedList.add("X");
linkedList.add("Y");
linkedList.add("Z");
used in data structures like HashMap and HashSet for efficient storage and
retrieval.
class Student {
String name;
int id;
@Override
Tutort Benefits
// Thread's logic
// Runnable's logic
Service Based
Vikhil
Krishna
Company
class SynchronizedExample {
// Synchronized method
count++;
6
// Synchronized block
void performTask() {
synchronized (this) {
read from and written to the main memory, avoiding thread caching.
class SharedResource {
Question 23
import java.util.concurrent.atomic.AtomicInteger;
class Counter {
AtomicInteger(0);
// Thread-safe increment
void increment() {
count.incrementAndGet();
thread(s).
class SharedResource {
6 InterruptedException {
Service Based
Saumya Mishra
Company
class SharedResource {
Question 26
generational, mark-and-sweep,
}
and G1.
}
files or sockets.
class Resource {
Question 28
enum Day {
Question 30
Annotations provide metadata about the code and can be used to add
@Override
// Method implementation
@Deprecated
// Deprecated method
Question 32
FileInputStream("file.txt")) {
} catch (IOException e) {
// Handle exceptions
allow you to define and pass functions as arguments to methods. They are
Question 34
data efficiently.
.filter(n -> n % 2 == 0)
.mapToInt(Integer::intValue)
.sum();
empty. It is used to avoid null pointer exceptions and indicate that a value
Optional<String> optionalName =
Optional.ofNullable(getName());
Name");
Question 36
sb.append("Hello, ");
sb.append("World!");
based on annotations.
@MyAnnotation
// Annotation-processed code
Question 38
String name;
int rollNumber;
// ...
The 'Reflection' API allows you to inspect and manipulate classes, methods,
fields, and objects at runtime. It is often used for dynamic code generation
and testing.
Class<?> clazz =
Class.forName("com.example.MyClass");
methods
Question 40
nested class is any class defined within another class. Inner classes have
class Outer {
int outerValue;
class Inner {
threads. It decouples the task submission from the thread creation and
Executor executor =
Executors.newFixedThreadPool(2);
executed."));
Question 42
class, while 'Comparator' allows you to define custom comparison logic for
String name;
int rollNumber;
@Override
tasks concurrently.
1000));
Question 44
import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.Future;
ExecutorService executor =
Executors.newVirtualThreadPerTaskExecutor();
Project Valhalla aims to introduce value types and reified generics to Java,
int x;
int y;
Question 46
C code
Question 48
Project Valhalla aims to introduce value types and reified generics to Java,
Question 49
Guaranteed
Hiring
Highest
The course is also valid for a lifetime, and new material is added regularly.
With their help, I cracked many top product based companies & currently
Explore More
www.tutort.net
Follow us on