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

Java Documentation (AutoRecovered)

The document outlines various Java programming concepts and topics covered over several days, including platform independence, keywords, data types, flow control structures, and methods. It details the creation of Java projects, variable declaration and initialization, as well as examples of programs related to areas of geometric shapes and student marks. Additionally, it discusses the use of packages, classes, and methods, along with practical programming exercises.

Uploaded by

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

Java Documentation (AutoRecovered)

The document outlines various Java programming concepts and topics covered over several days, including platform independence, keywords, data types, flow control structures, and methods. It details the creation of Java projects, variable declaration and initialization, as well as examples of programs related to areas of geometric shapes and student marks. Additionally, it discusses the use of packages, classes, and methods, along with practical programming exercises.

Uploaded by

Radhika Punnam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 96

Java Documentation

------------------------11/9/2023-Monday-------------------------------------
Java is platform independent
Java has 51 or 52 key words
Programs
Area of square
Area of rectangle
Area of circle
------------------------12/09/2023-Tuesday--------------------------------------
Addition of 2 nosfyg
Sub of 2 nos
Mul of 2 nos
Div of 2 nos
Power bill
Shopping bill
----------------------------13/09/2023-Wednesday-------------------------
Datatypes
Byte
Short
Int
Long
Float
Double
Boolean
Char
Submission form—just datatypes
Power bill-just datatypes

--------------------------------14/09/2023-Thursday------------------------
How to create new java project in spring tool
How to create class
---------------------------15/09/2023-Friday------------------------------
Execution starts from main method
In java it reads line by line
Programs
Area of square, rec, circle, triangle

-----------------------------16/09/2023-Saturday--------------------------------

Variable decalartion;
Variable initialization;
//17-sun-h
//18-mon(vin)-h
//19-tue(vin)-h
-----------------------------20/09/2023-Wednesday------------------------------
Datatypes
Int -8 bit
Byte-16
Short-32
Long-64
Float-32
Double-64
Boolean-1
Char-16

-------------------------------------21/9/2023-Thursday--------------------------
Keywords
Datatypes

Byte – 8 bits
Short -16 bits
Int – 32 bits
Long – 64 bits

Float – 32 bits
Double – 64 bits
Boolean – 1bit

Char c = ‘n’;
Char n = 67;
16 bytes
Single quotatations means no ascii
-------------------------------
Int x = 34;--right
X = 34;---wrong
-------------------------------------
Byte age;---var declaration
Age = 23---right
Byte age = 23;--wrong
Byte age1 = 34;

Byte age;//var decl


Age = 36;
Age = 45;

//var inti
(0r)
Byte age = 12;//var int

-----------------------------22/09/2023-Friday---------------------------------

Programming

Datatypes is 2 types

Primitive -

Non – prim-string, arrays,

-------------------23/09/2023-Saturday-------------------------------------------

2 programs
Datatypes capability is it can store some values it has no conditions

------------------25/09/2023-Monday-------------------------------------------

Flow controls:

If---syntax

Else -if

If/else

Switch

Break
Default

For

While

Do while

Class one{//start point of class


Main()

Operators

Dif b/w = & ==

---------------------------------26/09/2023-Tuesday-----------------------------

package com.slokam;

public class StudentMarks { JVM calls main method

public static void main(String[] args) {//Execution starts from main method
int marks;
//marks = 34;
//marks = 36;
//marks =50;
//marks = 70;
marks = 90; int = 32 bit
if (marks<=35) {
System.out.println("Fail");
}
if (marks>=36&&marks<50) {
System.out.println("Pass");
}
if (marks>=50&&marks<70) {
System.out.println("second class");
}
if (marks>=70&&marks<90) {
System.out.println("First class");
}
if (marks>=90&&marks<=100) {
System.out.println("Distinction");
}

When we run a program the JVM calls main method execution starts from here
here in above program at first we declared the variable and initialized the
variable. We have taken int datatype for variable so it creates 32 bit data(it
allocates 32 bit memory).our value is stored in that 32 bit. Now it checks series of
if statements I have initialized marks = 90. Here it will check all the if statements
which if statement is true it will print in the console.

Else if stops the execution when the condition is true it will not check all the
conditions as if statement.

----------------------------------27/09/2023-Wednesday----------------------------

SEP1234

ATM card series of if


Nested if
Nested if else

--------------------------------28/09/2023-Thursday------------------------------

If
If else
If if if

If else if else if else

If { if{else if()

35567.567 double

Ro = true
Bus a= true;
Seats = true;
Tickets = true;
Paymet = true;

-------------------------------------29/09/2023-Friday-------------------------

No float and double and switch


Case should be same dtype

Switch
If
If else

If last no need of break

If
If else else break default switch

1) Switch test

-----------------------------------30/09/2023-Saturday---------------

If and switch are sel


It checks only one condition

Scanner class new keyword


53 keywords

Today 2 programs
1.Restuarant.java
2.Smarks.java

-----------------1/09/2023—Sunday-------
--------------------------------2/09/2023-Monday-----------------------

Package for segregate classes


Mango package example
Scanner is not in com.A we need to import in to from
We are declare from input
Initialize from console
Created a Java Project “package emp & stu”,
Created 2 packages com.A&com.B
Today 2programs
1. Employee.java
2. Student.java

--------------------------3/09/2023-Tuesday---------------------------

Heap memory

Gmail example, Facebook example, owner only creates one class and we are
objects

Package emp&student
Stu.java new program just different appoarch
-------------------------04/10/2023-Wednesday--------------------------

Here we can write two types of variables


1)class variables- declaration and initialization
2)Local varibles- declaration and initialization

-----------------------05/09/2023-Thursday------------------------

//Don’t write method inside method

Class is nothing but blue print


Class create class keyword
Object – instance of class
Object Create using new keyword
For any given class we can have n number of objects/instances

Student s = new student();

Public class siva{


//instance variables—how can we initialize
//without object we caant initialize
Siva s = new siva();
s.sid=1;
Int sid;

//Methods for defining fuctionality


Void add(){

}
Main()
{
}

}
Main
First object creation for class
Then it contains all instance variables and instance methods
From this you can call all the instance variables and instance methods from main
method
Method call
Method execute

--------------------------06/09/2023-Friday----------------------------

Project – class and object


Package – Microsoft
Program – Calculatordynamic.javavoid – it means iam not going to return
anything to calling method just execute

Local variables we cant change in yesterday only call today dynamic

L,b
Rect = 2*l+b
Area
Square = a*a;

Circle I rad,d pi;


Ci = pi*r*r;

Calculatordynamic.java
CalculatorParameters.java
Areasbymethods.java
----------------------------------07/10/2023-Saturday------------------

Method name and class name should not be same


Method purpose

Void Metodname(int a,String h,double b, int c){

}
Classname ref.methodname();
package microsoft;

import java. util. Scanner;


public class Shoppingbilldynamic { JVM
double vat = 10;

Main method is called by


void bill (int quantity, double price) {
JVM. But Main method
System.out.println("Enter the quantity: "+quantity); consists of void return type
System.out.println("Enter the Price: "+price); so main method don’t
return any thing to JVM just
double cvat = (quantity*price)/vat;
it execute that’s it.
System.out.println("cvat on your bill: "+cvat);

double fbill = (quantity*price) +cvat; ----------------------------


System.out.println("Final bill with vat added:
09/10/2023-
"+fbill); Monday---------------------------
}

public static void main (String [] args) {

Scanner s = new Scanner (System.in); 3 programs


System.out.println("Please enter the quantity: ");
int q = s.nextInt();
System.out.println("Please enter the price: "); 1)Shopdis.java
double p = s. nextDouble(); 2)Programflowtest.java
3)shopbill.java

Shoppingbilldynamic b = new Shoppingbilldynamic(); ------------------------------


b.bill(q,p);
10/10/2023-
s.close(); Tuesday-------------------------

3 programs
} 1.sbill.java
} 2.test.java
3.Circle.java
Void – return type

Bill – met name

Method without any argum

Void bill(int id, String name) method with arg//instance methods

Ins methods & insta variables can communicate directly

---------------------------11/10/2023-Wednesday-------------------------

Core java- 2.5 months-60


Adv java- jdbc -3months - 60

Hibernate
Spring boot
Microservices
Project
AWS

MySQL
logical programs
1.8 features
Interview questions

Project : class and object


Package: Microsoft
Program: BankAtm.java

How to change class name if you want?

->If you want to change use directly change or right click

How cursor comes like this enter insert button or fn+insert.

->->->Testing for/about method return types


----------------------------12/10/2023-Thursday--------------------------
Datatypes

Int marks =127


Arrays
Array decla value ini
We can write in 2 ways

Byte b =12;
Byte[] n ={12,34,56,78}
N[2]=100;
Sop(n[0]);//no extra

Byte[] m=new byte[3];


M[0]=12;
M[0]=35
M[2]=45;
Sop(m[0],m[1],m[2]);

String[] name = {“sde”,”sef”,”ddg”};


Sop(name);
Sop(name[0]);
Sop(name[1]);

String[] name = new String[3];


Name[0]=”sde”;

Sop(nam[0]);

1)DatatypesRange.java
2)smarks.java
3)sdetails.java

-----------------------------13/10/2023-Friday--------------------------

2 ways of init an decla of arrays


String[] nam = {50}

If(t){
}
Selective – if, switch – condition checked only once

For (){
} conition true ayinata sepu it will iterate

//I =1 t i+1
//i=2 t i+1
//i=9 t i+1
//i=10 t i+1
//i

//initia //condi
For(int I =1; i<10; i=i+1){
Sop(i)//1…9
}

Int k =1
If(k<=5){
Sop(k)

String[] nam = {“ram”,”as,few}


Sop(nam.length)

//method ante oka functionality ni call cheyali


//string class lo length ane method untadi

For(int I =1; i<=06(7){i<=names.length-1}array index out of bound exception;


i=i+1){
Sop(nam[i])//1…9
}
Int[] marks = {45,56,78,34,89,90}
//total marks
//grade percentage
// pass or fail
//how much sub got failed

-------------------------------------14/10/2023-Saturday----------------

Array lo unna data ni add cheyali

Int[] marks ={34,56,78,89,90,92};


Marks.length -- method == length 0to 5 ---length-1;

Int t=0;//34;90;168;287;347;439
{
For(int i=0;i<=marks.length-1;i=i+1)
{
Tmarks =tmarks+marks[i];
}
Sop(tmarkks)
Sop(tmarks/6) per

If(marks[i]>=35)
{sop(pass+marks[i]);
}
Else{
Sop(fail);
}
}

Clock
I want timeh-24,m-60,s-60
I want tables

If hour rotate 1 time,60*60,60*60*60

Tables by nested for loop

Project: Nested for loop


Package: com.slokam
Programs:1)Clock.java
2)Tables.java

Program : Letter count “SLOKAM”


public class LetterCount {
public static void main(String[] args) {
String inputString = "Slokam";
int[] letterCount = new int[26]; // Assuming we are only counting letters A-Z
(case-insensitive)

// Convert the input string to uppercase to make the counting case-insensitive


inputString = inputString.toUpperCase();

// Loop through each character in the string


for (int i = 0; i < inputString.length(); i++) {
char ch = inputString.charAt(i);
if (Character.isLetter(ch)) {
int index = ch - 'A'; // Calculate the index for the letter A-Z
letterCount[index]++;
}
}

// Display the letter counts


for (char letter = 'A'; letter <= 'Z'; letter++) {
int index = letter - 'A';
int count = letterCount[index];
if (count > 0) {
System.out.println(letter + ": " + count);
}
}
}
}
---------------------------------------------16/10/2023-
Monday---------------------------------------------------------------
//Nested for loop
package com.slokam;

public class Hi {

public static void main(String[] args) {


for(int i=1;i<=2;i++) {
for(int j=1;j<=2;j++) {
System.out.println("Display no: "+j);
for(int z=1;z<=3;z++) {
System.out.println("Hi");
}
}
}

Nested for loop mechanism explained in notes in detail

Till now we covered topics in flow controls


Conditional statements
If
If else
Else if

If()
Elseif()
Nestedif /Nestedelse

Switch
Nested switch
Case
Break
Default

Looping statements
For()
{}

While()
{}

Dowhile()
{}
OVER ALL COVERED TOPICS
Datatypes
Flow contols
Object
Class
Methods
Arrays

Method with args(datatypes)(arrays byte[],)


Method args and return type(data types. String, void), Arrays.
Project: while, dowhile, Nested forloop
Packages:Default,com. cisco,com.slokam
Programs:Tables.java,marks.java,Check.java,Hi.java,DoAndWhileDifference.java
(5programs-2 hw).

---------------------------------------------17/10/2023-
TUESDAY-------------------------------------------------------------
Topic: Methods different ways usage
Project: Methods with dif types
Package: com.slokam
Programs:1)Slkstd.java
2)test.java
3)Student.java
How to use methods in different ways
Way 1:Normal instance method without any parameters
void m1()
{
System.out.println("Normal instance Method");
System.out.println("Returntype it is not going to return anything to
the calling method");
System.out.println("Method call without any parameters");

}
Way 2:Normal instance method with parameters datatypes (only single
values can be taken){byte,short,int,long,float,double,char,Boolean,String}

void m2(int b, String k)


{
System.out.println(b);
System.out.println(k);
System.out.println("Normal instance Method");
System.out.println("Returntype it is not going to return anything to
the calling method");
System.out.println("Method call parameters:(byte, short, int, long,
float, double, boolean, char, String)");

Way 3:Normal instance method with parameters Arrays(Multiple values can


be taken){byte[],short[],int[],long[],float[],double[],char[],Boolean[],String[]}
void m3(double[] marks,String[] subj)
{
System.out.println("Student Marks Address:"+marks);
for(int i=0;i<marks.length;i++)
{
System.out.println("Marks Obtained: "+marks[i]);
}
System.out.println("Subjects Address: "+subj);
for(int i=0;i<subj.length;i++)
{
System.out.println("Subjects: "+subj[i]);
}
System.out.println("Normal instance method");
System.out.println("returntype it was not returning anything to calling
method");
System.out.println("Method call parameters:(byte[], short[], int[], long[],
float[], double[], boolean[], char[], String[])");
}

Way 4:Normal instance method with method call parameter can be class
instance/object
void m4(Student std)
{
System.out.println(std.sid);
System.out.println(std.sname);
System.out.println("Student Marks Address: "+std.marks);
for(int i=0;i<std.marks.length;i++)
{
System.out.println("Marks Obtained: "+std.marks[i]);
}
System.out.println("Subjects Address: "+std.subj);
for(int i=0;i<std.marks.length;i++)
{
System.out.println("Subjects: "+std.subj[i]);
}
System.out.println("Normal instance method");
System.out.println("returntype it was not returning anything to calling
method");
System.out.println("Method Call Parameter can be class
instance/Object also");

----------------------------18/10/2023-WEDNESDAY------------------------

TOPIC: How to pass class instances in methods&iteration&by different


return types
PROJECT: Methods with dif types
PACKAGES: com.slokam
PROGRAMS:1)Employee.java
2)EmployeeTest.java
3)EmployeeTest1.java

How to pass class instances in methods


package com.slokam;

public class EmployeeTest {

void addemployee() {

System.out.println("Method Executed"+"\n");

void addallemployees(Employee emp[]) {

System.out.println(emp[0].eid);
System.out.println(emp[0].ename);
System.out.println(emp[0].esal);
System.out.println(emp[0].edesig+"\n");

System.out.println(emp[1].eid);
System.out.println(emp[1].ename);
System.out.println(emp[1].esal);
System.out.println(emp[1].edesig+"\n");

System.out.println(emp[2].eid);
System.out.println(emp[2].ename);
System.out.println(emp[2].esal);
System.out.println(emp[2].edesig+"\n");

}
JVM
void getallemployees(Employee emp[]) {

for(int i=0; i<= emp.length-1;i=i+1) {


System.out.println(emp[i].eid);
System.out.println(emp[i].ename);
System.out.println(emp[i].esal);
System.out.println(emp[i].edesig);
System.out.println("-----Next Employee-----"+"\n");

}
}

public static void main(String[] args) {

Employee e = new Employee();


e.eid = 1;//initializaton
e e1
e.ename = "Radhika";
e.esal = 10000000.000;

Heap Memory

e.edesig = "java developer";

Employee e1 = new Employee();


e1.eid = 2;
e1.ename = "lucky";
e1.esal = 13000000.000;
e1.edesig = "Software developer";

Employee e2 = new Employee();


e2.eid = 3;
e2.ename = "Pinky";
e2.esal = 14000000.000;
e2.edesig = "Python developer";

Employee d[] = {e,e1,e2};


EmployeeTest t = new EmployeeTest();
t.addemployee();
t.addallemployees(d);
t.getallemployees(d);

}
Today Class Summary

We have learnt about methods

 Void add emp(employee e)


{

*if you see this method create single employee object and initialize and pass or
send it.

 Void addallemp(employee[] e)
{

*we need create many emp objects and we need to store all this in one one array
and send or pass it

 Employee m1()
{}

*If we call m1 one employee object

 Employee[] m2()
{}

*If we call m2 array of employee objects will come

 First 2 methods takes one or array of objects.Next 2 methods gives


one or array of objects.

**Previously learnt this


 Void m1(int i)
{}
 Void m1(int[] i)
{}

 Int m3()
{
Return 3;
}

 Int[] m3()
{
Int[] n ={12,23}
Return n;
}

-------------------------------------------------19/10/2023—Thursday----------------------

Topic: OOPS CONCEPTS(Public, Private, Protected, default)& How to


initialize private proterties by using set and get methods

Project: OOPS CONCEPTS


Package: com.A, com.B
Programs:one.java, two.java, three.java

OOPS CONCEPTS:

So far I learnt about


1)Class
2)var
3)methods

Today I have learnt about public, private, default, protected


How to initialize private proterties

Public: By using public access modifier we can use within class,outside class,
within package , outside package by import

Private: Only within class

Default: within class, outside class, within package


Protected: within class,outside class, within package,outside package also but
using relation we will learn in inheritance concept.

Structure
Public default final abstract interface extends class name siva
{
Public default private protected final static transient volatile var =13

Public default private protected final static synronized abstract methodsname


m1()
{
}

We will learn all these keywords in these below order

Public default private---Protected extends final static abstract interface


synchronized transient volatile
-------------------------------------------20/10/2023---Friday-------------------------------

Topic: OOPS CONCEPTS (Encapsulation)


Project: OOPS CONCEPTS
Package: com.vyaire
Programs: Student.java, STest.java,Student1.java,S1Test.java,Course.java

Setter methods getter methods


N
-----------------------21-10-2023-Saturday------------------------------------
Topic:Encapsulation
Yesterday last program how to return class object.
Project:OOPS CONCEPTS
Packages:com.cisco, com.m(ma programs)
Programs:
-------student------
1.Student.java
2.Course.java
3.Stest.java
-------Employee---
4.Employee.java
5.Department.java
6.Etest.java

---------------------------25/10/2023-Wednesday----------------------------------------
Topic: one to one and one to many Relations
Project: OOPS CONCEPTS
Package: com.relations AADHAR and mobile
Programs:
-------AADHAR CARD----------
1.Person.java
2.Adhar.java
3.Mobile.java
4.test.java
--------PAN CARD------
5.Panper.java
6.Pancard.java
7.Car.java
8.PTest.java

I learnt about relations


N

------------------------------------------------26/10/2023—Thursday-----------------------
Topic: About Instance variable, Instance Method, Instance block
Static variable, Static Method, Static block
Program Phases: Compilation & Running
Project: OOPS Concepts
Package: com.wipro
Programs:
1.one.java
2.Two.java
Java comes in 2 stages

1)Compliation: Java program will be loaded. Next check program syntactically


correct or not. If correct ready for running the program
2)Running the program:
Object is created here

-------------------------------------------27/10/2023-Friday---------------------------------

Topic: Static and Instance variables, methods, blocks communications s-s,i-I,I-


s,S-i(only with object)
Project:OOPS CONCEPTS
Package:Static and Instance
Programs: 1.Slokam.java
2.Siva.java
3.New.java(HW)

Class{
Ins/sta Var
Ins/sta methods
Ins/sta blocks
}
--------------------------------------------28/10/2023-Saturday-----------------------------

Topic: How to update static and instance variables


Up to now what topics covered
Constructor
(Setters and getters) and constructor comparison
Constructor importance

Projects: OOPS CONCEPTS,Constructor


Packages:StaticandInstance,com.cisco
Programs:Updatevalue.java,student.java,Stest.java,one.java

Sofar covered topics


Datatypes
Flowcontrols

Class
Object
Methods
Instance and static
Access modifiers
Encapsulation
How to initialize object using setter methods
Static
------------------------------up to here completed-------------------------------------------
Constructor
Innheritance
Interface
Abstract
Overloading
Overriding
--------------oops concepts will be completed---------------

Files
Exception handling
Threads
Object class methods
collections

Constructor :N

--------------------------30/10/2023-Monday------------------------------------------------
Topic:Constructor
Project:Constructor
Package:co.vyaire,com.RelationslikeAADHAR and MOBILE, com.Tuesday
Programs:1)emp.java,2)test.java,3)Person.java,4)AADHAR.java,5)Mobile.ja
va,6)PTest.java,7)Student.java,8)STest.java

--------------------------------31/10/2023-Tuesday-----------------------------------------
Topic:Setter and Constructor Initialization
Project: Constructor
Packages:com.Tuesday,com.RelationslikeAADHAR and MOBILE
Programs:1)Person.java, 2)Adhar.java, 3)Mobile.java, 4)PTest.java,
5)Student.java, 6)pancard.java, 7)Address.java, 8)PTest.java
-----------------------------------------01/11/2023-------------------------------------------
Topic:Inheritance, Five types of Inheritance but we use three
Projects:Inheritance
Packages:Singlelevel_Inheritance, Multilevel_Inheritance, Hierarchical
_Inheritance
Programs:schild.java,sparent.java,STest.java

Inheritance: Acquiring the properties from parent class to child class.


There are 5 types of Inheritance
1)Single level

2)Multilevel

3)Hierarchical
4)Multiple
5)Hybrid
------------------------------------------02/11/2023-Thursday------------------------------
Topic: Hierarchical inheritance
Project: Inheritance
Package: Hierarchical Inheritance
Programs:
1)Login.java
2)Clerk.java
3)Manager.java
4)Test.java

Authentication & Authorization is done


By the inheritance we no need of writing common methods in all the classes.
We can extend the classes and put the common method in one class.

Login

Submit(String usern,String pwd)

Customer
Clerk reg() Manager reg() reg()

---------------------------------------03/11/2023-Friday------------------------------
Multi level Inheritance
Project: Inheritance
Child, Parent, grandparent, Test
------------------------------04/11/2023-Saturday-------------------------------------------
Topic: Overloading and Overriding
Project: Overloading,Overriding
Packages: com.CompiletimePolymorphismandStaticPolymorphism,
com.RuntimeorDynamic Polymorphism,com.FinalKeyword
Programs:
1)Login.java,2)Register.java,3)child.java4)parent.java,5)Fchild.java,6)Fparent.jav
a
-------------------------------------06/11/2023-Monday-------------------------------------
Topic:
Project:
Package:
Programs:

Overload
Override
Final
Public

Default lo
Private lo
Protected
Access modifers,static,final can be overloaded
Returntypes
No need to be same

Access Modifiers,Static,Final, returntypes can be overloaded and there is no need


to be same
Overriding
Public, default, protected can be overrided
Private,final,static cannot be overrided

--------------------------------08/11/2023-Wednes day------------------------------------
Topic:Interface, Purpose of Interface, Limitations, Restrictions for variables,
methods and blocks in Interface.
We cannot create the object in interface
Project:INTERFACE
Package: com.testinterface, com.SlokamLoan
Programs:1)Siva.java(Interface)
2)Test.java(Class)
3)Loan.java(Interface)
4)CarLoan.java(Class)
5)HouseLoan.java(Class)
6)LTest.java(Class)
-----------------------09/11/2023-Thurday---------------------------------------------------
Topic: Interface, Multiple Inheritance is achieved by interface, Protected Access
Modifier
Project: Inheritance, Protected_Access_Modifier
Package: Multiple Inheritance,com.protect,com.protectess
Programs:
1) A.java(interface)
2) B.java(interface)
3)C.java(Class)
4)one.java(Class)
5)two.java(Class)
6)Three.java(Class)
---------------------------10/11/2023-Friday----------------------------------------------

Topic:
Project:
Package:
Programs:

-----------------------------------13/11/2023-Monday---------------------------------------
Topic:
Project: File Creation, Deletion, Diff types of file methods usage
Package: com.cisco, com.readdata, com.writedata
Programs:
1) Filecreation.java
2)Filediffmethods.java
3)FindHowmanyFieldsInFolder.java
4)Finding_Files_inside_Directory.java—not completed

5)Wdata.java

6)Rdata.java
7)Rbuffer.java

Sep one
Pack: com. cisco
Slokam.java
Exists
If not
--------------------------------14/11/2023-Tuesday------------------------------------------
Topic: String Class
Project: String Class
Packages: com.pojo, com.read
Programs:
1) one.java
2)two.java
3)Three.java
4)Readdata.java

String class
String literals—String s1=”siva”;

New object creation


string s = new string(“siva”);
if length method not there how to write length char by char
To remove spaces s1.trim
Tolowercase.trim
Touppercase.trim

Split
For file editing
----------------------------15/11/2023—Wednesday----------------------------------------
Topic:
Project: Read data
Package: com.controller, com.pojo
Programs:
1)employee.java
2)FileDao.java
3)Test.java
Commonfile-empdataone

Take pojo package

In that take employee class

Pojo class exists means data should be taken from file and given to pojo class.
The data in pojo class must be given to file.
The data in file must come to pojo class
The data in pojo class must go to file
This is mediator, we must ply the object
Create another packsge
Class== FILEDAO
Public class FileDao{

//I want methods like they must read data from file line by line ,the read data must
be set in to pojo class this is our 1st task
//I need to fetch id
Public employee void getbyId(int eid){
Employee emp=new employee();

Return emp;
}
Public employee[] getByName(String ename){
}//This Array will take multiple employee objects
 But array have some disadvantages

Disadvantages:

Public class test{


Public static void main(String[] args){
Int[] k={33,42,23,23};
//The advantages of int array are k can hold multiple values
//this is one way of initializing an array
Int[] k1=new int[5];
K1[0]=23;
K1[1]=24;
K1[2]=25;
……
//This is one way of intialization
We will set in this way and we will get the data
//We can initializa in two ways,
The best option for us is
We can initialize by giving size fixed like 2 and without fixing size
//But we cannot take double in above
Double[] k ={32.2,22,32,”ram”};
Now my constraint is that I must take int, double,string.now it is possible

//This is one of the disadvantage arrays


It will also not take userdefined classes also
Employee b=new employee();
Test t= new Test();

Employee[] emp={b,t};
Employee array means it will take only employee class objects
Employee array will not take the test class object t.
Int array means it will take only int values
Usedefined classes means it will take only userdefined objects only
The array which type it will take that kind of data only
The above is main disadvantage of the arrays
If I want different kinds of data then how?
Arrays>datatypes
1)contains length method
2)Takes multiple values

Now I want the multiple methods not only length, and I should take different
types of data
From collection topics I am taking ArrayList
ArrayList is a class which implements arrays which in util package
We can add any kind of data
Import java.util.ArrayList;
Import com.pojo.employee;
Public class test{
Public static void main(String[] args){
Employee e1 = new employee(104,”siva”,34,6567.89,”se”);
Employee e2= new employee(105,”ram”,34,6567.89,”se”);

ArrayList a =new ArrayList<>();


a.add(12);
a.add(34.78);
a.add(“siva”);
a.add(true);
a.add(e1);
a.add(e2);
syso(a);

Array we can implement same kind of data. But in array list we can implement
different kind of data. Internally Arraylist also implements array only.

I n Array only length method. But In Array list I have so many methods.
Arraylist is replacement for arrays .Arraylist has so many builtin methods
support.

Get all means we will have multiple objects right. So take Array List
<>-generic (for specification of data)
When you said I want to insert only employee data this generic is neede. If you
did not say that specific data. You can insert anykind of data. Noneed of generic.
ArrayList<employee> k = new ArrayList<>();
ArrayList<String> k = new ArrayList<>();
Here you said we can take only string data
Then I got a doubt that what is difference between simple string array and the
Arraylist
Differences
In arrays only length method is there in Arraylist there are somany methods.

Exception Handling

We are going to discuss about topics

1)Types of Exception
2)What is Exception
3)What is Error
4)Try/Catch
5)Throw/Throws
6)Finally
7)Custom exception.

Example:
Road bike person
When a person want to take a bike he checks whether he has keys or not. Next
we will check for petrol, air in tires.
When Iam about to start even I did not started I got some exceptions. These
exceptions are called checked exceptions or compile time exceptions.
Air ,PETROL,KEYS are complietime exceptions

In our program the compile time exceptions are called Checked Exceptions.
These Checked exceptions must be handled then only program compiles.
Which third party, or connecting with something of others these are checked
exceptions
Example: I tried to connect a file. That file may present or not that is called
checked exception.
Now I need to run the program. I need to start the bike and I need to come from
Starting point to end point these need to be done at the ruuning or run time.
Now everything looks fine but when the program runs/Bike runs accident can
happen, friend can call, Police may stop
Puncture can happen
The above exceptions are runtime exceptions/Unchecked Exceptions.

Exceptions are 2 types:


1)CompileTime/Checked Exceptions(When you forgot some syntax it is called
compile time exception)
2)Runtime/Unchecked Exceptions(Un excepted exceptions)

Example:
Now we will see some run time exceptions below
package com.BasicExceptions;

public class One {

public static void main(String[] args) {


String[] n= {"siva","ram"};
System.out.println(n[0]);
System.out.println(n[1]);
}
In compile time loads class, it checks it is syntactically correct or not.
And also it checks is there any risky code.

In above example when we say n[0] in compile time it will not check it ther e any
data at n[0] or not . It will not even check is there zeroth index or not
also .Because For the Above mentioned string data creates at runtime.In compile
time it will not check n[0],n[1],n[2] is present or not. Which programs runs string
array object creates into that array data wiLG-L be inserted in to 0th index and 1wt
index.
(or)
When program execution starts for n array creates.After creation of array data
inserted in to the 0th and 1st index.
In compiletime it will not check the indexes. This indexes are checked runtime.

Ex:String n= {"siva","ram"};(wrong)

In compiletime it will only check either it is array or not& in this array it will
check have you given syntactically correct data or not

Ex:String[] n= {"siva","ram",097};(wrong)

This array object is created at runtime by JVM


machine

Ex:String[] n= {"siva","ram",097};(wrong)
If another line added to above program
package com.BasicExceptions;

public class One {

public static void main(String[] args) {

String[] n= {"siva","ram"};
System.out.println(n[0]);
System.out.println(n[1]);
System.out.println(n[2]);

OUTPUT:
Siva, ram,ArrayIndexoutofboundexception(Runtime Exception)

ABNORMAL TERMINATION OF PROGRAM:


package com.BasicExceptions;

public class One {

public static void main(String[] args) {

String[] n= {"siva","ram"};
System.out.println(n[2]);
System.out.println(n[1]);
System.out.println(n[0]);

}
When an exception comes at top remaining bottom lines will not excute
OUTPUT:
ArrayIndexoutofboundexception(Runtime Exception)

package com.BasicExceptions;

public class One {

public static void main(String[] args) {

String[] n= {"siva","ram"};
System.out.println(n[0]);
System.out.println(n[1]);
System.out.println(10/0);
System.out.println(n[2]);
System.out.println(n[3]);

}
--------------------------16/11/2023-Thursday-----------------------------------------------

TOPIC: Exception Handling,Exception Hierarchy


Project:
Packages:
Programs:
Throwable class is parent class of Exceptions

2 SUB CLASSES
1)ERROR(sub classes)
2)Exception(sub classes)

https://interviewnoodle.com/exception-in-java-89a0b41e0c45
Errors are unchecked errors occur at runtime
All child class of error class are unchecked errors occur at runtime
It is like hierearchical inheritance
8-15
Lack of memory resources error will come not becoz of our code

M1()
sts
M2();
END

M2()
S
e
g.m1();15-19

STACKS compile&update
When you goes to back to jvm normal termination of stack happens

M2
10/0
Abnormal termination

Try{
10/0
hello}
Catch
Or handle at m1()
M2()
M1(); recursive call
Or handle at main method
47-50

Patrt2 3-7
8-
T class
Err

Exe
Rte
Npe
Two

19-23-definations
Multiple catch purpose

Afternoon
Final can be applicable

Finally{} block

Try{}catch
Try{}catch(c)/catch(p)
Try{}finally{}-----**try exception or not it comes to finally
Try{}catch/finally{}
Try{}catch/catch/finally{}
Irrespective of exception finally

Finalize() method---Object class


--------------------------------17/11/2023-Friday--------------------------------------------
Topic:Throws,Throw
Project:Exception_Handling
Packages:Throws,Throw
Programs:
1)Slokam.java
2)STest.java
3)Atm.java
4)Server.java
5)InSufficientFunds.java

What is Exception?

Error?
Types of Exceptions?
Exception hierarchy
What happened when exception has been raised
5 ex for checked exceptions
5 ex for unchecked exceptions
Try/catch
Finally
Throw
Throws
User defined exceptions
Try with resources
Throw -jvm thrown
Own application own exception classes behave

AFTERNOON
THROW IS USED FOR CRETION OF EXCEPTION OBJECT.
Only classes in exception hierarchy they can be thrown
To be in exeption -----
Vyaire extends runtime exception

ATM PROGRAM

-----------------------------18/11/2023-saturday--------------------------------
Throw-userdefined exceptions define
Arithmetic excep
Nullpointer

----------------------------20/11/2023-Monday---------------------------------------------
Topic:Threads
Project:Threads
Packages:com.displayingThreadName,CreatingThreads

Thread: a thread refers to the smallest unit of execution within a process.


Programs:1)one.java
2)Siva.java
3)Test.java
4)Slokam.java(AN)
https://chat.openai.com/c/17e8ce5a-f816-41aa-84ba-34c049880501
------------------------------21/11/2023-Tuesday--------------------------------------------
Project:Threads
Packages: CreatingThreads_Using_RunnableInterface_Implements
Programs:Slokam.java

Here we can create thread by two ways


1)Runnable Interface
2)Extending class

--------------22/11/2023-WED------------------------------------------------------
Topic: Synchronized
Project: Threads, Synchronized_Keyword
Packages:Multiple_Thread_Displaying_Singletime,New, Movie_Ticket_Booking
Programs:1) Ticketbooking.java

2)User.java
3) Bank.java(1st program)
4)BankCls.java
5)Customer.java
6)BankWD.java
7)Bank.java(Switch)
8)Transactions.java(Switch)
Siva is a child of thread .Thread is a chlid of Runnable.

--------------------------------------23/11/2023-----------------------------------------------
Topic: Synchronization, Thread lifecycle, Object level lock, Class Level lock
Project:Synchronized_Keyword
AFTERNOON
Package:Synchronize, Synchronized_Block
(AFTERNOON)
Programs:
1) Bank.java
2) Slokam.java
3) Bank1.java
4) Slokam1.java
Afternoon
1)one.java

-------------------------------------------24/11/2023-Friday-------------------------------

Topic: Object Class,toString, String Class


Project:Object_Class, String_Class
Packages:Different_Methods_Usage
Programs:
1)Hashcode.java
2)ToString.java
Open Object Class either
3)Employee.java
by extending Thread class
4)Department.java or directly open toString
5)Mobiles.java Class
6)ETest.java
-Background running threads are called deamon threads
Garbage collector can be called by you or by JVM
But the authors of java said that When you called garbage collec

----------------------------------25/11/2023----------------------------------------
Topic: Cloning, Shallow Cloning, Deep Cloning
 Project: Clone_Method_Usage
 Package: Employee_Data_Cloning
 Programs:
1)Employee.java
2)Department.java
3)ETest.java

------------------------27/11/2023—Monday-----------------------------------------
Topic: Shallow Cloning, Deep Cloning, wait() method, Notify() method,
Packages: Employee_Data_Cloning, com.slokam
Programs: 1)EmployeeM.java 2)DepartmentM.java
3)One.java
4)Bank.java
5)Customer.java

Notes:
Actually why
------------------------28/11/2023—Tuesday-----------------------------------------

Topic: Deadlock (is a situation when threads are waiting for eachother).
Project: Deadlock, Deamon_Threads,Yield_Method
Packages:
1) Deadlock_Occurance_between_two_threads, 2) Deamon_Thread_Intro,
3)Default_Package
Programs:
1)Deadlock.java,2)Testdeamon.java, 3) 1TestYield.java
--------------------29/11/2023—Wednesday---------------------------------------
Topic:
Project:
Packages:
Programs:

---------------------4/12/2023-Monday-----------------------------------------------

Collections

Arraylist
Linkedlist
Vector—stack

Set
1)Hashset-Linkedhashset
2)TreeHashset
COLLECTION
COLLECTION

LIST SET QUEUES

1)ARRAYLIST 1) HASH SET

LINKEDHASHSET
2)TREE HASHSET
2)LINKEDLIST

3)VECTOR

STACK

How to import the class arraylist from one project to another project
How to clone method In arrayList

Topic: Collections Introduction, ArrayListMethods


Project: Collections
Package: 1)Basics_And_Checking…..,
Programs:
1)LArrayList.java
2)Employee.java
Afternoon

ARRAYLIST
Arraylist advantages: It is good add and retrieval of data
Disadvantages: It is not good for adding data in middle

Arraylist is based on list


Linkedlist is based on node

LINKEDLIST
Linkedlist advantages: It is good to add data in middle of array
Linkedlist disadvantages: It is not good to add and retrieval of data in terms of
speed

VECTOR
Vector: It is same as arraylist but provides thread safety
In case of Vector For every method synronized is provided.

----------------------------------------5/12/2023-Tuesday-----------------------------------
Topic:ArrayList Methods, LinkedList Methods
Project:Collections
Package: ArrayList, LinkedList, Vector, Stack
Program: 1)Employee.java
2)Test.java
3)Employee.java
4)Test.java
5)Student.java
6)Test.java
7)Student.java
8)Test.java

Arraylist
Multilple employee objects

List contains multiple methods


Add-single index
Addall- separate index
Random access- markerinterface to fast retrieval

Serialization- Marker interface


Fast fetching array list is best
But middle add not correct

LinkedList
Has no random access
k.addFirst();
addlast();

removelastoccurence();
vector new
k.addelement
k.capacity

size and capacity differ


stack is legacy(not used)

push,pop,peek in stack
AFTERNOON

Iterate
3 cursors

1)Iterator(List, set, Queues-All collection implemented classes)


Three methods has next, next, remove
Iterator is a interface
2)ListIterator(List implemented classes)5 to 6
3)Enumeration(All Legacy classes-(eg:stack and vector))

-----------------------------------------06/12/2023-Wednesday-----------------------------
Topic: (Morning)Cursors,Set-(Afternoon)
Morning

Projects: Iteration Cursors, Collection SET


Packages:List_Iterator,HashSet, LinkedHashSet
Programs: 1)LIterator.java, 2)Test.java, 3)Test.java

Afternoon
Projects:
Packages:
Programs:

Hasnext next remove add modify hasPrevious in list iterator


Hasnext next remove in iterator
Hasnext next in enumeration

SET
HASHSET
Set : Not allows duplicate data
Insertion order not preserved
Alloows all kinds of data and NULL
Hasset parent set set parent collection
LINKEDHASHSET
Insertion order preserved

Morning
Projects: Iteration Cursors, Collection SET
Packages:List_Iterator,HashSet, LinkedHashSet
Programs: 1)LIterator.java, 2)Test.java, 3)Test.java

Afternoon
Object class-hashcode,equals, ==

---------------------------------------07/12/2023—Thursday-----------------------------
(Checkonce)
Topic:Linked Hashset ,Tree set
Project: Collections SET
Package:
1)Difference_btw_working_of_hashcode_In_HashSet_And_ObjectClass,
2)TreeSet
Programs: employee1.java, LinkedHashSettest.java, Test.java
1. HashSet: The HashSet class does not rely on the compareTo method.
It uses the hashCode method and the equals method to determine
whether two objects are considered equal. The ordering of elements
in a HashSet is not based on their values, and it does not maintain
any specific order.
2. TreeSet: The TreeSet class, on the other hand, can use the
compareTo method (if elements implement the Comparable interface)
or a specified Comparator to determine the order of elements. If the
elements do not implement Comparable and no Comparator is
provided, the TreeSet will throw a ClassCastException at runtime.

----------------------------------------------08/12/2023-Friday----------------------------

(Noneed of checking -everything is fine)


Topic:
MORNING
Tree Set(Comparator), How to compare data on different properties,
Yesterday we compared only one any one property by comparable interface.
But today we are going to learn how to compare multiple properties using
Comparative
Project: Collections SET
Packages: Tree Set
Programs:
MORNING
1) employee.java
2)BasedonId.java
3)BasedonName.java
4)BasedonSal.java
5)ETest.java
Treeset methods
Headset—lessthan
Tailset—greaterthan
AFTERNOON
Online

------------------------------------------11/12/2023-Monday------------------------------

See from EntrySet


Topic:Tree map, (See Once)How to do using EntrySet using Foreach, How to do
using EntrySet using Iterator, How to do using KeySet using Foreach
Project:Maps, Exception_Handling
Packages:TreeMap, Try_withresources
Programs:
1)Employee.java
2)One.java
3)BasedonId.java
4)Dept.java
5)Slokam.java(Overriding not displayed)

Tree Map

Ascending order=binary search algoriyhm


Key should be not notnull in set or map
TreeMap and HashMap main differensce is Hash map takes null values. Tree
map will not take null values at key position

Afternoon
TryWithresources

----------------------------12/12/2023-Tuesday----------------------------------------
Topic:Threads
Project:Threads,Join_Method,Threads
Packages:RunnableInterface, Join,Callable_Interface
Programs:
Runnable Interface
1)Slokam.java
2)Employee.java
Join
1)Siva.java
2)Slokam.java(just practice again same as above)
Callable_Interface
1)testcall.java(Compulsory check it in rec)

--------------------13/12/2023-Wednesday--------------------------------------------------
Topic:Object Class methods(10)
toString,
Clone,
Wait,Notify,notiftall,
Project: Clone_Method_Usage
Packages:clone_13_12_2023
Programs:
Morning

Shallow Cloning and Deep Cloning


1)Employee.java
2)Dept.java
3)Test.java
AFTERNOON

Hashtable:
It doesnot take any null values
Values can be duplicate but no null values
Only tree set and tree map I can apply Comparable
Project: Maps
Package: HashTable
Programs:
1)Employee.java
2)Three.java
Project: Maps
Package: HashTable
Programs:
1)Employee.java
2)Three.java

-------------------------------14/12/2023—Thursday----------------------------------------

Object Class Methods:(GETHWNNFC)


Get Class,
equals,
== equals,
to String,
Hash code,
Wait,
Notify,
Notify All,
Finalize,
Clone()

OBJECT CLASS METHODS CODE:(GETNHWNNFC)

GETCLASS- CURRENT CLASS OBJECT ADDRESS


EQUALS,
DOUBLEEQUALS,
TOSTRING- CURRECT CLASS+HEXADECIMALVALUE OF HASHCODE
HASHCODE- GIVES ADDRESS OF CURRENT CLASSS
WAIT,
NOTIFY,
NOTIFYALL,
FINALIZE- GARBAGE COLLECTOR CALLS FINALIZE METHOD TO
REMOVE UNREFERENCED OBJECTS.
CLONE- CREATE DUPLICATE OBJECT IN CURRENT CLASS
-------------------------15/12/2023-Friday---------------------------------------------------
----------------------------16/12/2023-SATURDAY----------------------------------------
WEAK HASHMAP
Concurrent hashmap- Segment level lock
-----------------------------------23/12/2023-Saturday--------------------------------------
--------------------------25/12/2023-Monday-----------------------------------------------
Topic:Collections(Maps) Notes written
----------------26/12/2023-Tuesday----------------------------------------------------------
Topic:
Project:
Packages:
Programs
Arrays -single and multidimensional
File to database
Pojo class Employee
DaoFileReader class

-------------------------------------------------30/12/2023-----------------------------------
JDBC
What is class----class.forname
How to connect database
What are the interface in jdbc
Drivermanager class
What is STATEMENT
What is PREPARED STATEMENT
What is CALLABLE STATEMENT

Difference between st and prest

Batch update
Transactions
How to create basic procedure
How to call procedure
We have completed--------below topics
Curd operations
Joins – Relations—subqueries
Aggregate
Select count(*) from employee;
Select max(esal), min(esal), avgfrom
Having, we can apply only we can haveOrderby
Group by
Having

---------------------------22-01-2024----------------Monday----------------------------
Topic: String literals and String class
String constant pool and Heap Memory
Project: String literals and String Class
Package:
StringLiteralsAndStringClassIntroduction
Programs:
1)STest.java
Afternoon no class
-----------------------23-01-2024--------Tuesday--------------------------
Topic: How to create our own immutable class (INTERVIEW QUESTION)
Project: String literals and String Class
Package: How_to_create_custom_immutable_class
Programs: Employee.java
Etest.java
Department.java
Afternoon Hib relations class oto,otm,mtm
-----------27-03-2024-----------Wednesday-----------------------------------
TOPIC: SERIALIZATION AND DESERIALIZATION
PROJECT: Serialization AND Deserialization
PACKAGE: com.cisco
PROGRAMS:
1) empPojo.java
2) One.java
3) TestSerialization.java
4) TestDeserialization.java

1) empPojo.java
package com.cisco;

import java.io.Serializable;

public class empPojo implements Serializable {

private int eid;


private String ename;
private Double esal;
private String edesg;
public empPojo(int eid, String ename, Double esal,
String edesg) {
super();
this.eid = eid;
this.ename = ename;
this.esal = esal;
this.edesg = edesg;
}

public empPojo() {

@Override
public String toString() {
return "empPojo [eid=" + eid + ", ename=" +
ename + ", esal=" + esal + ", edesg=" + edesg + "]";
}

public int getEid() {


return eid;
}

public void setEid(int eid) {


this.eid = eid;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public Double getEsal() {
return esal;
}
public void setEsal(Double esal) {
this.esal = esal;
}
public String getEdesg() {
return edesg;
}
public void setEdesg(String edesg) {
this.edesg = edesg;
}

2) One.java
package com.cisco;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class One {

public static void main1(String[] args) {

try {
FileWriter fw = new FileWriter("E:\\html\\
Slokam\\sdes.txt",true);
BufferedWriter bw = new
BufferedWriter(fw);
bw.write("3,lucky,99.5,se");
bw.newLine();
bw.close();
fw.close();

} catch (Exception e) {

e.printStackTrace();
}

public static void main2(String[] args) {

try {
FileReader fr = new FileReader("E:\\html\\
Slokam\\sdes.txt");
BufferedReader br = new
BufferedReader(fr);

for(String s = br.readLine();s!
=null;s=br.readLine()) {
System.out.println(s);
}
br.close();
fr.close();

} catch (Exception e) {

e.printStackTrace();
}

public static void main(String[] args) {

try {
FileWriter fw = new FileWriter("E:\\html\\
Slokam\\sdes.txt",true);
BufferedWriter bw = new
BufferedWriter(fw);
empPojo k = new
empPojo(4,"aaa",95.5,"dev");
bw.write(k.getEid()+","+k.getEname()
+","+k.getEsal()+","+k.getEdesg());
//bw.write("3,lucky,99.5,se");
bw.newLine();
System.out.println("inserted");
bw.close();
fw.close();

} catch (Exception e) {

e.printStackTrace();
}

3) TestSerialization.java
package com.cisco;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class TestSerialization {

public static void SENDDATATOFILE(empPojo emp) {


try {
FileOutputStream fo = new
FileOutputStream("E:\\Slokam Files\\se.txt",true);
ObjectOutputStream oo = new
ObjectOutputStream(fo);
oo.writeObject(emp);
System.out.println("Data Inserted");
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {

empPojo e = new
empPojo(100,"loki",75.5,"dev");
SENDDATATOFILE(e);
}

Output:-

4)TestDeserialization.java
package com.cisco;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class TestDeserialization {

public static void retrieve() {


try {
FileInputStream fi = new
FileInputStream("E:\\Slokam Files\\se.txt");
ObjectInputStream oi = new
ObjectInputStream(fi);
empPojo k= (empPojo) oi.readObject();
System.out.println("Employee data from
file---"+"\n"+k);
} catch (Exception e) {

e.printStackTrace();
}
}

public static void main(String[] args) {


retrieve();

Output:-

USAGE OF TRANSIENT KEYWORD:

1) empPojo.java
package com.cisco;

import java.io.Serializable;

public class empPojo implements Serializable {


private int eid;
private String ename;
private Double esal;
private transient String edesg;
public empPojo(int eid, String ename, Double esal,
String edesg) {
super();
this.eid = eid;
this.ename = ename;
this.esal = esal;
this.edesg = edesg;
}

public empPojo() {

@Override
public String toString() {
return "empPojo [eid=" + eid + ", ename=" +
ename + ", esal=" + esal + ", edesg=" + edesg + "]";
}

public int getEid() {


return eid;
}

public void setEid(int eid) {


this.eid = eid;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public Double getEsal() {
return esal;
}
public void setEsal(Double esal) {
this.esal = esal;
}
public String getEdesg() {
return edesg;
}
public void setEdesg(String edesg) {
this.edesg = edesg;
}

2) TestSerialization.java

package com.cisco;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class TestSerialization {

public static void SENDDATATOFILE(empPojo emp) {


try {
FileOutputStream fo = new FileOutputStream("E:\\
Slokam Files\\se.txt");
ObjectOutputStream oo = new ObjectOutputStream(fo);
oo.writeObject(emp);
System.out.println("Data Inserted");
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {

empPojo e = new empPojo(300,"bbb",75.5,"dev");


SENDDATATOFILE(e);

}
3) TestDeserialization.java

package com.cisco;
import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class TestDeserialization {

public static void retrieve() {


try {
FileInputStream fi = new FileInputStream("E:\\Slokam Files\\
se.txt");
ObjectInputStream oi = new ObjectInputStream(fi);
empPojo k= (empPojo) oi.readObject();
System.out.println("Employee data from file---"+"\n"+k);
} catch (Exception e) {

e.printStackTrace();
}
}

public static void main(String[] args) {


retrieve();
}

AFTER USAGE OF Department in the empPojo class

1) empPojo.java
package com.cisco;

import java.io.Serializable;

public class empPojo implements Serializable {

public static final long serialversionID = 1L;


private int eid;
private String ename;
private Double esal;
private String edesg;
private Department dep;

public empPojo() {

@Override
public String toString() {
return "empPojo [eid=" + eid + ", ename=" +
ename + ", esal=" + esal + ", edesg=" + edesg + ",
dep=" + dep
+ "]";
}

public empPojo(int eid, String ename, Double esal,


String edesg, Department dep) {
super();
this.eid = eid;
this.ename = ename;
this.esal = esal;
this.edesg = edesg;
this.dep = dep;
}

public Department getDep() {


return dep;
}

public void setDep(Department dep) {


this.dep = dep;
}

public int getEid() {


return eid;
}
public void setEid(int eid) {
this.eid = eid;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public Double getEsal() {
return esal;
}
public void setEsal(Double esal) {
this.esal = esal;
}
public String getEdesg() {
return edesg;
}
public void setEdesg(String edesg) {
this.edesg = edesg;
}

2) Department.java
package com.cisco;

public class Department implements Serializable {

private int did;


private String dname;
private String dloc;
@Override
public String toString() {
return "Department [did=" + did + ", dname=" +
dname + ", dloc=" + dloc + "]";
}
public Department() {
super();
}
public Department(int did, String dname, String
dloc) {
super();
this.did = did;
this.dname = dname;
this.dloc = dloc;
}
public int getDid() {
return did;
}
public void setDid(int did) {
this.did = did;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
public String getDloc() {
return dloc;
}
public void setDloc(String dloc) {
this.dloc = dloc;
}

IF YOU DID NOT KEEP THE IMPLEMENTS SERIALIZABLE

3) TestSerialization.java
package com.cisco;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class TestSerialization {

public static void SENDDATATOFILE(empPojo emp) {


try {
FileOutputStream fo = new FileOutputStream("E:\\Slokam
Files\\se.txt",true);
ObjectOutputStream oo = new ObjectOutputStream(fo);
oo.writeObject(emp);
System.out.println("Data Inserted");
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {

Department d = new Department(1,"CSE","hyd");

empPojo e = new empPojo(400,"ccc",75.5,"dev",d);


SENDDATATOFILE(e);

}
4) TestDeserialization.java

package com.cisco;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class TestDeserialization {

public static void retrieve() {


try {
FileInputStream fi = new FileInputStream("E:\\Slokam
Files\\se.txt");
ObjectInputStream oi = new ObjectInputStream(fi);
empPojo k= (empPojo) oi.readObject();
System.out.println("Employee data from file---"+"\
n"+k);
} catch (Exception e) {

e.printStackTrace();
}
}

public static void main(String[] args) {


retrieve();

}
IS -A RELATION: IF YOU KEEP IMPLEMENTS SERIALIZABLE TO
empPojo

1) empPojo.java
package com.cisco;

import java.io.Serializable;

public class empPojo extends Department{

//public static final long serialversionID = 1L;


private int eid;
private String ename;
private Double esal;
private String edesg;
private Department dep;

public empPojo() {

@Override
public String toString() {
return "empPojo [eid=" + eid + ", ename=" +
ename + ", esal=" + esal + ", edesg=" + edesg + ",
dep=" + dep
+ "]";
}

public empPojo(int eid, String ename, Double esal,


String edesg, Department dep) {
super();
this.eid = eid;
this.ename = ename;
this.esal = esal;
this.edesg = edesg;
this.dep = dep;
}

public Department getDep() {


return dep;
}

public void setDep(Department dep) {


this.dep = dep;
}

public int getEid() {


return eid;
}

public void setEid(int eid) {


this.eid = eid;
}
public String getEname() {
return ename;
}
public void setEname(String ename) {
this.ename = ename;
}
public Double getEsal() {
return esal;
}
public void setEsal(Double esal) {
this.esal = esal;
}
public String getEdesg() {
return edesg;
}
public void setEdesg(String edesg) {
this.edesg = edesg;
}

2) Department.java
package com.cisco;

import java.io.Serializable;

public class Department implements Serializable {

private int did;


private String dname;
private String dloc;
@Override
public String toString() {
return "Department [did=" + did + ", dname=" +
dname + ", dloc=" + dloc + "]";
}
public Department() {
super();
}
public Department(int did, String dname, String
dloc) {
super();
this.did = did;
this.dname = dname;
this.dloc = dloc;
}
public int getDid() {
return did;
}
public void setDid(int did) {
this.did = did;
}
public String getDname() {
return dname;
}
public void setDname(String dname) {
this.dname = dname;
}
public String getDloc() {
return dloc;
}
public void setDloc(String dloc) {
this.dloc = dloc;
}

3) TestSerialization.java

package com.cisco;
import java.io.FileOutputStream;
import java.io.ObjectOutputStream;

public class TestSerialization {

public static void SENDDATATOFILE(empPojo emp) {


try {
FileOutputStream fo = new FileOutputStream("E:\\
Slokam Files\\se.txt");
ObjectOutputStream oo = new ObjectOutputStream(fo);
oo.writeObject(emp);
System.out.println("Data Inserted");
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {

Department d = new Department(1,"CSE","hyd");

empPojo e = new empPojo(400,"bbb",75.5,"dev",d);


SENDDATATOFILE(e);

}
4) TestDeserialization.java

package com.cisco;

import java.io.FileInputStream;
import java.io.ObjectInputStream;

public class TestDeserialization {

public static void retrieve() {


try {
FileInputStream fi = new FileInputStream("E:\\Slokam Files\\se.txt");
ObjectInputStream oi = new ObjectInputStream(fi);
empPojo k= (empPojo) oi.readObject();
System.out.println("Employee data from file---"+"\n"+k);
} catch (Exception e) {

e.printStackTrace();
}
}

public static void main(String[] args) {


retrieve();

AFTERNOON:
What is serialization
How to implement serialization
Serializable ID
Deserialization
Has – A Relation
Employee implements serialization extends dep – Not possible

Dept //IS A relation


Dep implements serialization Empl extends dep – Possible

TOPIC-2: INNER CLASSES


1) MEMBER INNER CLASS: A non static nested class that is defined
member level of another class. It has access to all members of the outer
class, including private members

A)Car.java

Public, default, final Car{


Public,default, private, protected(allows access) int cid=1;
Void m1(){
Syso(“Outer class method”);
}

Public, default, private, protected,final Class InnerClass


{

Public void display(){


Syso(cid);

}
}

Psvm(){
Car c = new car();
c.display();
}

b) Test.java
class Test{
psvm(s[]a){
Car c = new Car();//Outer class object[cid]
Inner class k =c.new InnerClass();
k.display();
}
}

2) Static Nested Class

Its is a static. It acceses only static members


1) Car.java
package Static_inner_class;

public class Car {

static int cid=100;


static void m1() {
System.out.println("Outer class method --
Static Inner class");
}

static class Innerclass{


static void display() {
System.out.println("Inner class -- Static
Inner class");
System.out.println(cid);
m1();
}
}

2) Test.java
package Static_inner_class;

import Static_inner_class.Car.Innerclass;

public class Test {

public static void main(String[] args) {


System.out.println(Car.cid);
Car.Innerclass.display();
}

3) Local Inner class

Local class—default, final


ADVANTAGES OF INNER CLASSES:
1) ENCAPSULATION: inner classes can access the private
2) Easy readability and maintainability
3) Anomolous inner class

You might also like