Core Java Fundamentals: Key Concepts and Definitions

1. The Role of the JVM

The JVM (Java Virtual Machine) is an engine that provides a runtime environment to drive Java code. It converts Java bytecode into machine-specific instructions, enabling Java’s “write once, run anywhere” platform independence.

2. Primitive Data Types

Primitive data types are the most basic, built-in types in Java that hold pure, simple values rather than objects. Examples include:

  • int: For integers.
  • boolean: For true/false values.

3. == Operator vs. equals() Method

  • ==: Compares memory locations to check if two variables point to the exact same object.
  • equals(): Compares the actual content or values stored within two objects.

4. Type Casting in Java

Type casting is the process of converting a variable from one data type to another:

  • Implicit casting (Widening): e.g., int to double.
  • Explicit casting (Narrowing): e.g., double to int.

5. Method Overloading

A feature that allows a class to have multiple methods with the same name, provided their parameter lists (number of parameters, types, or both) are different.

6. The ‘this’ Keyword

A reference variable used to refer to the current object invoking a method or constructor. It is primarily used to resolve naming ambiguity between instance variables and method parameters.

7. Arrays in Java

An array is a container object that holds a fixed number of values of a single, uniform data type.

Syntax: dataType[] arrayName = new dataType[arraySize]; (e.g., int[] numbers = new int[5];)

8. Encapsulation and Abstraction

  • Encapsulation: Wrapping data (variables) and code (methods) together as a single unit, often used for data hiding.
  • Abstraction: Hiding complex implementation details and exposing only essential features.

9. Constructors

A special block of code invoked automatically when an object is created to initialize its state.

  • Default constructor: No-argument.
  • Parameterized constructor: Accepts arguments.

10. Abstract Class vs. Interface

  • Abstract Class: Can contain abstract and concrete methods, supports single inheritance, and can have instance variables.
  • Interface: Traditionally contains only abstract methods and constants. Supports multiple inheritance.

11. Java GUI

GUI (Graphical User Interface) allows users to interact with applications through visual elements like windows, buttons, and menus instead of a command line.

12. AWT vs. Swing

  • AWT: Heavyweight and platform-dependent; relies on the local OS to render components.
  • Swing: Lightweight and platform-independent; written entirely in Java with customizable components.

13. Loops: While vs. Do-While

  • while loop: Entry-controlled; the condition is checked before execution.
  • do-while loop: Exit-controlled; the body executes at least once before the condition is checked.

14. Event-Driven Programming

A paradigm where the program flow is determined by user actions (events) such as mouse clicks or key presses.

15. Event Listener

An interface or object that waits for a specific event to occur and executes a block of code to handle it.

16. ActionListener

An interface used for handling action events, such as button clicks. It requires the implementation of the actionPerformed(ActionEvent e) method.

17. String vs. StringBuffer

  • String: Immutable; value cannot be changed. Best for fixed data.
  • StringBuffer: Mutable and thread-safe. Best for frequent text manipulations.

18. Layout Manager

An interface/class that governs how components are automatically arranged, sized, and positioned within a container.

19. Applets

Small Java programs designed to be embedded in web pages (Note: Deprecated in modern Java).

20. Applet Lifecycle Methods

  • init(): Initializes the applet.
  • start(): Starts execution.

21. Exception Handling

A mechanism to handle runtime errors gracefully using try, catch, and finally blocks.

22. Types of Exceptions

  • Checked Exceptions: e.g., IOException, SQLException.
  • Unchecked Exceptions: e.g., NullPointerException, ArithmeticException.

23. The paint() Method

Called whenever a GUI component needs to be drawn or redrawn. Used to render shapes, text, or images.

24. Threads and Multithreading

  • Thread: A lightweight sub-process and the smallest unit of processing.
  • Multithreading: Concurrent execution of multiple threads to maximize CPU utilization.

25. Creating a Thread

  1. Extending the Thread class.
  2. Implementing the Runnable interface.

26. The start() Method

Begins the execution of a thread by allocating resources and calling the run() method.

27. Applet init() Method

Used for one-time initialization tasks. Example: public void init() { setBackground(Color.BLUE); }

28. Thread Lifecycle

States include: New, Runnable, Running, Non-Runnable/Blocked, and Terminated/Dead.

29. The Thread Class

Provides methods and constructors to create and perform operations on threads.

30. The Cosmic Super Class

Refers to java.lang.Object, the root of the Java class hierarchy.

31. Design Patterns

  • Creational: Object creation (e.g., Singleton).
  • Structural: Object composition (e.g., Adapter).
  • Behavioral: Object interaction (e.g., Observer).

32. MVC Architecture

Separates an application into three components: Model (data), View (UI), and Controller (input logic).

33. Collection Frameworks

A unified architecture providing classes and interfaces (List, Set, Map) to store and manipulate groups of objects.

34. Wrapper Classes

Classes that encapsulate primitive data types into objects, necessary for use in Collections.

35. Method vs. Operator Overloading

  • Method Overloading: Multiple methods with the same name but different parameters.
  • Operator Overloading: Java does not support user-defined operator overloading, though + is overloaded for String concatenation.

36. Popular MVC Frameworks

  1. Spring MVC
  2. Apache Struts
  3. JSF (JavaServer Faces)