Java Definitions
Java Definitions
6. Abstraction: Abstraction hides complex implementation details and shows only the
necessary features. It can be achieved using abstract classes or interfaces. For
example, a "Remote" interface only shows essential functions like power On and
volume Up.
8. Method Overloading: Method overloading allows multiple methods with the same
name but different parameter lists. It helps improve code readability. For example, a
print () method that prints integers and another that prints strings.
11. Aggregation: Aggregation is a special type of association where one class contains a
reference to another class, but both can exist independently. For example, a "Library"
class containing "Book" objects.
12. Composition: Composition is a stronger form of aggregation where the contained
object cannot exist independently. For example, a "House" class composed of
"Room" objects, where rooms cease to exist without the house.
13. Interface: An interface is a contract that defines a set of abstract methods a class
must implement. It supports multiple inheritance. For example, a "Flyable" interface
with a fly() method implemented by both Bird and Airplane classes.
14. Abstract Class: An abstract class is a class that cannot be instantiated and may have
abstract methods. It provides a base for other classes to build on. For example, a
"Shape" abstract class with an abstract draw () method.
15. Static Keyword: The static keyword makes a class member belong to the class rather
than any object. For example, a static count variable shared by all instances of a class.
16. Final Keyword: The final keyword can be used with variables, methods, or classes to
restrict modifications. For example, a final class cannot be subclassed, and a final
variable cannot change its value.
17. This Keyword: This keyword refers to the current object. It is used to resolve naming
conflicts and invoke constructors. For example, this.name refers to the instance
variable name.
18. Super Keyword: The super keyword refers to the superclass and is used to access its
methods or constructors. For example, super () calls the parent class constructor.
19. Object Class: The Object class is the root class of all Java classes. It provides basic
methods like to String (), equals (), and hash Code (). For example, every Java class
inherits these methods.
20. Packages: Packages are collections of related classes and interfaces that help
organize code and avoid naming conflicts. For example, java. util contains utility
classes like Array List and HashMap.
1. Single Inheritance
Single inheritance involves one child class inheriting from a single parent class.
It helps in code reusability and allows the child class to access the parent’s methods
and properties.
Example: A "Dog" class inherits from an "Animal" class.
2. Multilevel Inheritance
Multilevel inheritance occurs when a class is derived from another derived class.
It forms a chain where each class inherits properties from its immediate superclass.
Example: "Baby Dog" → "Dog" → "Animal," where Baby Dog inherits properties from
both Dog and Animal.
3. Hierarchical Inheritance
Hierarchical inheritance involves multiple child classes inheriting from a single parent
class.
It models a tree-like structure where several classes share common properties.
Example: "Car" and "Bike" classes inherit from the "Vehicle" class.
Thread in Java
Multithreading in Java
String in Java
StringBuilder in Java
Operators in Java:
In Java, operators are special symbols or keywords used to perform operations on variables
and values. They help manipulate data, make comparisons, and control program flow.
Operators are essential building blocks of Java programs, allowing you to solve problems
efficiently!
1. Arithmetic Operators
These operators perform basic mathematical calculations like addition, subtraction,
multiplication, and division.
/ (Division): Divides the first value by the second (returns the quotient).
Example:
If a = 10 and b = 3:
a + b results in 13
a % b results in 1 (remainder)
> (Greater than): Returns true if the first value is greater than the second.
< (Less than): Returns true if the first value is less than the second.
>= (Greater than or equal to): Returns true if the first value is greater than or equal
to the second.
<= (Less than or equal to): Returns true if the first value is less than or equal to the
second.
Example:
If x = 5 and y = 10:
x == y results in false
3. Logical Operators
These operators are used to combine multiple boolean expressions or conditions.
! (Logical NOT): Reverses the result (true becomes false, and vice versa).
Example:
If a = 5 and b = 10:
4. Assignment Operators
These operators assign values to variables.
= (Simple assignment): Assigns the value on the right to the variable on the left.
+= (Add and assign): Adds the right value to the left variable and assigns the result.
-= (Subtract and assign): Subtracts the right value from the left variable and assigns
the result.
Example:
If x = 5:
x += 3 → x becomes 8
x *= 2 → x becomes 16
5. Unary Operators
These operators work with a single operand.
Example:
If x = 5:
++x makes x → 6
6. Bitwise Operators
Operate on bits of integer values.
| (Bitwise OR)
^ (Bitwise XOR)
~ (Bitwise NOT)
7. Ternary Operator
A shorthand for if-else statements.
Example:
Conditional Logic: Control program flow with comparisons and logical checks.