0% found this document useful (0 votes)
4 views5 pages

TCS Java Interview Questions 50

The document lists the top 50 Java interview questions, covering fundamental concepts such as Java's features, JVM, JDK, and JRE, as well as object-oriented principles like inheritance, encapsulation, and polymorphism. It also addresses advanced topics including exception handling, multithreading, collections, and Java 8 features like lambda expressions and the Stream API. Each question is accompanied by a concise answer, making it a useful resource for Java interview preparation.

Uploaded by

anillohar7972
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views5 pages

TCS Java Interview Questions 50

The document lists the top 50 Java interview questions, covering fundamental concepts such as Java's features, JVM, JDK, and JRE, as well as object-oriented principles like inheritance, encapsulation, and polymorphism. It also addresses advanced topics including exception handling, multithreading, collections, and Java 8 features like lambda expressions and the Stream API. Each question is accompanied by a concise answer, making it a useful resource for Java interview preparation.

Uploaded by

anillohar7972
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Top 50 Java Interview Questions - TCS

1. What is Java?

Java is a high-level, object-oriented programming language developed by Sun Microsystems. It is

platform-independent due to the Java Virtual Machine (JVM).

2. What are the features of 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.

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

JDK = JRE + Development Tools; JRE = JVM + Libraries; JVM = Runs bytecode.

7. What are access modifiers?

They define access levels: public, private, protected, and default.

8. What is the difference between equals() and ==?

`equals()` compares content, `==` compares references.

9. What is inheritance in Java?

Inheritance allows one class to acquire properties and methods of another class using 'extends'.

10. What is encapsulation?

Encapsulation is wrapping data and methods into a single unit (class) and restricting access using access
modifiers.

11. What is polymorphism?

Polymorphism allows methods to behave differently based on the object (method overloading and overriding).

12. What is abstraction?

Abstraction is hiding implementation details and showing only essential features using abstract classes or

interfaces.

13. What is an interface?

An interface is a reference type with abstract methods that a class can implement.

14. What is the difference between abstract class and interface?

Abstract class can have method definitions; interface can't (prior to Java 8).

15. What is a constructor?

A constructor is a special method used to initialize objects.

16. What is method overloading?

Method overloading means defining multiple methods with the same name but different parameters.

17. What is method overriding?

Method overriding means redefining a parent class method in a child class.

18. What is the final keyword?

`final` can be used to mark a variable as constant, a method as non-overridable, or a class as

non-inheritable.

19. What is static keyword?

`static` means the variable or method belongs to the class, not the instance.

20. What is the difference between ArrayList and LinkedList?

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.

22. What is the difference between checked and unchecked exceptions?

Checked exceptions are checked at compile-time; unchecked are not.

23. What is a try-catch block?

Used to handle exceptions to prevent program crashes.

24. What is throw and throws?

`throw` is used to explicitly throw an exception, `throws` declares exceptions a method might throw.

25. What is multithreading?

Multithreading is executing multiple threads concurrently to improve performance.

26. How do you create a thread in Java?

By extending the Thread class or implementing the Runnable interface.

27. What is synchronization?

Synchronization ensures only one thread can access a resource at a time.

28. What is deadlock?

Deadlock is a situation where two or more threads are blocked forever, each waiting for the other.

29. What are collections in Java?

Collections are data structures like List, Set, and Map used to store and manipulate groups of objects.

30. What is the difference between HashMap and Hashtable?

HashMap is not synchronized; Hashtable is synchronized.

31. What is the difference between List and Set?

List allows duplicates and maintains order; Set does not allow duplicates.

32. What is garbage collection?


Garbage collection is automatic memory management that reclaims memory used by unreferenced objects.

33. What is the purpose of the 'this' keyword?

`this` refers to the current object instance.

34. What is super keyword?

`super` refers to the parent class and can be used to call parent methods or constructors.

35. What is the main method signature in Java?

`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?

Java passes everything by value (even object references).

37. What is a package in Java?

A package is a namespace that organizes classes and interfaces.

38. What is a singleton class?

A class that allows only one instance to be created throughout the application.

39. What is the use of transient keyword?

Marks a variable to be skipped during serialization.

40. What is serialization?

Serialization is converting an object into a byte stream for storage or transfer.

41. What is the use of instanceof?

`instanceof` checks whether an object is an instance of a specific class or subclass.

42. What is autoboxing and unboxing?

Autoboxing converts primitives to wrapper objects; unboxing does the reverse.

43. What is a lambda expression?

A lambda is an anonymous function used to simplify code, introduced in Java 8.


44. What is the Stream API?

Stream API is used to process collections in a functional style (introduced in Java 8).

45. What is Optional in Java 8?

Optional is a container object to avoid null pointer exceptions.

46. What is the default method in interface?

A default method has a body and can be overridden in implementing classes (Java 8+).

47. What are functional interfaces?

Interfaces with a single abstract method. Used in lambda expressions (e.g., Runnable).

48. What is method reference?

Method reference is a shorthand for calling methods using `::` operator.

49. What is the difference between Comparable and Comparator?

Comparable is natural ordering; Comparator is custom ordering.

50. What are annotations in Java?

Annotations provide metadata to code and are used by compilers and frameworks.

You might also like