JAVA
JAVA
FEATURES
Variables
Datatype variable_name=value
Or
Datatype variable_name;
Variable_name=value;
Operator in java→
1. Arithmetic
2. Assignment
3. Comparison
4. Logical
5. Bitwise
6. Conditional
Control statements→
★ Conditional-if ,else, if else if ,nested ,switch
★ Loop-for,while,do while
★ Jump-break ,
ctrl+alt+downArrow eclipse
shift+alt+downArrow vscode
Java flow
1. Class
2. Methods
3. Variables
4. Constructor
5. Keywords
6. Data types
1.Class-
❖
2.Methods
Return ,static,void
Static - assign memory location once.
-executes at once
-A method declared as static belongs to the class itself, not to any objects of the class
OOPs Concept
Class & objects
Inheritance- Single,multilevel,multiple,hybrid,hierarchical
Abstraction
Encapsulation
Abstraction
Keywords -
Super →
- used to call parent class,
-
FInal →
- Cannot change value of variable when declared as final
- Cannot extends final class
This →
- Call any constructor
- Use in single class
Constructor→
- Initialize the instance variable
- It is special method of class
- Class name and constructor name is same
- Syntax →
Public class A{
Public A{ } //this is constructor ,no requirement of return type
}
- Default constructor
- Parameterized constructor /non parameterized
- Copy Constructor
Access Modifier→
- Public :Access from anywhere
- Private:Limited access for that class ,can’t extends
- Protected: limited access for same package subclass
- Default:cannot declare any modifier
Nested Class→
- Class in class
- Declare reference of main class when we have to create object of inner class
Composition→
-
Aggregation →
String Class→
- String literal > string str= “mystring”;
- Using new keyword > String str=new String(“mystring”);
- StringBuilder -built in methods like append,replace,etc
Exception→
- All handle by throwable class
- Checked : compile time error
- Unchecked exception : runtime error
- Try ,catch, finally, throw, throws
- Try block is always with catch block
- Finally after terminate print statements
- Throw use for custom exception
- Throws use for handle i/o exception
Array -
- It is collection of data having similar data types
- Int[] arr=new arr[5];
Synchro
Process synchro Thread synchro
Mutual Exclusive →
- Synchronized method()
- Synchronized block {}
- Static Synchronization
Co-operations→
- wait()
- notify()
- notifyAll()
Co-Operations
Wait→ use in synchronized methods
Notify→ run after wait method
Join Thread→
Interrupt Thread →
th.Interupt(); –Interrupt the thread
isInterrupted - return boolean value
Interrupted - return boolean value but reverse the value
Daemon Thread→
- Run in background of another thread
- Set before the start method
File Handling →
- File
- File Reader
- File Writer
Legacy Class → means jdk1.0 have some predefined classes which re engineer
predefined classes after jdk 1.2 with some hierarchy
Cursor→
- Enumeration
- Enumeration<Integer> en = list.elements();
while (en.hasMoreElements()) {
System.out.println(en.nextElement());
}
- Iterator
-Iterator<Integer> ir = list.iterator();
while (ir.hasNext()) {
System.out.println(ir.next());
}
- listiterator
-ListIterator<Integer> litr =list.listIterator();
while(litr.hasNext())
{
System.out.println(litr.next());
}
System.out.println("Iterate the Data Backwardly....");
while(litr.hasPrevious()) {
System.out.println(litr.previous());
}
Collection→
ArrayList
● The ArrayList class implements the List interface.
● It uses a dynamic array to store the duplicate element of different data types.
● The ArrayList class maintains the insertion order and is non-synchronized.
● The elements stored in the ArrayList class can be randomly accessed
Linked List
Doubly LinkedList
-
Circular LinkedList
Vector→
Stack→
Queue→
PriorityQueue→
ArrayDeque→
Set→
HashSet→
- Not follow insertion order
- Allow null value
- Non synchronize
-
LinkedHashSet→
- Not allow null value
TreeSet→
- follow sorting sequence
MAP Interface →
5
4
JAVA 8 →
Lambda Expressions
Lambda expression helps us to write our code in functional style. It provides a clear and
concise way to implement SAM interface(Single Abstract Method) by using an
expression. It is very useful in collection library in which it helps to iterate, filter and
extract data.
Functional Interface
An Interface that contains only one abstract method is known as functional interface. It
can have any number of default and static methods. It can also declare methods of
object class.
Functional interfaces are also known as Single Abstract Method Interfaces (SAM
Interfaces).
JDBC Java Database Connectivity→
Connectivity to mysql →
Connection con=null;
try {
con=DriverManager.getConnection("jdbc:mysql://localhost/jdbc11",
"root","1234");
if(con==null)
{
System.out.println("Connection Failed");
}
else {
System.out.println("Connection Establish
Successfully");
}
}
catch(Exception e) {
e.printStackTrace();
}
Callable interface→
Delimiter → DELIMITER (//,/,@,!,etc);
- it use to change terminator of sql
- Procedure →
- – createion
- create procedure comp()
- -> begin
- -> select * from emp;
- -> end
- -> !
- Call →call comp()!
- Show all procedures friom db→
- show procedure status where db='jdbc11'!