0% found this document useful (0 votes)
13 views3 pages

Java

The document is a structured Q&A guide on foundational Java concepts, covering topics such as Java fundamentals, keywords and modifiers, object-oriented principles, and advanced concepts. It explains key components like JDK, JRE, and JVM, as well as important keywords like static, final, and volatile. Additionally, it includes coding examples and instructions on how to save the guide as a PDF.

Uploaded by

Aman Trivedi
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)
13 views3 pages

Java

The document is a structured Q&A guide on foundational Java concepts, covering topics such as Java fundamentals, keywords and modifiers, object-oriented principles, and advanced concepts. It explains key components like JDK, JRE, and JVM, as well as important keywords like static, final, and volatile. Additionally, it includes coding examples and instructions on how to save the guide as a PDF.

Uploaded by

Aman Trivedi
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

This is an excellent set of foundational Java concepts.

Based on the notes you provided, I


have structured them into a clean, professional Q&A format suitable for a PDF guide.

Java Programming: Essential Concepts &


Interview Guide
1. Fundamentals of Java
Q: What is Java and why is it not considered a "pure" Object-Oriented Programming (OOP)
language?
A: Java is a high-level, class-based, object-oriented programming language designed to have
minimal implementation dependencies. It follows the "Write Once, Run Anywhere" (WORA)
principle.
Java is not considered a "pure" OOP language because it supports primitive data types
(such as int, boolean, char, etc.). In a pure OOP language, everything must be an object.

Q: Explain the key components of Java.


●​ JDK (Java Development Kit): The full toolset for developing Java apps. It includes the
JRE and development tools like the compiler (javac).
●​ JRE (Java Runtime Environment): Provides the minimum requirements to run a Java
application, including the JVM and core libraries.
●​ JVM (Java Virtual Machine): An abstract machine that executes Java bytecode. It
provides a platform-independent execution environment.
●​ Java Standard Library: A vast collection of pre-written classes (I/O, networking, data
structures).

2. Keywords and Modifiers


Q: What is the significance of the static keyword?
A: The static keyword indicates that a member (variable or method) belongs to the class itself
rather than a specific instance (object).
1.​ Shared Memory: Only one copy exists for all instances.
2.​ Access: Can be called without creating an object (e.g., [Link]()).
3.​ Efficiency: Used for constants or utility methods (like [Link]()).

Q: Explain the difference between final, finally, and finalize.


| Keyword | Purpose |
| :--- | :--- |
| final | Used to declare constants (variables that can't change), prevent method overriding, or
prevent class inheritance. |
| finally | A block used in exception handling that always executes (useful for closing
resources), whether an exception occurs or not. |
| finalize | A method called by the Garbage Collector before an object is destroyed. (Note:
Deprecated in modern Java). |

3. Object-Oriented Principles
Q: What are Constructors?
A: Constructors are special methods used to initialize objects. They have the same name as
the class and no return type.
●​ Default Constructor: Provided by Java if you don't write one; initializes attributes to
default values.
●​ Parameterized Constructor: Allows passing values at the time of object creation.

Q: Differentiate between Method Overloading and Method Overriding.


●​ Overloading (Compile-time Polymorphism): Multiple methods in the same class with
the same name but different parameters (type or number).
●​ Overriding (Runtime Polymorphism): A subclass provides a specific implementation for
a method already defined in its parent class using the @Override annotation.

4. Advanced Concepts
Q: What is a Singleton Class?
A: A design pattern that ensures a class has only one instance and provides a global point of
access to it. This is achieved by:
1.​ Making the constructor private.
2.​ Creating a private static instance of the class.
3.​ Providing a public static method (usually getInstance()) to return that instance.

Q: What is the volatile keyword?


A: It is used in multi-threading to ensure that a variable's value is always read from and written
to the main memory, not cached locally by a thread. This ensures visibility across multiple
threads.

5. Coding Examples
Type Casting
Java

// Implicit (Widening) - Small to Large​


int myInt = 9;​
double myDouble = myInt; ​

// Explicit (Narrowing) - Large to Small​
double d = 9.78;​
int i = (int) d; // i becomes 9​

File I/O (NIO Way)

Java

Path path = [Link]("[Link]");​


// Write​
[Link](path, "Hello Java", [Link]);​
// Read​
String content = [Link](path);​

How to save this as a PDF:


1.​ Copy the text above.
2.​ Paste it into a Markdown editor, Google Docs, or Microsoft Word.
3.​ Go to File > Export / Save As and select PDF.

Would you like me to add more advanced topics like Java Streams, Lambda
expressions, or Collections to this list?

You might also like