0% found this document useful (0 votes)
5 views

JAVA

java notes

Uploaded by

kalamkar.adi11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

JAVA

java notes

Uploaded by

kalamkar.adi11
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

JAVA

Software is a collection of progrmas

System software Application software


C,C++
Standalone & distributed

Enterprise & Web


.net

Java uses jit compiler


Class makes from 8 bits

FEATURES

● Simple and Easy to Learn.


● Object-Oriented Programming.
● Platform Independence.
● Automatic Memory Management.
● Security.
● Rich API.
● Multithreading.
● High Performance.

Jvm is platform independent

OOPs concept in detail


● Encapsulation
● Inheritance
● Polymorphism
● Abstraction

Encapsulation - The binding of data into a single entity is called encapsulation.


The purpose of encapsulation is information hiding and data hiding to secure our data at
that time we use private access specifier

Example :- Bank Account


Comments in java
// write comment here
/* write comment here */

Data types are used to define size of a data

Data types in java


1.Primitive data type-
built in data types , stores single value
Byte, long, int, short, float, char, boolean, double,
2. Non primitive data type-
user defined data types (Except string), stores multiple values
String,array,Classes

Variables
Datatype variable_name=value
Or
Datatype variable_name;
Variable_name=value;

1. local Variable – Available in method only and declare in method,also declare in


parameters of method
2. Instance Variable – declare inside the class but outside method
3. Static Variable – declare using static keyword ex static int a;,to access this we do not
need to create an object of that class.it is accessible only in that class.

Type casting and Type Conversion

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

Inheritance- parent child

Polymorphism -many forms


Perform one task using many ways then polymorphism is use

Method Overloading-same name but different parameters


Method Overriding -same name same parameters
Abstraction - Hiding the internal implementation and showing necessary information
1. Abstract - implement and un-implement method using abstract keyword
- Can't create object of abstract class
- Memory management
- Class B extends class A
2. Interface
- un-implement methods
- Can't create object
- Does not require to write method as abstract
- Implement using interface keyword
- Class B implements Interface A
Encapsulation- all java classes are encapsulation

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];

Task class not found exception


Array index out of bound

Collection → interface class


List →
- ArrayList → List obj =new ArrayList() ;
- LinkedList
Set→
- Hashset
- Treeset
- Shortedset
- LinkedHashset
MultiThreading→
1.Thread(class)
2.Runnable(interface) →
- Functional Interface → which interface have only one abstract method

In single class only one method is public

Data inconsistency →error


to overcome this java introduce →Mutual exclusive
- Synchronized method() → all operations wait for run the first operation then
the run one by one
- Synchronized block {} →include only that operation we want to synchronize
- Static Synchronization → we cannot use variable in static method without
declare it static variable

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

- LinkedList implements the Collection interface.


- It uses a doubly linked list internally to store the elements.
- It can store the duplicate elements.
- It maintains the insertion order and is not synchronized.
- In LinkedList, the manipulation is fast because no shifting is required.

● Implement by list and dequeue


● Follow insertion order
● Allows multiple null value
● Not synchronize
● Not thread safe

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 →

- It sort data in top–bottom & right–left


- It has 11 buckets only 0-10
1
0

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→

Connection → Establish connection or built path

Statement→ Run simple queries

Prepared Statement→ Run Predefined queries

Callable→Call Stored Procedures

ResultSet→ Retrieve data

execute() → used to run ddl queries


executQuery() → used to run ddl queries
executeUpdate() →used to run dml queries

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'!

You might also like