TCS Java Interview Questions 50
TCS Java Interview Questions 50
1. What is Java?
Object-Oriented, Platform Independent, Secure, Robust, Multithreaded, Portable, and High Performance.
3. What is JVM?
JVM (Java Virtual Machine) is a part of JRE that executes Java bytecode and provides platform
independence.
4. What is JDK?
JDK (Java Development Kit) is a software development environment used to develop Java applications.
5. What is JRE?
JRE (Java Runtime Environment) provides libraries and JVM to run Java applications.
JDK = JRE + Development Tools; JRE = JVM + Libraries; JVM = Runs bytecode.
Inheritance allows one class to acquire properties and methods of another class using 'extends'.
Encapsulation is wrapping data and methods into a single unit (class) and restricting access using access
modifiers.
Polymorphism allows methods to behave differently based on the object (method overloading and overriding).
Abstraction is hiding implementation details and showing only essential features using abstract classes or
interfaces.
An interface is a reference type with abstract methods that a class can implement.
Abstract class can have method definitions; interface can't (prior to Java 8).
Method overloading means defining multiple methods with the same name but different parameters.
non-inheritable.
`static` means the variable or method belongs to the class, not the instance.
ArrayList uses a dynamic array, faster in retrieval; LinkedList uses nodes, faster in insertion/deletion.
21. What is exception handling?
Exception handling is the process of handling runtime errors using try-catch blocks.
`throw` is used to explicitly throw an exception, `throws` declares exceptions a method might throw.
Deadlock is a situation where two or more threads are blocked forever, each waiting for the other.
Collections are data structures like List, Set, and Map used to store and manipulate groups of objects.
List allows duplicates and maintains order; Set does not allow duplicates.
`super` refers to the parent class and can be used to call parent methods or constructors.
`public static void main(String[] args)` is the entry point of Java applications.
36. What is the difference between pass by value and pass by reference?
A class that allows only one instance to be created throughout the application.
Stream API is used to process collections in a functional style (introduced in Java 8).
A default method has a body and can be overridden in implementing classes (Java 8+).
Interfaces with a single abstract method. Used in lambda expressions (e.g., Runnable).
Annotations provide metadata to code and are used by compilers and frameworks.