Feature of Java
Feature of Java
Features of Java:
Simple: Easy to learn, similar to C++ but without complexities like pointers.
Object-Oriented: Based on OOP concepts such as inheritance, polymorphism, and
encapsulation.
Platform-Independent: Java programs run on any system with a JVM.
Secure: Provides built-in security features and no explicit memory management.
Robust: Strong memory management with exception handling and garbage
collection.
Multithreaded: Supports concurrent execution of multiple threads.
High Performance: Uses JIT (Just-In-Time) compiler for better performance.
Distributed: Supports remote method invocation (RMI) and networking.
2. JDK, Java API, JVM, and Java Program Structure:
JDK (Java Development Kit): Includes tools for developing Java applications, such
as the compiler and debugger.
Java API: A collection of pre-defined classes and methods for performing common
tasks.
JVM (Java Virtual Machine): Converts Java bytecode into machine code for
execution.
Java Program Structure: Typically consists of classes, methods, and the main()
method, which serves as the entry point.
3. Static in Java:
The static keyword allows methods and variables to belong to the class rather than
an instance.
Static variables retain their values across all instances of the class.
Static methods can be called without creating an object of the class.
4. Method Overloading:
Defining multiple methods with the same name but different parameters (type or
number).
Improves readability and flexibility by allowing different ways to perform similar
operations.
5. Method Overriding:
Occurs when a subclass provides a specific implementation of a method defined in the
parent class.
The method in the subclass must have the same name, return type, and parameters as
in the parent class.
Allows achieving runtime polymorphism.
6. Constructor and Its Types:
A constructor is a special method that initializes an object when it is created.
Types of constructors:
1. Default Constructor: No parameters, assigns default values.
2. Parameterized Constructor: Accepts arguments to initialize variables.
3. Copy Constructor: Copies values from one object to another (not built-in but
can be implemented manually).
7. Super Keyword:
The super keyword is used to refer to the parent class.
It is commonly used to:
o Call the parent class constructor.
o Access parent class methods when overridden.
o Access parent class variables.
8. Garbage Collection:
Java automatically manages memory by reclaiming unused objects through garbage
collection.
The garbage collector removes objects that are no longer referenced.
It is triggered automatically but can be requested using System.gc().
9. Multiple Inheritance in Java:
Java does not support multiple inheritance with classes to avoid ambiguity.
However, multiple inheritance can be achieved using interfaces, where a class can
implement multiple interfaces.
10. Inheritance:
Inheritance allows a child class to acquire the properties and behaviors of a parent
class.
It helps in code reusability and establishing a hierarchical relationship between
classes.
Types of inheritance:
1. Single Inheritance: One class inherits from another.
2. Multilevel Inheritance: A class inherits from another class, which itself is
derived from another.
3. Hierarchical Inheritance: Multiple classes inherit from a single parent class.
11. Interface in Java:
An interface is a blueprint of a class that contains abstract methods (methods without
implementation).
A class implements an interface and provides implementations for its methods.
Interfaces support multiple inheritance.
12. Interface vs. Abstract Class:
Feature Interface Abstract Class
Only abstract methods (before Can have both abstract and concrete
Methods
Java 8) methods
Variables Public, static, final by default Can have instance variables
Multiple
Supports multiple inheritance Cannot extend multiple classes
Inheritance
Constructor Cannot have a constructor Can have a constructor
Let me know if you need further clarification