JAVA 5
Boilerplate Comments
Data Types and variable
initializing multiple similar datatype variable
Wrong format to initialize
@cseabhisheks 1
JAVA 5
Primitive Data Type
Scanner Class
(import java.util.Scanner)
@cseabhisheks 2
JAVA 5
Operator Boolean not change into int in java but in c
Boolean convert into int by default
@cseabhisheks 3
JAVA 5
Important concept of function
Important concept of function
@cseabhisheks 4
JAVA 5
Data Type Conversion /widening/implicit
conversion
Byteshortint long floatdouble
Type Casting / Narrowing /Explicit
Conversion
Operators
1. Arithmetic
a. Binary (mathematical) operator: + - * / %
b. Unary operator: ++x x++ --x x—
c. Ternary operator: ?:
2. Relational ( == != > >= < <= )
3. Logical ( && || ! )
4. Assignment ( = += -= *= %= /=)
5. Bitwise (
a. &(bitwise and)
b. |(bitwise or)
c. <<(shift left)
d. >>(shift right)
e. ~(one’s complement)
f. ^(bitwise exclusive or) )
@cseabhisheks 5
JAVA 5
Bitwise Operator in detail
@cseabhisheks 6
JAVA 5
Break and Continue Statement
Break(to exit loop) Continue(to skip specific condition iteration)
Output: break Output: continue
Math function
@cseabhisheks 7
JAVA 5
String Function
Associativity of operator (* and / has both same important and rest bodmas rule is same)
Err for printinsg error message
@cseabhisheks 8
JAVA 5
@cseabhisheks 9
JAVA 5
Conditional Branching/Selectional
Control/Decision Making
If Statement if else Statement if only one statement
Else if Statement Nested if Statement
Switch statement
@cseabhisheks 10
JAVA 5
Loop Statement
1)Exit Controlled Loop/post tested loop (do while loop)
2)Entry Controlled Loop/pre tested loop (for loop,for each loop, while loop)
FOR EACH LOOP
@cseabhisheks 11
JAVA 5
Function
call by value call by reference
(primitive data type including string) (object including string builder)
Function overloading:
1. Parameter (same name different parameter)
2. Datatype (same name but parameter datatype different)
Array
For understanding only
1. Int dim[row]
@cseabhisheks 12
JAVA 5
2. Int dim2[row][column]
3. Int dim3[depth][row][column] (generally not used but can be)
One dimensional Array
Multidimensional Array
2d and 3d array and many more
OOPS: Class
Object: Entities in the real-world (ex-p)
Classes: Group of these entities (ex-pen)
this keyword: It is used to use already define variable(ex-this.price)
@cseabhisheks 13
JAVA 5
Note: By convention class first letter of name is written in capital letter
Class vs object vs constructor
This and Super Keyword
Java Constructor Chaining – Calling one constructor from another constructor
is generally referred to as constructor chaining. This can be achieved in two
ways.
Super keyword: use to refer immediate parent class object
@cseabhisheks 14
JAVA 5
this () (with in same class)
super () (with parent class in child class)
This keyword to differentiate current and local variable
How constructor is calling (super keyword is used by java by default if
not used)
Final Keyword
1. Final variable
@cseabhisheks 15
JAVA 5
2. Final methods
3. Final class
Static variable (to count total object) and instance variable
Constructor:
constructor overloading: multiple constructors within a class each with different parametrized
@cseabhisheks 16
JAVA 5
here I explain three: parametrized constructor, default (non-parametrized) and constructor overloading
Shallow copying constructor deep copying constructor
Nesting Method Variable shadowing
(Same property in each parent and child class and its child classes)
@cseabhisheks 17
JAVA 5
1. Encapsulation (wrapping up data and methods under a single
unit .it also implants data hiding using access specifier like
default private protected)
2. Inheritance (passing of property and methods from parent
class (base class) to child class (derived class))
Type of inheritance same logic will work as human extends animal
@cseabhisheks 18
JAVA 5
3. Polymorphism
Runtime/dynamic polymorphism (many forms for function only):
method overriding
Static/compile time polymorphism (many forms for function
only): method overloading
@cseabhisheks 19
JAVA 5
4. Abstraction (hiding all unnecessary details and showing only
important parts while encapsulation hide important data like
password)
Abstraction using abstract method
(we don’t use abstract keyword with variable (i.e. abstract int x. it is wrong;) we use it with function only (i.e. abstract void
m0() ;)
Abstraction using non abstract method
Making and calling abstract class constructor using super keyword
@cseabhisheks 20
JAVA 5
5.Interfaces (part of abstraction)
We can use interface instead of class for main file
Extending interface
Multiple inheritance is not supported by java but can be implement using interface
@cseabhisheks 21
JAVA 5
abstraction using interface keyword
Package
Main Function Folders/Packagess
Packages
@cseabhisheks 22
JAVA 5
Errors in JAVA
Try and catch finally
throws keyword
Throw keyword (for custom exception)
@cseabhisheks 23
JAVA 5
Operator Overloading
@cseabhisheks 24
JAVA 5
Awt
Abstract Window Toolkit (AWT) is an API used for developing GUI(Graphic
User Interfaces) or Window-Based Applications in Java.
@cseabhisheks 25
JAVA 5
@cseabhisheks 26
JAVA 5
@cseabhisheks 27
JAVA 5
@cseabhisheks 28