In Java, we use Scanner
to take input from the user
2. Print
You use System.out.println()
to print output:
3. Mathematical Operators
Common operators include +
(addition), -
(subtraction), *
(multiplication), /
(division), %
(modulus):
4. Assignment and Logical Operators
- Assignment:
=
- Logical Operators:
&&
(AND), ||
(OR), !
(NOT):
5. If-else
Conditional statements:
6. Switch Case
Efficient alternative to multiple if-else
:
7. Loops
8. Break and Continue
- Break: Exit loop.
- Continue: Skip the current iteration.
9. Class
Blueprint for objects, containing attributes (fields) and methods.
10. Object
Instance of a class:
OOP Concepts
11. Inheritance
Allows one class to inherit fields and methods from another.
12. Encapsulation
Restricting access to class members using access modifiers (private
, public
, etc.), typically with getters/setters:
13. Abstraction
Hiding complex details and showing only essential features.
- Interface: All methods are abstract by default.
14. Polymorphism
- Method Overloading: Same method name with different parameters.
- Method Overriding: Child class redefines a method from the parent class.
15. Static Keyword
Static methods/variables belong to the class, not instances:
16. Constructors
A special method used to initialize objects.
17. Constructor Overloading
Multiple constructors with different parameters:
18. Package
Groups related classes together:
19. Access Modifiers
public
: accessible everywhere.
private
: accessible only within the class.
protected
: accessible in the same package and subclasses.
- (default): accessible within the same package.
20. This Keyword
Refers to the current object instance:
21. Final Keyword
- Final variable: Can’t be changed.
- Final method: Can’t be overridden.
- Final class: Can’t be extended.