0% found this document useful (0 votes)
14 views

Java

java interview / viva

Uploaded by

abhishes39561
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)
14 views

Java

java interview / viva

Uploaded by

abhishes39561
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

Core Java Concepts

1. What is the Java Virtual Machine (JVM)?

The JVM is an engine that provides a runtime environment to execute Java bytecode.

2. Explain the difference between JDK, JRE, and JVM.

JDK is the Java Development Kit, JRE is the Java Runtime Environment, and JVM is the Java Virtual Machine;
JDK includes JRE, which includes JVM.

3. What are the main features of Java?

Java is platform-independent, object-oriented, robust, secure, and supports multithreading.

4. What is the difference between a class and an object?

A class is a blueprint for objects, while an object is an instance of a class.

5. What are the access modifiers in Java?

Public, private, protected, and default (no modifier) control the visibility of classes and members.

6. Explain the concept of inheritance in Java.

Inheritance allows a class to acquire properties and methods of another class.

7. What is polymorphism in Java?

Polymorphism allows methods to perform differently based on the object that invokes them.

8. Differentiate between method overloading and method overriding.

Overloading is having multiple methods with the same name but different parameters; overriding is
redefining a superclass method in a subclass.

9. What is encapsulation?

Encapsulation is the wrapping of data and methods into a single unit, typically a class.

10. What is abstraction in Java?

Abstraction is the process of hiding implementation details and showing only functionality.
Exception Handling

11. What is exception handling in Java?

Exception handling manages runtime errors, allowing the normal flow of the program to continue.

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

Checked exceptions are checked at compile-time; unchecked exceptions occur at runtime.

13. Explain try-catch-finally blocks.

Try contains code that might throw an exception; catch handles the exception; finally executes code
regardless of exception occurrence.

14. What is the purpose of the throw and throws keywords?

Throw is used to explicitly throw an exception; throws declares exceptions a method might throw.

15. Can we have multiple catch blocks for a single try block?

Yes, to handle different types of exceptions separately.

Collections Framework

16. What is the Java Collections Framework?

A set of classes and interfaces that implement commonly reusable collection data structures.

17. Differentiate between List, Set, and Map.

List allows duplicate elements; Set does not allow duplicates; Map stores key-value pairs.

18. What is the difference between ArrayList and LinkedList?

ArrayList uses a dynamic array; LinkedList uses a doubly linked list.

19. Explain HashMap and HashSet.

HashMap stores key-value pairs; HashSet stores unique elements.

20. What is the difference between Iterator and ListIterator?

ListIterator allows bidirectional traversal; Iterator allows unidirectional traversal.


Multithreading and Concurrency

21. What is multithreading in Java?

Multithreading is a process of executing multiple threads simultaneously.

22. How do you create a thread in Java?

By extending the Thread class or implementing the Runnable interface.

23. What is the difference between process and thread?

A process is an independent program; a thread is a subset of a process.

24. What are the states of a thread?

New, Runnable, Blocked, Waiting, Timed Waiting, and Terminated.

25. Explain synchronization in Java.

Synchronization controls access to shared resources by multiple threads to prevent data inconsistency.

Java Input/Output (I/O)

26. What is the difference between byte streams and character streams?

Byte streams handle raw binary data; character streams handle character data.

27. What are InputStream and OutputStream?

Abstract classes for reading and writing byte streams.

28. What is the purpose of the File class?

To represent file and directory pathnames in an abstract manner.

29. How do you read and write files in Java?

Using classes like FileReader, FileWriter, BufferedReader, and BufferedWriter.

30. What is serialization in Java?

Serialization is the process of converting an object into a byte stream for storage or transmission.
Java Memory Management

31. Explain garbage collection in Java.

Garbage collection is the process of automatically freeing memory by deleting unreachable objects.

32. What are the different types of memory areas allocated by JVM?

Method Area, Heap, Stack, Program Counter Register, and Native Method Stack.

33. What is the difference between Stack and Heap memory?

Stack stores method calls and local variables; Heap stores objects.

34. What is the purpose of the finalize() method?

To perform cleanup operations before the object is garbage collected.

35. Can you force garbage collection in Java?

You can suggest it using System.gc(), but it is not guaranteed.

Advanced Java Concepts

36. What is JDBC?

Java Database Connectivity (JDBC) is an API for connecting and executing queries with databases.

37. Explain the steps to connect to a database using JDBC.

Load the driver, establish a connection, create a statement, execute queries, and close the connection.

38. What is the difference between Statement and PreparedStatement?

PreparedStatement is precompiled and more efficient; it also prevents SQL injection.

39. What is the use of the transient keyword?

To indicate that a field should not be serialized.

40. What is the difference between Comparable and Comparator?

Comparable is used for natural ordering; Comparator is used for custom ordering.
Java 8 Features

41. What are lambda expressions?

Lambda expressions provide a clear and concise way to implement functional interfaces.

42. What are functional interfaces?

Interfaces with a single abstract method, used primarily with lambda expressions.

43. What is the Stream API?

A new abstraction introduced in Java 8 for processing sequences of elements.

44. What are default methods in interfaces?

Methods with default implementations in interfaces.

45. What is the Optional class?

A container object which may or may not contain a non-null value.

Miscellaneous

46. What is the difference between == and equals() in Java?

== compares object references; equals() compares object content.

47. What is the purpose of the static keyword?

To indicate that a member belongs to the class rather than instances.

48. What is the difference between String, StringBuilder, and StringBuffer?

String is immutable; StringBuilder is mutable and not thread-safe; StringBuffer is mutable and thread-safe.

49. What is autoboxing and unboxing in Java?

Autoboxing is the automatic conversion of primitives to their wrapper classes; unboxing is the reverse.

50. What are annotations in Java?

Metadata that provides data about a program but is not part of the program itself.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy