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

Java Intro - Merged

The document discusses different topics related to learning full stack Java development. It covers Core Java, advanced Java, frameworks, databases, and front-end technologies. It also explains the difference between languages, technologies, and frameworks.

Uploaded by

Sai Teja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

Java Intro - Merged

The document discusses different topics related to learning full stack Java development. It covers Core Java, advanced Java, frameworks, databases, and front-end technologies. It also explains the difference between languages, technologies, and frameworks.

Uploaded by

Sai Teja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 157

dt : 26/10/2022(Day-1)

Batch : Full Stack Java

1.CoreJava (langauge)

2.AdvJava (Technology)

3.Spring(Spring Core,Spring MVC,Spring JDBC,Spring Boot)

i
thi
4.Web Services(Frameworks)

ipa
5.Oracle

6.HTML/CSS/JS

7.Anguler
Ma
sh
8.Testing Basics - Selenium

9.DevSecOps
ate

Duration : 5 to 6 months
nk

Advantages:
Ve

Role : Full Stack Java Developer

NASSCOM

Project

=============================================================

CoreJava : 60 Working Sessions


============================================================

Placements

===========================================================

Parallel Batches:

CoreJava - 11 Am

Oracle -

i
thi
HTML/CSS/JS -

======================================================

ipa
process of learning Language:

step-1 : Alphabets

step-2 : Grammer
Ma
step-3 : Construction rules
sh

Note:
ate

=>Every Language will have its own Alphabets,Grammer and

Construction rules.
nk

----------------------------------------------------------------

Java language:
Ve

part-1 : CoreJava(LKG)

part-2 : AdvJava(UKG)

part-1 : CoreJava:

=>CoreJava includes the following:


1.Java Programming Components(Java Alphabets)

2.Java Programming Concepts

3.Object Oriented Programming features

1.Java Programming Components(Java Alphabets)

(a)Variables

i
thi
(b)Methods

(c)Blocks

ipa
(d)Constructors

(e)Classes

(f)Interfaces

(g)AbstractClasses
Ma
sh
2.Java Programming Concepts:

(a)Object Oriented Programming


ate

(b)Exception Handling process

(c)Multi-Threading process
nk

(d)Java Collection Framwork(JCF)

(data Structures in Java)


Ve

(e)Files in Java(IO Streams and Files)

(f)Networking in Java

3.Object Oriented Programming features:

(a)Class
(b)Object

(c)Abstraction

(d)Encapsulation

(e)PolyMorphism

(f)Inheritance

---------------------------------------------------------------

i
thi
Dt : 27/10/2022(Day-2)

Note:

ipa
=>Using CoreJava Components and Concepts we can develop "Stand Alone

Applications".
Ma
-------------------------------------------------------------

faq:

define "Stand Alone Applications"?


sh
=>The applications which are installed in one computer and performs

actions in the same computer are known as "Stand Alone Applications"


ate

or Windows Applications or DeskTop applications


nk

Note:

=>According to Java Developer "Stand Alone Application" means.


Ve

No HTML input

No Server Environment

No Database Connection

============================================================

part-2 : AdvJava
=>AdvJava provide the following technologies to construct Web

applications

1.JDBC

2.Servlet

3.JSP

i
thi
Diagram:

ipa
1.JDBC:

=>JDBC stands for "Java DataBase Connectivity" and which is used to


Ma
establish communication b/w JavaProgram and Database product.

2.Servlet:
sh
=>Servlet means "Server program" and which is used to accept the request

from users/Clients through WebBrowser.


ate

3.JSP:
nk

=>JSP stands for "Java Server Page" and which is response from Web

Application
Ve

faq:

define Web Application?

=>The application which is executed in Web environment or Internet

environment is known as Web Applications.


i
thi
ipa
===================================================================

Dt : 28/10/2022(Day-3)
Ma
Conclusion:

CoreJava : Stand Alone Application development


sh
AdvJava : Web Application Development
ate

==============================================================

faq:

wt is the diff b/w


nk

(i)Language
Ve

(ii)Technology

(iii)Framework

(i)Language:

=>Language will provide componts,concepts,features and Construction

rules.
Ex:

CoreJava

(ii)Technology:

=>The process of transforming the knowledge into realtime world

application development is known as Technology

i
thi
Ex:

AdvJava

ipa
(iii)Framework:
Ma
=>The Structure which is ready constructed and available for

aplication development is known as Framework.

Ex:
sh
Spring

WebServices
ate

=============================================================
nk
Ve
Dt : 1/11/2022

*imp

define Program?(Syllabus)

=>Program is a set-of-Instructions.

define Programming?

i
thi
=>The process of constructing programs is known as Programming.

ipa
SDLC(Software Development Life Cycle)

1.Analysis

2.Design

3.Coding(Construction)
Ma
4.Testing
sh
5.Deployment
ate

Note:

=>The process of converting "Analysis and Design" in to Code-Form


nk

is known as Coding or Constructing or Programming

============================================================
Ve

Note:

=>After writing the programs,we save the programs with language

extention

Test.c

Test.cpp
Test.java

=>After Saving the program,the program will have the following two

stages:

1.Compilation

2.Execution

1.Compilation:

i
thi
=>The process of checking the program constructed according to the rules

of language or not,is known as Compilation process.

ipa
=>After Compilation process is successfull,

=>c and c++ languages generate Objective code and Java lang generate

Byte Code.

2.Execution:
Ma
=>The process of running Compiled codes and checking the required output
sh
is generated or not,is known as Execution process.

=>In C and c++ languages the Objective Code is converted into executable
ate

code and generate result.

=>In Java Language the Byte code is executed on JVM(Java Virtual Machine)
nk

Diagram:
Ve
i
thi
ipa
===============================================================

faq:

wt is the diff b/w

(i)Objective Code
Ma
(ii)Byte Code
sh

(i)Objective Code:
ate

=>The Compiled code generated from c and c++ programs is known as

Objective code.
nk

=>while Objective Code generation Operating System is participated and

Objective Code is Platform dependent code.


Ve

Dis-Advantage:

=>The Objective Code which is generated from one PlatForm cannot be

executed on other PlatForms.


Note:

=>c and c++ languages which are generating Objective Code are Platform

dependent languages.

(ii)Byte Code:

=>The Compiled code generated from Java programs is known as Byte Code.

i
thi
=>while Byte code generation Operating System is not participated and

ByteCode is PlatForm independent code.

ipa
Advantage:
Ma
=>The ByteCode generated from one PlatForm can be executed on other

PlatForms based on JVM.


sh
Note:

=>The JavaLang which is generating ByteCode is PlatForm independent


ate

language
nk

Diagram:
Ve
i
thi
ipa
Ma
==============================================================
sh
ate
nk
Ve
Dt : 2/11/2022

faq:

define High Level Languages?

=>The language formats which are understandable by the user are known as

"High level Languages".

Ex:

ii
C,C++,Java

ath
faq:

aip
define Low Level Languages?

=>The language formats which are understandable by the Machine and which
hM
are not understandable by the User are known as "Low Level Languages"

Ex:

Machine Languages
tes

faq:
a

define Translators?
nk

=>Translators are used to translate High Level language formats into

Low Level Language formats and Low Level Language formats into High
Ve

Level Formats.

=>These Translators are categorized into two types:

(i)Compilers - means translate total the program at-a-time

(ii)Interpreters - means translate the program line-by-line


ii
ath
aip
hM
====================================================================
tes

Dt : 3/11/2022

Author : James Gosling


a

Joined Sun micro systems in 1991


nk

WORA - Write Once and Run Anywhere

Test.gt (Green Talk Lang)


Ve

OAK language

"DNA" "SILK" ...

"Java"..

1995

1996 - Top 10 Products Java available


*imp

Java Versions:

1995 - Java Alpha&Beta

1996 - JDK 1.0

1997 - JDK 1.1

ii
1998 - JDK 1.2

ath
2000 - JDK 1.3

2002 - JDK 1.4

aip
--------------------------------------

2004 - Java5(Tiger Java)


hM
2006 - Java6

2011 - Java7

----------------------------------------
tes

2014 - Java8

2017 - Java9
a

2018 - Java10,Java11
nk

2019 - Java12,Java13

2020 - Java14,Java15
Ve

2021 - Java16,Java17

2022 - Java18,Java19

=========================================================

=>The following are LTS(Long Term Support) products:

Java8
Java11

Java17

=======================================================

faq:

wt is the diff b/w

(a)JDK

ii
(b)JRE

ath
(C)JVM

aip
(a)JDK:

=>JDK stands for "Java Development Kit" and which is collection of the
hM
following Components:

(i)Java Compiler

(ii)JVM
tes

(iii)Java Library
a

(i)Java Compiler:
nk

=>Java Compiler will compile SourceCode and,if compilation is

Successfull then SourceCode is converted into ByteCode.


Ve

(ii)JVM:

=>JVM Stands for "Java Virtual Machine" and which is used to execute

Java ByteCode.

=>The JVM internally divided into the following partitions:


1.Class Loader SubSystem

2.Runtime data Area

3.Execution Engine

=>The s/w component which internally having the behaviour like

machine is known as Virtual Machine.

ii
(iii)Java Library:

ath
=>Java Library will provide pre-defined ready constructed components

which are used in constructing applications.

aip
=>we use "java" word to represent JavaLibrary.

=>JavaLibrary is collection of "packages".


hM
=>packages are collection of "Classes and Interfaces".

=>These Classes and Interfaces are collection of

"Variables and Methods"


tes

Diagram:
a
nk
Ve
ii
ath
aip
hM
---------------------------------------------------------

(b)JRE:
tes

=>JRE stands for "Java Runtime Environment" and which is collection

of "Java Library and JVM".

=>JRE is an internal partition of JDK.


a
nk

(C)JVM:
Ve

=>JVM is an internal partition of JRE.


ii
ath
aip
hM
================================================================

*imp
tes

Installing Java S/w and setting path:


a

step-1 : Download JDK from Oracle Website


nk

Link => https://www.oracle.com/in/java/technologies/downloads/


Ve

step-2 : Install JDK

Note:

=>After installation process is Successfull,we can find one folder

with name "java" in ProgramFiles.


C:\Program Files\Java

step-3 : Set JavaPath in "Environment Variables"

RightClick on MyComputer->Properties->Advanced System Settings->

Environment Variables->Click "new" from System Variables

ii
ath
Variables name : path

aip
Variable Value : C:\Program Files\Java\jdk-17.0.4.1\bin;
hM
step-4 : Click "ok" for three times,then path is setted

================================================================
a tes
nk
Ve
Dt : 4/11/2022

*imp

Writing,Saving,Compiling and Executing Java program:

define "class"?

=>class is a "Structured Layout" and which generate "Objects".

i
thi
=>class is a collection of Variables,Methods and main()

Variables - are data holders

ipa
Methods - are the actions

main() - is starting point of program execution


Ma
=>main() in java having the following standard format:

public static void main(String args[])

=>we use "class" keyword to construct classes in Java:


sh

structure of class in Java:


ate

class Class_name
nk

Variables
Ve

Methods

main()

Note:
=>In realtime the class names in Java must start with UpperCase letter

or Capital letter.

---------------------------------------------------------------

Ex-program:

wap to display the msg as "Welcome to Java"?

i
thi
class Display

ipa
public static void main(String args[])

}
System.out.print("Welcome to Java");
Ma
}
sh

============================================================
ate

step-1 : Create folder in any drive to save the programs

D:\Demo141
nk

step-2 : Open notepad and type the program


Ve

step-3 : Save the program in folder as

syntax:

Class_name.java

Ex:
Display.java

click on File->Save->Browse the folder and name the file->

Save as Type must be "All Files"->click "Save".

Note:

i
thi
=>Open CommandPrompt and perform "Compilation and Execution process"

=>To open CommandPrompt,goto folder->type "cmd" in address bar and

ipa
press enter.

step-4 : Compile the program as follows

syntax:
Ma
javac Class_name.java
sh
Ex:

javac Display.java
ate

step-5 : Execute the program as follows


nk

syntax:

java Class_name
Ve

Ex:

java Display

================================================================

Commands:

javac - Compilation Command


java - Execution Command

==============================================================

i
thi
ipa
Ma
sh
ate
nk
Ve
Dt : 5/11/2022

EX-program:

wap to display the sum of two numbers?

class Addition

i
thi
public static void main(String args[])

ipa
int a=10,b=20,c;

c = a+b;

System.out.println("a value="+a);

System.out.println("b value="+b);
Ma
System.out.println("The sum="+c);
sh
}

}
ate

o/p:
nk

a value=10

b value=20
Ve

The sum=30

D:\Demo141>

========================================================

Note:

=>"+" symbol in print() method specify to combine msg with result.


===========================================================

faq:

wt is the diff b/w

(i)print()

(ii)println()

i
thi
(i)print():

=>print() method is used to display in the same line.

ipa
(ii)println():
Ma
=>println() method is used to display in different lines.

=============================================================

Assignment1:
sh
wap to display 6 sub marks,totMarks and percentage?
ate

int s1,s2,s3,s4,s5,s6,totMarks;

float per;
nk

============================================================

Assignment2:
Ve

wap to display employee basicSalary,hra,da and totSalary

int basicSalary;

float hra,da,totalSalary;
totSalary = basicSalary+hra+da;

hra = 93% of basicSalary;

da = 63% of basicSalary;

========================================================

i
thi
ipa
Ma
sh
ate
nk
Ve
Dt : 7/11/2022

Note:

=>Java s/w is PlatForm dependent while downloading and installing.

=>After installation process is Successfull,the java s/w is Platform

independent while compilation and execution process.

==================================================================

ii
*imp

ath
Naming Conventions in Java:

=>The coding rules used by the programmer in writing Java programs

aip
are known as Naming Conventions in Java.
hM
packages:

def : packages are collection of Classes and Interfaces

rule : The packages must be in Lowercase.


tes

Classes and Interfaces :


a

def : Classes and Interfaces are collection of Variables and methods.


nk

rule : In Classes and Interfaces the starting letter of every word

must be UpperCase.
Ve

Ex:

Employee

StudentResult

InputStreamReader
Variables and Methods :

def : Variables are data holders and Methods are actions

rule : In Variables and Methods the first word in LowerCase and from

Second word onwards the Starting letter must be capital.

Ex : Methods

readLine()

ii
getSalary()

ath
Ex : Variables

aip
rollNumber

panCardNumber
hM
Keywords :

def : The pre-defined words or Built-in Words are known as Keywords


tes

rule : The keywords must be in LowerCase.

Ex:
a

static
nk

void

class
Ve

===================================================================

faq:

define Identifiers?

=>The names which are assigned for programing components for

identification are known as Identifiers.


==============================================================

*imp

DataTypes in Java:

=>The types of data which we are expecting as input to Java Programs

are known as "Datatypes in Java"

=>Datatypes in Java are categorized into two types:

ii
1.Primitive Datatypes

ath
2.NonPrimitive Datatypes

aip
1.Primitive Datatypes:

=>The "Single Valued data formats" are known as Primitive Datatypes.


hM
=>These Primitive datatypes are categorized into four types:

(a)Integer datatypes

(b)Float datatypes
tes

(c)Character datatype

(d)Boolean datatype
a
nk

(a)Integer datatypes:

=>The numeric data without decimal point representation are known as


Ve

Integer datatypes.

=>Types:

byte - 1 byte(8bits)

short - 2 bytes

int - 4 bytes
long - 8 bytes

Note:

=>"byte" and "short" are special datatypes used hold Stream data.

(Multimedia data)

=>"int" datatype is used in normal programming

=>"long" datatype is used to hold large numeric values.

ii
=>In the process of assigning long value we must use "L" or "l" in the

ath
RHS of declaration.

Ex:

aip
long l = 9898981234L;
hM
(b)Float datatypes:

=>The numeric data with decimal point representation are known as

Float datatypes.
tes

=>Types:

float - 4 bytes
a

double - 8 bytes
nk

Note:

=>"float" datatype is used in normal programming.


Ve

=>"double" datatype is used to hold largest scientific calculated

values.

=>In the process of assigning float value we must use "F" or "f" in the

RHS of declaration.
Ex-program : DataTypes.java

class DataTypes

public static void main(String[] args)

byte b = 127;

ii
short s = 32767;

ath
int i = 34562345;

long l = 9898981234L;

aip
float f = 12.34F;

double d = 1234.56;
hM
System.out.println("byte value="+b);

System.out.println("short value="+s);

System.out.println("int value="+i);
tes

System.out.println("long value="+l);

System.out.println("float value="+f);
a

System.out.println("double value="+d);
nk

}
Ve

o/p:

byte value=127

short value=32767

int value=34562345

long value=9898981234
float value=12.34

double value=1234.56

=============================================================

ii
ath
aip
hM
a tes
nk
Ve
Dt : 8/11/2022

(c)Character datatype:

=>The "Single valued character" which is represented in single

quotes is known as Character datatype.

Ex:

'k','j','n',...

ii
=>Types:

ath
char - 2 bytes

aip
faq:

why Java-lang use 2 bytes for a Character?


hM
=>Java-lang use "UNICODE"(Universal Code) representation,which means

ready to accept all types of language codes available in the world.


tes

Example of Language codes:


a

(i)ASCII (American Standard Code for Information Interchange)


nk

for the United States.

(ii)ISO 8859-1 for Western European Language.


Ve

(iii)KOI-8 for Russian.

(iv)GB18030 and BIG-5 for chinese.


ii
ath
(d)Boolean datatype:

aip
=>The datatype which is represented in the form of true or false

is known as Boolean datatype.


hM
=>Types:

boolean - 1 bit
tes

program : DataTypes2.java

class DataTypes2
a

{
nk

public static void main(String[] args)

{
Ve

char ch = 'A';

int code = (int)ch;//TypeCasting

boolean b = true;

System.out.println("char value="+ch);

System.out.println("ASCII Code of A="+code);


System.out.println("boolean value="+b);

o/p:

char value=A

ASCII Code of A=65

ii
boolean value=true

ath
=====================================================

faq:

aip
define TypeCasting process?

=>The process of converting one datatype into another datatype is


hM
known as TypeCasting process.

=>TypeCasting process is categorized into two types:

(a)Widening process
tes

(b)Narrowing process
a
nk

(a)Widening process:

=>The process of converting lower datatype value into higher datatype


Ve

value is known as Widening process.

=>This Widening process is also known as UpCasting process.

char->byte->short->int->long->float->double
(b)Narrowing process:

=>The process of converting higher datatype value into lower datatype

value is known as Narrowing process.

=>This Narrowing process is also known as downcasting process.

double->float->long->int->short->byte->char

ii
====================================================================

ath
Assignment1:(Solution)

wap to display 6 sub marks,totMarks and percentage?

Program : StudentResult.java

aip
hM
class StudentResult

public static void main(String[] args)


tes

int s1=90,s2=78,s3=77,s4=63,s5=93,s6=99;
a

int totMarks = s1+s2+s3+s4+s5+s6;


nk

float per = (float)totMarks/6;//TypeCasting

System.out.println("Sub-1="+s1);
Ve

System.out.println("Sub-2="+s2);

System.out.println("Sub-3="+s3);

System.out.println("Sub-4="+s4);

System.out.println("Sub-5="+s5);

System.out.println("Sub-6="+s6);
System.out.println("TotMarks=="+totMarks);

System.out.println("Percentage="+per);

o/p:

Sub-1=90

ii
Sub-2=78

ath
Sub-3=77

Sub-4=63

aip
Sub-5=93

Sub-6=99
hM
TotMarks==500

Percentage=83.333336

===========================================================
tes

Assignment2:(Solution)

wap to display employee basicSalary,hra,da and totSalary


a
nk

program : EmployeeSalary.java

class EmployeeSalary
Ve

public static void main(String[] args)

int bSal = 17453;

float hra = 0.93F*bSal;


float da = 0.63F*bSal;

float totSal = bSal+hra+da;

System.out.println("BSal="+bSal);

System.out.println("HRA="+hra);

System.out.println("DA="+da);

System.out.println("TotSal="+totSal);

ii
}

ath
}

o/p:

aip
BSal=17453

HRA=16231.29
hM
DA=10995.39

TotSal=44679.68

========================================================
tes

*imp

2.NonPrimitive Datatypes:
a

=>The "group valued data formats" are known as NonPrimitive datatypes


nk

or Referential datatypes.

=>NonPrimitive datatypes are categorized into four types:


Ve

(a)Class

(b)Interface

(c)Array

(d)Enum

============================================================
*imp

Object Oriented Programming:

=>The process of constructing applications using class-object concept

is known as Object Oriented programming.

=>In object oriented programming we control NonPrimitive datatypes

or Referential datatypes

ii
ath
Levels in Object Oriented programming:

1.Object definition

aip
2.Object creation

3.Object location
hM
4.Object Components

5.Object Types

6.Object Cloning
tes

7.Object Serializable

8.Object Locking
a

9.Objects Collection(Grouping objects)


nk

10.Objects Sorting

==============================================================
Ve
Dt : 9/11/2022

*imp

define "object"?

=>Object is a Storage related to a class holding the members of class.

=>we use "new" keyword in java to create objects.

syntax of Object creation:

ii
ath
Class_name obj_name = new Class_name();

===================================================================

aip
*imp

define "static" keyword?


hM
=>"static" keyword in java is used to declare programming components.

=>This "static" keyword will decide the memory location of programming components.

=>Based on "static" keyword programming components are categorized into two types:
tes

(i)static programming components

(ii)NonStatic programming components


a
nk

(i)static programming components:

=>The programming components which are declared with "static" keyword are known
Ve

as "static programming components" and will get the memory within the class.

(ii)NonStatic programming components:

=>The programming components which are declared without "static" keyword are

known as NonStatic programming components and will get the memory within the
Object.

======================================================================

EX-program : Test.java

class Test

int a=10;//4 bytes memory in Object

ii
static int b=20;//4 bytes memory in Class

ath
public static void main(String[] args) //memory in class

aip
Test ob = new Test();

System.out.println("a value="+ob.a);
hM
System.out.println("b value="+Test.b);

}
tes

o/p:

a value=10
a

b value=20
nk

Diagram:
Ve
ii
ath
aip
hM
============================================================
tes

*imp

(a)Class:
a

=>Class is a "structured layout" and which generate "Objects".


nk

=>Class is a Collection of Variables and methods

=>Classes in java are categorized into two types:


Ve

1.Pre-defined classes

2.User defined classes

1.Pre-defined classes:

=>The classes which are already defined and available from JavaLib are known as
Pre-defined classes or Built-in classes.

Ex:

String

System

2.User defined classes:

ii
=>The classes which are defined by the programmer are known as User defined

ath
classes

Ex:

aip
Addition

StudentResult
hM
EmployeeSalary

==========================================================================

*imp
tes

Variables in Java:

=>Variables are the data holders in applications.


a

=>Based on datatype variables are categorized into two types:


nk

1.Primitive datatype variables

2.NonPrimitive datatype variables


Ve

1.Primitive datatype variables:

=>The variables which are declared with primitive datatypes like byte,short,

int,long,float,double,char,boolean are known as Primitive datatype variables.

=>These primitive datatype variables will hold values.


2.NonPrimitive datatype variables:

=>The variables which are declared with NonPrimitive datatypes like Class,

Interface,Array,Enum are known as NonPrimitive datatype variables or referential

datatype variables

=>These NonPrimitive datatype variables will hold Object references or Object

ii
Addresses.

ath
=======================================================================

aip
hM
a tes
nk
Ve
Dt : 10/11/2022

*imp

=>Based on static keyword the variables are categorized into two types:

1.Static Variables

2.NonStatic Variables

ii
1.Static Variables:

ath
=>The variables which are declared with "static" keyword are known as "static"

variables or Class Variables.

aip
=>These static variables will get the memory within the class while class

loading and can be accessed with class_name.


hM
2.NonStatic Variables:

=>The variables which are declared without "static" keyword are known as
tes

NonStatic variables

=>These NonStatic variables are categorized into two types:


a

(a)Instance Variables
nk

(b)Local Variables
Ve

(a)Instance Variables:

=>The NonStatic variables which are declared outside the methods are known

as Instance Variables or Object Variables.

=>These Instance variables will get the memory within the object while

Object creation and can be accessed with object_name


(b)Local Variables:

=>The NonStatic variables which are declared inside the methods are known

as Local Variables.

=>These Local variables will get the memory within the method while method

execution.

ii
=========================================================================

ath
faq:

define static local variables?

aip
=>There is no concept of static local variables in java,which means we cannot

declare local variables with "static" keyword.


hM
faq:

define Global variables?


tes

=>There is no concept of Global variables in Java,becuase variables must be

declared inside class or Interface or Enum or Record.


a

========================================================================
nk

*imp

Methods in Java:
Ve

=>Methods are the actions and which generate results.

=>Based on "static" keyword methods are categorized into two types:

1.static methods

2.NonStatic methods(Instance methods)


1.static methods:

=>The methods which are declared with "static" keyword are known as static

methods or Class methods.

=>These static methods will get the memory within the class while class

loading and canbe accessed with Class_name.

ii
struture of static methods:

ath
static return_type method_name(para_list)

aip
//method_body

}
hM
Coding rule:

=>Static methods can access static variables directly but cannot access
tes

Instance variables directly.

--------------------------------------------------------------
a

=>Types of "static" methods:


nk

=>Static methods are categorized into two types:

(i)Pre-defined static methods


Ve

(ii)User defined static methods

(i)Pre-defined static methods:

=>The static methods which are already defined and available from JavaLib

are known as Pre-defined static methods.


(ii)User defined static methods:

=>The static methods which are defined by the user(programmer) are known

as User defined static methods.

=====================================================================

2.NonStatic methods(Instance methods):

ii
=>The methods which are declared without "static" keyword are known as

ath
NonStatic methods or Instance methods or Object methods.

=>These Instance methods will get the memory within the object while object

aip
creation process and can be accessed with Object_name.
hM
structure of Instance methods

return_type method_name(para_list)

{
tes

//method_body

}
a
nk

Coding rule:

=>Instance methods can access both variables,Instance variables and Static


Ve

variables.

------------------------------------------------------------

=>Types of Instance methods:

=>Instance methods are categorized into two types:

(i)Pre-defined Instance methods


(ii)User defined Instance methods

(i)Pre-defined Instance methods:

=>The Instance methods which are defined and available from JavaLib are

known as Pre-defined Instance methods.

ii
(ii)User defined Instance methods:

ath
=>The Instance methods which are defined by the User(Programmer) are known

as User defined Instance methods.

aip
======================================================================

Ex-program : DemoMethods1.java
hM
class DemoMethods1

int a=10; //Instance Variable memory in Object


tes

static int b=20; //Static Variables memory in Class

static void m1()//Static method memory in class


a

{
nk

System.out.println("****static method m1()****");

//System.out.println("a value:"+a);//Error
Ve

System.out.println("b value:"+b);

void m2()//Instance method memory in Object

System.out.println("****Instance method m2()*****");


System.out.println("a value:"+a);

System.out.println("b value:"+b);

public static void main(String[] args)

DemoMethods1.m1();//method_call

ii
DemoMethods1 ob = new DemoMethods1();

ath
ob.m2();//method_call

aip
}

o/p:
hM
****static method m1()****

b value:20

****Instance method m2()*****


tes

a value:10

b value:20
a

=====================================================================
nk
Ve
Dt : 11/11/2022

faq:

define parameters?

=>parameters are the variables which are used to transfer the data from one

method to another method.

=>Based on Parameters the methods are categorized into two types:

ii
1.Methods without parameters

ath
2.Methods with parameters

aip
1.Methods without parameters:

=>The methods which are declared without parameters are known as 0-parameter
hM
methods or Methods without parameters.

2.Methods with parameters:


tes

=>The methods which are declared with parameters are known as Parameterized

methods or Methods with parameters.


a

====================================================================
nk

faq:

define return_type?
Ve

=>return_type specify the methods will return the value or not.

=>Based on return_type methods are categorized into two types:

1.NonReturn type methods

2.Return type methods


1.NonReturn type methods:

=>The methods which will not return the value after method execution are known

as NonReturn type methods.

=>The methods which are declared with "void" are known as NonReturn type methods

2.Return type methods:

ii
=>The methods which return the value after method execution are known as Return

ath
type methods.

=>The methods which are declared without "void" are known as Return type methods.

aip
============================================================================

*imp
hM
JVM Architecture with Internals:

=>JVM Stands for "Java Virtual Machine" and which is used to execute JavaByteCode

=>JVM internally divided into the following partitions:


tes

1.Class Loader SubSystem

2.Runtime Data Area


a

3.Execution Engine
nk

1.Class Loader SubSystem:


Ve

=>Class Loader SubSystem will load the class-file on to Runtime Data Area using

loaders.

2.Runtime Data Area:

=>This Runtime Data Area internally divided into the following partitions:
(a)Method Area

(b)Heap Area

(c)Java Stack Area

(d)PC Register Area

(e)Native Method Area

ii
(a)Method Area:

ath
=>The memory loaction where the class is loaded is known as Method Area.

=>when MainClass loaded onto Method Area,main() method will get the memory.

aip
=>Once main() method got the memory then it is automatically copied to

Java Stack Area to start the execution process.


hM
(b)Heap Area:

=>The memory block where the objects are created is known as Heap Area.
tes

(c)Java Stack Area:


a

=>The memory block where the methods are executed is known as Java Stack Area.
nk

=>main() is the first method copied onto Java Stack Area to start the execution

process and this main() method will call remaining methods for execution.
Ve

faq:

define Method Frame?

=>The partition of Java Stack Area where the method is copied for execution is

known as Method Frame.


=>After method execution completed the method frame will be destroyed

automatically

Diagram : (Execution flow of above program)

ii
ath
aip
hM
tes

=============================================================================
a
nk
Ve
Dt : 12/11/2022

faq:

wt is the diff b/w

(i)Object

(ii)Object reference

(iii)Object reference Variable

ii
(i)Object:

ath
=>The memory generated to hold Instance members of class is known as Object.

(Storage part is known as Object)

(ii)Object reference:

aip
=>The address location where the object is created is known as Object reference.

(iii)Object reference Variable:


hM
=>The NonPrimitive datatype variable which is holding object reference is known

as Object reference variable or Object name.


tes

Diagram:
a
nk
Ve
================================================================

(d)PC Register Area:

=>Program Counter(PC) Registers will hold the status of method executions in

Java Stack Area.

=>Every method which is executing in Java Stack Area will have its own

Program Counter Register.

ii
=>All these Program Counter Registers are opened in a separete memory block

ath
known as PC-Register Area.

======================================================================

(e)Native Method Area:

aip
=>The methods from JavaLib which are declared with "native" keyword are known

as Native methods.
hM
=>These Native methods internally having c/c++ code.

=>when these Native methods are used in applications then they are identified

by the "Class Loader SubSystem" and loaded onto Separate memory block known as
tes

Native method Area.

=>These Native methods are executed using JNI(Java Native method Interface)
a

and while execution JNI uses Native method Libraries.


nk

======================================================================

3.Execution Engine:
Ve

=>Execution Engine is an Executor of JVM and which starts the execution

process with main() method available from Java Stack Area.

=>Execution Engine internally having two translators:

(a)Interpreter

(b)JIT(Just-In-Time) Compiler
(a)Interpreter:

=>Interpreter will start the execution process and executes normal

instructions.

=>when Interpreter finds Stream instructions(Multi-media Instructions) then

it transfers the control to JIT-Compiler.

ii
ath
(b)JIT Compiler:

=>JIT Compiler will execute Stream intructions or Multi-media Instructions.

========================================================================

aip
faq:

why Java uses Interpreter in Execution process?


hM
=>when we have interpreter in execution process,then we can accept the request

in the middle of execution process and which is preferable for Server application

development.
tes

===========================================================================

Note:
a

Java is Interpreted Language becuase it uses Interpreter in execution process.


nk

===========================================================================
Ve
Ve
nk
ates
hM
aip
ath
ii
Dt : 14/11/2022

*imp

"Scanner" class:

=>"Scanner" is a pre-defined class from "util"(utility) package and which

provide pre-defined Insance methods to read the data from the console(Keyboard)

ii
ath
aip
hM
a tes

=>The following are some important instance methods from 'Scanner" class:
nk

1.nextByte() - to read byte data

2.nextShort() - to read short date


Ve

3.nextInt() - to read int date

4.nextLong() - to read long data

5.nextFloat() - to read float data

6.nextDouble() - to read double data

7.nextBoolean() - to read boolean data


8.nextLine() - to read String data

=>we use the following syntax to create object for "Scanner" class:

Scanner s = new Scanner(System.in);

=>"System.in" in Java represent connecting OS-Buffer to Scanner class object.

=>The following are the syntaxes of methods:

ii
1.nextByte() - to read byte data

ath
Method Signature : public byte nextByte();

syntax : byte var = s.nextByte();

2.nextShort() - to read short date

aip
hM
Method Signature : public short nextShort();

syntax : short var = s.nextShort();


tes

3.nextInt() - to read int date

Method Signature : public int nextInt();


a

syntax : int var = s.nextInt();


nk

4.nextLong() - to read long data


Ve

Method Signature : public long nextLong();

syntax : long var = s.nextLong();

5.nextFloat() - to read float data

Method Signature : public float nextFloat();


syntax : float var = s.nextFloat();

6.nextDouble() - to read double data

Method Signature : public double nextDouble();

syntax : double var = s.nextDouble();

ii
7.nextBoolean() - to read boolean data

ath
Method Signature : public boolean nextBoolean();

syntax : boolean var = s.nextBoolean();

8.nextLine() - to read String data

aip
hM
Method Signature : public String nextLine();

syntax : String var = s.nextLine();


tes

Ex-program : wap to read and display UserDetails(UserName,MailId,phNo)?


a

DemoMethods2.java
nk

import java.util.Scanner;

class DemoMethods2
Ve

public static void main(String[] args)

Scanner s = new Scanner(System.in);

System.out.println("Enter UserName:");
String name = s.nextLine();//will read String data

System.out.println("Enter the MailId:");

String mailId=s.nextLine();

System.out.println("Enter the PhoneNo:");

long phNo=s.nextLong();

System.out.println("====UserDetails====");

ii
System.out.println("UserName:"+name);

ath
System.out.println("MailId:"+mailId);

System.out.println("PhoneNo:"+phNo);

aip
}

}
hM
o/p:

Enter UserName:

raj
tes

Enter the MailId:

[email protected]
a

Enter the PhoneNo:


nk

9898981234

====UserDetails====
Ve

UserName:raj

MailId:[email protected]

PhoneNo:9898981234

Diagram:
ii
ath
aip
hM
tes

=====================================================================

Assignment-1:
a
nk

wap to read and display BookDetails(code,name,author,price,qty)?


Ve

Assignment-2:

wap to read and display BankCustomer details(accNo,name,balance,accType)?

==========================================================================
Dt : 15/11/2022

Assignment-1:(Solution)

wap to read and display BookDetails(code,name,author,price,qty)?

Program : DemoMethods3.java

import java.util.Scanner;

ii
class DemoMethods3

ath
{

public static void main(String[] args)

aip
{

Scanner s = new Scanner(System.in);//Scanner object connected to Console


hM
System.out.println("Enter the BookCode:");

String code = s.nextLine();

System.out.println("Enter the BookName:");


tes

String name = s.nextLine();

System.out.println("Enter the BookAuthor:");


a

String author = s.nextLine();


nk

System.out.println("Enter the BookPrice:");

float price = s.nextFloat();


Ve

System.out.println("Enter the BookQty:");

int qty = s.nextInt();

System.out.println("=====BookDetails=====");

System.out.println("BookCode="+code);

System.out.println("BookName="+name);
System.out.println("BookAuthor="+author);

System.out.println("BookPrice="+price);

System.out.println("BookQty="+qty);

ii
o/p:

ath
Enter the BookCode:

CS121

aip
Enter the BookName:

C-Lang
hM
Enter the BookAuthor:

B-Swamy

Enter the BookPrice:


tes

234.56

Enter the BookQty:


a

12
nk

=====BookDetails=====

BookCode=CS121
Ve

BookName=C-Lang

BookAuthor=B-Swamy

BookPrice=234.56

BookQty=12

==============================================================
Assignment-2:

wap to read and display BankCustomer details(accNo,name,balance,accType)?

Program : DemoMethods4.java

import java.util.Scanner;

class DemoMethods4

ii
{

ath
public static void main(String[] args)

aip
Scanner s = new Scanner(System.in);

System.out.println("Enter the AccNo:");


hM
long accNo = Long.parseLong(s.nextLine());

System.out.println("Enter the CustName:");

String name = s.nextLine();


tes

System.out.println("Enter the Balance:");

float bal = Float.parseFloat(s.nextLine());


a

System.out.println("Enter the AccType:");


nk

String accType = s.nextLine();

System.out.println("====CustomerDetails====");
Ve

System.out.println("AccNo:"+accNo);

System.out.println("CustName:"+name);

System.out.println("Balance:"+bal);

System.out.println("AccType:"+accType);

}
}

o/p:

Enter the AccNo:

6123456

Enter the CustName:

Raj Kumar

ii
Enter the Balance:

ath
12000

Enter the AccType:

aip
Savings

====CustomerDetails====
hM
AccNo:6123456

CustName:Raj Kumar

Balance:12000.0
tes

AccType:Savings

==========================================================================
a

Note:
nk

=>In Java,when we read String data after numeric data,the String data will be

skipped in reading from Console(Keyboard),because the buffer will hold enter-key


Ve

information.

=>This Dis-Advantage can be overcomed using the following parse-methods:

byte var = Byte.parseByte(s.nextLine());

short var = Short.parseShort(s.nextLine());

int var = Integer.parseInt(s.nextLine());


long var = Long.parseLong(s.nextLine());

float var = Float.parseFloat(s.nextLine());

double var = Double.parseDouble(s.nextLine());

ii
ath
aip
hM
tes

=========================================================================
a

*imp
nk

Operators in Java:
Ve

=>Operators are the special symbols which are used to perform operations.

=>The following are some important operators in Java:

1.Arithmetic Operators

2.Relational Operators

3.Logical Operators

4.Increment/Decrement Operators
1.Arithmetic Operators:

=>Arithmetic operators are used to perform fundamental operations or basic

operations.

Operator Meaning

+ Addition

ii
- Subtraction

ath
* Multiplication

/ Division

aip
% ModDivision
hM
2.Relational Operators:

=>Relational operators are used to compare two values and generate boolean

reasult.
tes

Operator Meaning

> Greater Than


a

>= Greater Than or equal to


nk

< Less Than

<= Less Than or equal to


Ve

== Is Equal to

!= Not Equal to

3.Logical Operators:

=>Logical Operators are used to compare two comparisions and generate boolean
result.

Operator Meaning

&& Logical AND

|| Logical OR

! Logical NOT

ii
Logical AND(&&):

ath
A B A&&B

T T T

aip
F T F

T F F
hM
F F F

Logical OR(||):
tes

A B A||B

T T T
a

F T T
nk

T F T

F F F
Ve

Logical NOT(!):

A !A

T F
F T

4.Increment/Decrement Operators:

=>Increment operator will increment the value by 1 and decrement operator will

decrement the value by 1.

Operator Meaning

ii
++ Increment

ath
-- Decrement

=========================================================================

aip
*imp

Control Structures in Java:


hM
=>The structures which are used to control the part of program for execution are

known as Control Structures.

=>These Control Structures are categorized into three types:


tes

1.Selection statements

2.Iterative statements
a

3.Branching statements
nk

1.Selection statements:
Ve

=>The statements which are used to select part of program for execution based

on condition are known as Selection statements or Conditional Statements.

=>Types:

(a)Simple if

(b)if-else
(c)Nested if

(d)Ladder if-else

(e)switch-case

2.Iterative statements:

=>The statements which are used to execute some lines of program repeatedly

ii
are known as Iterative Statements or Repeatitive Statements or Looping Structures

ath
=>Types:

(a)while loop

aip
(b)do-while loop

(c)for loop
hM
3.Branching statements:

=>The statements which are used to transfer the execution-control from one
tes

location to another location are known as Branching statements or Transfer

statements
a

=>Types:
nk

(a)break

(b)continue
Ve

(c)return

(d)exit

Note:

=>"goto" statement is not available in Java.

=================================================================
Note:

=>In the process of constructing Java Applications we must use one MainClass

and any number of SubClasses.

MainClass - The class in application which is holding main() method is known as

MainClass

SubClass - The classes which are declared in applications other than MainClass

ii
are known as SubClasses.

ath
=====================================================================

Assignment1:

aip
wap to read 6 sub marks and display totMarks and percentage?
hM
Codition:

=>If all the Submarks are in b/w 0 to 100 then calculate totMarks and per,

else display msg as "Invalid" marks


tes

===========================================================

Assignment2:
a

wap to read bSal,hra,da and calculate totSal?


nk

Condition:
Ve

=>bSal must be min 12000/-,else "Invalid bSal".

=>hra and da must greater than zero,else "Invalid hra and da"

==============================================================
Dt : 16/11/2022

Ex-program : wap to read two int numbers and perform the following operations based on

user choice:

1.GreaterValue

2.SmallerValue

ii
SubClasses : GreaterValue,SmallerValue

ath
MainClass : DemoMethods5

aip
program : DemoMethods5.java

import java.util.Scanner;
hM
class GreaterValue //SubClass

int greater(int x,int y)


tes

if(x>y)
a

{
nk

return x;

}
Ve

else

return y;

}
}

class SmallerValue //SubClass

int smaller(int x,int y)

if(x<y)

ii
{

ath
return x;

aip
else

{
hM
return y;

}
tes

class DemoMethods5 //MainClass


a

{
nk

public static void main(String[] args)

{
Ve

Scanner s = new Scanner(System.in);

System.out.println("Enter the value-1:");

int v1 = s.nextInt();

System.out.println("Enter the value-2:");

int v2 = s.nextInt();
if(v1>0 && v2>0)

if(v1==v2)

System.out.println("Values are equal...");

ii
else

ath
{

System.out.println("****Choice*****");

aip
System.out.println("1.GreaterValue\n2.SmallerValue");

System.out.println("Enter the Choice:");


hM
int choice = s.nextInt();

switch(choice)

{
tes

case 1:

GreaterValue gv = new GreaterValue();


a

int r1 = gv.greater(v1,v2);
nk

System.out.println("GreaterValue:"+r1);

break;//stop the switch


Ve

case 2:

SmallerValue sv = new SmallerValue();

int r2 = sv.smaller(v1,v2);

System.out.println("SmallerValue:"+r2);

break;
default:

System.out.println("Invalid Choice...");

}//end of switch

else

ii
{

ath
System.out.println("Invalid values...");

aip
}

}
hM
o/p:

Enter the value-1:

12
tes

Enter the value-2:

13
a

****Choice*****
nk

1.GreaterValue

2.SmallerValue
Ve

Enter the Choice:

SmallerValue:12

-----------------------------------------------------------------

Execution flow of above program:


ClassFiles:

GreaterValue.class

SmallerValue.class

DemoMethods5.class(MainClass)

ii
ath
aip
hM
a tes
nk

=======================================================================

List of variables from the above program:


Ve

Primitive datatype variables : v1,v2,choice,r1,r2,x,y

NonPrimitive datatype variables : s,gv,sv

parameters : v1,v2,x,y
Actual parameters : v1,v2

Formal parameters : x,y

Note:

=>we can have have same parameter names in actual parameters and formal parameters.

=============================================================================

faq:

ii
define switch-case statement?

ath
=>switch-case statement is used to select one from multiple available options

or cases.

aip
syntax:

switch(value)
hM
{

case 1:statements;

break;
tes

case 2:statements;

break;
a

...
nk

case n:statements;

break;
Ve

default:statements;

Execution behaviour:

=>switch-value is compared with available options and if the switch-value is


matched with any option then statements are executed.

=>After executing statements,we use break to stop the switch-case.

=>If the switch-value is not matched with any available options then default is

executed.

==================================================================

Assignment:

ii
wap to read two int values and perform the following operations based of user

ath
choice:

1.add

aip
2.sub

3.mul
hM
4.div

5.modDiv
tes

SubClasses : Addition,Subtraction,Multiplication,Division,ModDivision

MainClass : DemoMethods6
a

========================================================================
nk
Ve
Dt : 17/11/2022

Assignment:(Solution)

wap to read two int values and perform the following operations based of user

choice:

1.add

2.sub

ii
3.mul

ath
4.div

5.modDiv

aip
SubClasses : Addition,Subtraction,Multiplication,Division,ModDivision
hM
MainClass : DemoMethods6

program : DemoMethods6.java
tes

import java.util.Scanner;

class Addition //SubClass


a

{
nk

int add(int x,int y)

{
Ve

return x+y;

class Subtraction //SubClass

{
int sub(int x,int y)

return x-y;

class Multiplication //SubClass

ii
{

ath
int mul(int x,int y)

aip
return x*y;

}
hM
}

class Division //SubClass

{
tes

float div(int x,int y)

{
a

return (float)x/y;
nk

}
Ve

class ModDivision //SubClass

int modDiv(int x,int y)

return x%y;
}

class DemoMethods6 //MainClass

public static void main(String[] args)

ii
Scanner s = new Scanner(System.in);

ath
System.out.println("Enter the int value1:");

int v1 = s.nextInt();

aip
System.out.println("Enter the int value2:");

int v2 = s.nextInt();
hM
if(v1>0 && v2>0)

System.out.println("****Choice*****");
tes

System.out.println("1.add\n2.sub\n3.mul\n4.div\n5.modDiv");

System.out.println("Enter the Choice:");


a

int choice = s.nextInt();


nk

switch(choice)

{
Ve

case 1:

Addition ad = new Addition();

int r1 = ad.add(v1,v2);

System.out.println("Sum:"+r1);

break;
case 2:

Subtraction sb = new Subtraction();

int r2 = sb.sub(v1,v2);

System.out.println("Sub:"+r2);

break;

case 3:

ii
Multiplication ml = new Multiplication();

ath
int r3 = ml.mul(v1,v2);

System.out.println("Mul:"+r3);

aip
break;

case 4:
hM
Division dv = new Division();

float r4 = dv.div(v1,v2);

System.out.println("Div:"+r4);
tes

break;

case 5:
a

ModDivision md = new ModDivision();


nk

int r5 = md.modDiv(v1,v2);

System.out.println("ModDiv:"+r5);
Ve

break;

default:

System.out.println("Invalid Choice...");

}//end of switch

}
else

System.out.println("Invalid values...");

ii
o/p:

ath
Enter the int value1:

12

aip
Enter the int value2:

7
hM
****Choice*****

1.add

2.sub
tes

3.mul

4.div
a

5.modDiv
nk

Enter the Choice:

4
Ve

Div:1.7142857

==============================================================

wap to read and display Employee details?

1.read empName
2.read empDesg

=>empDesg must be in SE or TE or ME,else "Invalid empDesg"

3.If the desg is verified successfully,then read empId

=>empId must be 4 characters(Alphanumeric),else "Invalid empId".

4.If the empId is validated,then read bSal

=>the bSal must be min 12000/-,else "Invalid bSal"

ii
5.If the bSal is validated,then read hra and da

ath
=>The hra and da must greater than zero

6.If all are validated successfully then calculate totSal.

Program : DemoMethods7.java

aip
hM
import java.util.Scanner;

class CheckDesignation //SubClass

{
tes

boolean verify(String empDesg)

{
a

return switch(empDesg)
nk

case "SE":yield true;


Ve

case "TE":yield true;

case "ME":yield true;

default:yield false;

};

}
}

class EmpTotalSalary //SubClass

float calculate(int bSal,float hra,float da)

return bSal+hra+da;

ii
}

ath
}

class DemoMethods7 //MainClass

aip
{

public static void main(String[] args)


hM
{

Scanner s = new Scanner(System.in);

System.out.println("Enter the EmpName:");


tes

String empName = s.nextLine();

System.out.println("Enter the empDesg:");


a

String empDesg = s.nextLine().toUpperCase();


nk

CheckDesignation cd = new CheckDesignation();

boolean k = cd.verify(empDesg);
Ve

if(k)

System.out.println("Enter the empId:");

String empId = s.nextLine();

int len = empId.length();


if(len==4)

System.out.println("Enter the bSal:");

int bSal = s.nextInt();

if(bSal>=12000)

ii
System.out.println("Enter the HRA:");

ath
float h= s.nextFloat();

float hra = (h*bSal)/100;

aip
System.out.println("Enter the DA:");

float d = s.nextFloat();
hM
float da = (d*bSal)/100;

if(hra>0 && da>0)

{
tes

EmpTotalSalary ob = new EmpTotalSalary();

float totSal = ob.calculate(bSal,hra,da);


a

System.out.println("EmpName:"+empName);
nk

System.out.println("EmpDesg:"+empDesg);

System.out.println("EmpId:"+empId);
Ve

System.out.println("BSal:"+bSal);

System.out.println("TotSal:"+totSal);

}//end of if

else

{
System.out.println("Imvalid hra and da..");

}//end of if

else

System.out.println("Invalid bSal...");

ii
}

ath
}//end of if

aip
else

{
hM
System.out.println("Invalid empId...");

}
tes

}//end of if

else
a

{
nk

System.out.println("Invalid empDesg...");

}
Ve

o/p:

Enter the EmpName:


Raj

Enter the empDesg:

SE

Enter the empId:

A121

Enter the bSal:

ii
17000

ath
Enter the HRA:

93

aip
Enter the DA:

61
hM
EmpName:Raj

EmpDesg:SE

EmpId:A121
tes

BSal:17000

TotSal:43180.0
a

=========================================================
nk
Ve
Dt : 18/11/2022

Assignment-1:

wap to read and display Student details with result?

1.read stuName

2.read stuBranch

ii
=>stuBranch must be in CIVIL or MECH or EEE or ECE or CSE,else "Invalid branch"

ath
3.If the branch is verified Successfully,then read stuRollNo

=>rollNo must be 10 characters(Alphanumeric),else "Invalid rollNo".

aip
4.If rollNo validated Successfully,then read six subject marks.

=>If six sub marks entered in b/w 0 to 100,then calculate


hM
totMarks

per

result
tes

per : 70 to 100 ==>Distinction(Grade A)

60 to <70 ==>FirstClass(Grade B)
a

50 to <60 ==>SecondClass(Grade C)
nk

35 to <50 ==>ThirdClass(Grade d)

else ==>Fail
Ve

o/p :

Name =

Branch =

RollNo =
totMarks=

per =

result=

Note:

=>If any one sub entered in b/w 0 to 34 then display Student details with

ii
result as "Fail".

ath
Layout:

aip
hM
a tes
nk
Ve

========================================================================

Assignment-2:

wap to read three int values and perform the following operations:

1.GreaterValue
2.SmallerValue

Note:

=>All three values must be greater than zero

=>Display "equal.." if all three values are same.

ii
=========================================================================

ath
define return_type switch?

=>return_type switch introduced by Java13 version and which is used to return

aip
the result.
hM
syntax:

return switch(value)

{
tes

case 1 : yield result;

case 2 : yield result;


a

...
nk

default : yield default_result;

};
Ve

Note:

=>"yield" keyword specify to stop the switch execution and return the result.

==============================================================================

*imp
Blocks in Java:

=>The set-of-statements which are declared within the flower brackets and

executed automatically is known as block.

=>Blocks in Java are categorized into two types:

1.static blocks

2.NonStatic blocks(Instance blocks)

ii
ath
1.static blocks:

=>The blocks which are declared with "static" keyword are known as static blocks

aip
or Class blocks.
hM
syntax:

static

{
tes

//statements

}
a
nk

Execution behaviour of static block:

=>static block is executed only once with highest priority when the class is
Ve

used for first time.

=>static block can access static variables directly,but cannot access instance

variables directly.

Ex : DemoBlock1.java
class DemoBlock1 //MainClass

static int k=200;

public static void main(String[] args)

System.out.println("****main()*****");

ii
System.out.println("The value k:"+k);

ath
}

static

aip
{

System.out.println("****static block****");
hM
System.out.println("The value k:"+k);

}
tes

o/p:

****static block****
a

The value k:200


nk

****main()*****

The value k:200


Ve

-------------------------------------------------------------------------

Ex : DemoBlock2.java

class Test //SubClass

static int z;
static

System.out.println("****Static block****");

System.out.println("The value z:"+z);

static int getValue()

ii
{

ath
return z;

aip
}

class DemoBlock2 //MainClass


hM
{

public static void main(String[] args)

{
tes

Test.z = 200;

int p = Test.getValue();
a

System.out.println("*****main()******");
nk

System.out.println("The value z:"+p);

}
Ve

o/p:

****Static block****

The value z:0

*****main()******
The value z:200

===========================================================

ii
ath
aip
hM
a tes
nk
Ve
Dt : 19/11/2022

Execution for above program:(DemoBlock1.java)

ii
thi
ipa
Ma
Execution flow of above program(DemoBlocks2.java)
sh
ate
nk
Ve

============================================================

2.NonStatic blocks(Instance blocks):

=>The blocks which are declared without "static" keyword are known as Instance
blocks or NonStatic blocks.

syntax:

//statements

ii
}

thi
Execution behaviour of NonStatic block:

ipa
=>NonStatic block or Instance block executed while object creation process.

=>NonStatic block is executed for every multiple object creation process.


Ma
=>NonStatic block can access both static and Instance variables.
sh
Ex-program : DemoBlock3.java

class BTest //SubClass


ate

int a = 10;
nk

static int b = 20;


Ve

a++;

b++;

System.out.println("====Instance block====");

System.out.println("The value a:"+a);


System.out.println("The value b:"+b);

class DemoBlock3

public static void main(String[] args)

ii
{

thi
BTest ob1 = new BTest();//Object

BTest ob2 = new BTest();//Object

ipa
}

o/p:
Ma
====Instance block====
sh
The value a:11

The value b:21


ate

====Instance block====

The value a:11


nk

The value b:22

--------------------------------------------------------------
Ve

Execution flow of above program:


ii
thi
ipa
Ma
======================================================================
sh
ate
nk
Ve
Dt : 21/11/22

Note:

=>Class can generate any number of objects without restriction and the multiple

objects generated from the class are independent by their memory location on

HeapArea.

=>In generating multiple objects the class will be loaded only once.

ii
=========================================================================

ath
faq:

wt is the diff b/w

aip
(i)Block

(ii)Method
hM
=>Blocks are executed automatically without calling,but methods are executed on

MethodCall.
tes

=>Blocks will have Highest Priority in execution than methods.

=>static blocks will have highest priority in execution than static methods.
a

=>Instance blocks will have highest priority in execution than Instance methods.
nk

=============================================================================

*imp
Ve

Constructors in Java:

=>Constructor is a method having the same name of the class and executed while

object creation,because the constructor call is available in Object creation

syntax attached with "new" keyword.

=>while declaring constructor we must not use return_type,because the constructor


will have Class_return_type

structure of Constructor:

Class_name(para_list)

//method_body

ii
}

ath
-----------------------------------------------------------------

=>Based on parameters the constructors are categorized into two types:

aip
1.Constructors without parameters

2.Constructors with parametes


hM
1.Constructors without parameters:

=>The Constructors which are declared without parameters are known as 0-parameter
tes

Constructors or Constructors without parameters.


a

Ex-program : DemoCon1.java
nk

class CTest1 //SubClass

{
Ve

int k=12;

CTest1()

System.out.println("====CTest()====");

System.out.println("The value k:"+k);


}

void dis()

System.out.println("====dis()====");

System.out.println("The value k:"+k);

ii
}

ath
class DemoCon1 //MainClass

aip
public static void main(String[] args)

{
hM
CTest1 ob = new CTest1();//Con_Call

ob.dis();//Method_call

ob.dis();
tes

ob.dis();

}
a

}
nk

o/p:

====CTest()====
Ve

The value k:12

====dis()====

The value k:12

---------------------------------------------------------

Execution flow of above program:


ii
ath
aip
================================================================

faq:
hM
wt is the diff b/w

(i)Constructor

(ii)Instance method
tes

=>Constructor is executed while object creation,but Instance method is executed


a

after Object creation.


nk

=>Constructor is executed only once while object creation,but Instance method

can be executed any number of times from the same object.


Ve

=====================================================================
Dt : 22/11/2022

faq:

define default Constructor?

=>The Constructor without parameters which is added by the compiler at compilation

stage is known ad default constructor.

ii
faq:

ath
In wt situation default constructor is added?

=>Compiler at compilation stage finds any class declared without constructors

aip
then default constructor is added.
hM
faq:

wt is the diff b/w

(i)Instance block
tes

(ii)Constructor

=>Both components are executed while object creation process,but Instance block
a

will have highest priority in execution than Constructor.


nk

faq:
Ve

wt is the diff b/w

(i)static block

(ii)Constructor

=>Static block is executed only once with highest priority when the class is used
for the first time and Constructor also executes only once while object creation

process.

faq:

wt is the behaviour of constructor declared with return_type?

=>when constructor declared with return_type then it is considered as normal

ii
method.

ath
faq:

aip
Can we declare "return" statement in Constructor?

=>Yes,we can declare "return" statement in constructor,but it must be empty


hM
return type.

faq:
tes

define static constructor?

=>There is no concept of Static Constructors in java,because Constructor means


a

executed while object creation process and which cannot be Class_level_component.


nk

Ex : DemoCon2.java
Ve

class CTest2 //SubClass

CTest2()

{
System.out.println("****CTest2()****");

return;

System.out.println("****Instance block****");

ii
}

ath
static

aip
{

System.out.println("****Static block****");
hM
}

class DemoCon2 //MainClass


tes

public static void main(String[] args)


a

{
nk

CTest2 ob = new CTest2();//Con_Call

}
Ve

o/p:

****Static block****

****Instance block****

****CTest2()****
=================================================================

2.Constructors with parametes:

=>The Constructors which are declared with parameters are known as Parameterized

constructors or Constructors with parameters.

=>we pass parameters to parameterized constructors while Object creation process.

ii
Ex-program : DemoCon3.java

ath
import java.util.Scanner;

class CTest3 //SubClass

aip
{

CTest3(int x,int y,int z)


hM
{

System.out.println("====CTest3(x,y,z)====");

System.out.println("x:"+x);
tes

System.out.println("y:"+y);

System.out.println("z:"+z);
a

}
nk

CTest3(int x,int y)

{
Ve

System.out.println("====CTest3(x,y)====");

System.out.println("x:"+x);

System.out.println("y:"+y);

CTest3(int x)
{

System.out.println("====CTest3(x)====");

class DemoCon3 //MainClass

ii
public static void main(String[] args)

ath
{

Scanner s = new Scanner(System.in);

aip
System.out.println("Enter the value of x:");

int x = s.nextInt();
hM
System.out.println("Enter the value of y:");

int y = s.nextInt();

System.out.println("Enter the value of z:");


tes

int z = s.nextInt();

System.out.println("====Choice=====");
a

System.out.println("1.CTest3(x,y,z)\n2.CTest3(x,y)\n3.CTest3(x)");
nk

System.out.println("Enter the Choice:");

int choice = s.nextInt();


Ve

switch(choice)

case 1:

CTest3 ob1 = new CTest3(x,y,z);//Con_3_para

break;
case 2:

CTest3 ob2 = new CTest3(x,y);//Con_2_para

break;

case 3:

CTest3 ob3 = new CTest3(x);//Con_1_para

break;

ii
default:

ath
System.out.println("Invalid Choice....");

}//end of switch

aip
}

}
hM
o/p:

Enter the value of x:

11
tes

Enter the value of y:

12
a

Enter the value of z:


nk

13

====Choice=====
Ve

1.CTest3(x,y,z)

2.CTest3(x,y)

3.CTest3(x)

Enter the Choice:

1
====CTest3(x,y,z)====

x:11

y:12

z:13

===================================================================

*imp

ii
Multiple Constructors in Class:

ath
=>we can declare multiple Constructors within the class and only one Constructor

is executed while object creation process.

Note:

aip
hM
=>when we want to execute multiple Constructors then we have to create multiple

Objects.

======================================================================
tes

faq:

Can we execute multiple constructors by creating single Object?


a

=>Yes,we can execute multiple Constructors by creating single object,using


nk

Constructor Chaining process or Constructor Inter-Linlking process.


Ve

faq:

define Constructor Chaining process?

=>The process of calling one constructor from another constructor using "this()"

is known as Constructor Chaining process.


Coding Rule:

=>"this()" is a Pre-defined format to call constructors from the same class and

"this()" must be declared as first line in the constructor.

-----------------------------------------------------------------

Ex : DemoCon4.java

import java.util.Scanner;

ii
class CTest4 //SubClass

ath
{

CTest4(int x,int y,int z)

aip
{

this(x,y);//Con_2_para
hM
System.out.println("====CTest3(x,y,z)====");

System.out.println("x:"+x);

System.out.println("y:"+y);
tes

System.out.println("z:"+z);

}
a

CTest4(int x,int y)
nk

this(x);//Con_1_para
Ve

System.out.println("====CTest3(x,y)====");

System.out.println("x:"+x);

System.out.println("y:"+y);

CTest4(int x)
{

System.out.println("====CTest3(x)====");

System.out.println("x:"+x);

class DemoCon4 //MainClass

ii
{

ath
public static void main(String[] args)

aip
Scanner s = new Scanner(System.in);

System.out.println("Enter the value of x:");


hM
int x = s.nextInt();

System.out.println("Enter the value of y:");

int y = s.nextInt();
tes

System.out.println("Enter the value of z:");

int z = s.nextInt();
a

CTest4 ob = new CTest4(x,y,z);//Con_3_para


nk

}
Ve

o/p:

Enter the value of x:

11

Enter the value of y:

12
Enter the value of z:

13

====CTest3(x)====

x:11

====CTest3(x,y)====

x:11

ii
y:12

ath
====CTest3(x,y,z)====

x:11

aip
y:12

z:13
hM
=================================================================

*imp

Advantage of Constructor:
tes

=>Constructors are used to initialize instance variables while object creation

process and which saves the execution time and generate HighPerformance of an
a

application
nk

===============================================================
Ve
Dt : 23/11/2022

Ex-program : DemoCon5.java

import java.util.Scanner;

class UserRegistration //SubClass

//Instance variables memory in Object

ii
String userName,passWord,firstName,lastName;

ath
UserRegistration(String userName,String passWord,String firstName,

String lastName)

aip
{ //Local Variables memory in method

this.userName=userName;
hM
this.passWord=passWord;

this.firstName=firstName;

this.lastName=lastName;
tes

void getUserRegistrationDetails()
a

{
nk

System.out.println("====UserRegistrationDetails====");

System.out.println("UserName:"+userName);
Ve

System.out.println("PassWord:"+passWord);

System.out.println("FirstName:"+firstName);

System.out.println("LastName:"+lastName);

}
}

class DemoCon5 //MainClass

public static void main(String[] args)

Scanner s = new Scanner(System.in);

ii
System.out.println("Enter the UserName:");

ath
String uName = s.nextLine();

System.out.println("Enter the PassWord:");

aip
String pWord = s.nextLine();

System.out.println("Enter the FirstName:");


hM
String fName = s.nextLine();

System.out.println("Enter the LastName:");

String lName = s.nextLine();


tes

UserRegistration ob = new UserRegistration(uName,pWord,fName,lName);


a
nk

ob.getUserRegistrationDetails();

}
Ve

o/p:

Enter the UserName:

nit.v

Enter the PassWord:


mzu672

Enter the FirstName:

Raj

Enter the LastName:

Kumar

====UserRegistrationDetails====

ii
UserName:nit.v

ath
PassWord:mzu672

FirstName:Raj

aip
LastName:Kumar

---------------------------------------------------------------
hM
Execution flow of above program:
a tes
nk
Ve

================================================================

faq:

define "this" keyword?

=>"this" is a pre-defined keyword and which is NonPrimitive datatype variable

holding the reference of Object from where current Constructor or method is


executing.

faq:

In wt situation "this" keyword is used?

=>when we want to load the data from Local variables to Instance variables,and

if we are having same variable names then we use "this" keyword.

ii
==============================================================================

ath
*imp

Loading data to Objects:

aip
=>we can load the data to objects in three ways.
hM
(a)Using Constructor

(b)Using Object reference Variable

(c)Using "Setter methods"


tes

(a)Using Constructor
a

=>We can use Constructor to initialize instance variables while Object creation
nk

process.

Ex:
Ve

above program

-------------------------------------------------------------------

(b)Using Object reference Variable

=>we can also use Object reference Variables to load the data to objects.

Ex : DemoCon6.java
import java.util.Scanner;

class Product //SubClass

int code;

String name;

void getProduct()

ii
{

ath
System.out.println("====ProductDetails====");

System.out.println("ProductCode:"+code);

aip
System.out.println("ProductName:"+name);

}
hM
}

class DemoCon6 //MainClass

{
tes

public static void main(String[] args)

{
a

Scanner s= new Scanner(System.in);


nk

Product ob = new Product();

System.out.println("Enter the ProdCode:");


Ve

ob.code = Integer.parseInt(s.nextLine());

System.out.println("Enter the ProdName:");

ob.name = s.nextLine();

ob.getProduct();
}

o/p:

Enter the ProdCode:

123

Enter the ProdName:

ii
Mouse

ath
====ProductDetails====

ProductCode:123

aip
ProductName:Mouse

-----------------------------------------------------------------------
hM
(c)Using "Setter methods"

=>we can also load the data to objects using "Setter methods" and we display

the data using "Getter methods"


tes

Ex : DemoCon7.java
a

import java.util.Scanner;
nk

class BookDetails //SubClass

{
Ve

int code;

String name,author;

void setCode(int code)

this.code=code;
}

void setName(String name)

this.name=name;

void setAuthor(String author)

ii
{

ath
this.author=author;

aip
int getCode()

{
hM
return code;

String getName()
tes

return name;
a

}
nk

String getAuthor()

{
Ve

return author;

class DemoCon7 //MainClass

{
public static void main(String[] args)

Scanner s = new Scanner(System.in);

BookDetails ob = new BookDetails();

System.out.println("Enter the bCode:");

int bCode = Integer.parseInt(s.nextLine());

ii
ob.setCode(bCode);

ath
System.out.println("Enter the bName:");

String bName = s.nextLine();

aip
ob.setName(bName);

System.out.println("Enter the bAuthor:");


hM
String bAuthor = s.nextLine();

ob.setAuthor(bAuthor);

System.out.println("======BookDetails=====");
tes

System.out.println("Code:"+ob.getCode());

System.out.println("Name:"+ob.getName());
a

System.out.println("Author:"+ob.getAuthor());
nk

}
Ve

o/p:

Enter the bCode:

123

Enter the bName:

C-Lang
Enter the bAuthor:

B-Swamy

======BookDetails=====

Code:123

Name:C-Lang

Author:B-Swamy

ii
=====================================================================

ath
aip
hM
a tes
nk
Ve
Dt : 24/11/2022

faq:

define Setter methods?

=>The methods which are used to set the data to the objects are known as

"Setter methods"

ii
faq:

ath
define Getter methods?

=>The methods which are used to get the data from the objects are known as

aip
"Getter methods".
hM
Coding rule of Setter and Getter methods:

=>Each variable in class must be declared with its own Setter and Getter methods

========================================================================
tes

Assignment:

Construct the program for the following Layout:


a
nk

program-1 : Using Construtor process

Program-2 : Using Object reference variable process


Ve

Program-3 : Using Setter and Getter methods

===================================================================

*imp

Packages in Java:

=>Package is a collection of "Classes and Interfaces".


=>Packages in Java are categorized into two types:

1.Pre-Defined packages(Built-in packages)

2.User defined packages

1.Pre-Defined packages(Built-in packages):

=>The packages which are already defined and available from JavaLib are known as

ii
Pre-Defined packages or Built-in packages.

ath
=>The following are some important Pre-defined packages:

java.lang - Language package(default package)

aip
java.util - Utility package

java.io - Input/Output Streams packages


hM
java.net - Networking package

*imp
tes

2.User defined packages:

=>The packages which are defined by the programmer are known as User defined
a

packages.
nk

=>we use "package" keyword to define user defined packages

syntax:
Ve

package package_name;

==========================================================================

Note:

Download Eclipse IDE from the following:

https://www.eclipse.org/downloads/
select the type : Eclipse IDE for Enterprise Java and Web Developers

IDE => Integrated Development Environment

=====================================================================

*imp

ii
Creating Java Project using IDE Eclipse:

ath
step-1 : Open IDE eclipse,while opening name the WorkSpace and click "Launch"

step-2 : Create Java Project

aip
hM
Click on File->new->Project->Java->select "Java Project" and click "Next"->

name the project and click "finish"


tes

step-3 : Create packages in "src"


a
nk

Right Click on "src"->new->package,name the package and click "finish"


Ve

step-4 : Created classes in packages

Right Click on package->new->Class,name the class and click "finish"

Note:
=>To increase font,Click on Window->Preferences->General->Appearance->

Colors and Fonts->Java->Java Editor Text Font->...

step-5 : Execute the program

Open MainClass->Click "Run"->"Run"

=======================================================================

ii
Diagram:

ath
aip
hM
a tes

ProjectName : Demo_App
nk

packages,
Ve

p1 : EmployeeSalary

p2 : EmpMainClass

EmployeeSalary.java
package p1;
public class EmployeeSalary {
public float calculate(int bSal) {
return bSal+(0.93F*bSal)+(0.63F*bSal);
}
}

EmpMainClass.java

package p2;

ii
import java.util.Scanner;

ath
import p1.EmployeeSalary;

public class EmpMainClass {

aip
public static void main(String[] args) {

Scanner s = new Scanner(System.in);


hM
System.out.println("Enter the bSal:");

int bSal = s.nextInt();

EmployeeSalary es = new EmployeeSalary();


tes

float totSal = es.calculate(bSal);

System.out.println("BSal:"+bSal);
a

System.out.println("TotSal:"+totSal);
nk

s.close();

}
Ve

===========================================================================
Dt : 25/11/2022

ProjectName : Customer_App

packages,

p1 : CustomerDetails,CustContact

p2 : CustMainClass

ii
CustomerDetails.java

ath
package p1;
public class CustomerDetails {
public String custId,custName,custCity;

aip
public String getCustId() {
return custId;
}
hM
public void setCustId(String custId) {
this.custId = custId;
}

public String getCustName() {


return custName;
tes

public void setCustName(String custName) {


this.custName = custName;
a

}
nk

public String getCustCity() {


return custCity;
}
Ve

public void setCustCity(String custCity) {


this.custCity = custCity;
}

CustContact.java
package p1;
public class CustContact {
public String mailId;
public long phoneNo;
public String getMailId() {
return mailId;
}
public void setMailId(String mailId) {
this.mailId = mailId;
}
public long getPhoneNo() {

ii
return phoneNo;
}

ath
public void setPhoneNo(long phoneNo) {
this.phoneNo = phoneNo;
}

CustMainClass.java(MainClass)

aip
hM
package p2;
public class CustMainClass {
public static void main(String[] args) {
java.util.Scanner s = new java.util.Scanner(System.in);
p1.CustomerDetails cd = new p1.CustomerDetails();
p1.CustContact cc = new p1.CustContact();
tes

System.out.println("Enter the CustID:");


cd.setCustId(s.nextLine());
System.out.println("Enter the CustName:");
cd.setCustName(s.nextLine());
a

System.out.println("Enter the CustCity:");


nk

cd.setCustCity(s.nextLine());
System.out.println("Enter the MailID:");
cc.setMailId(s.nextLine());
System.out.println("Enter the PhoneNo:");
Ve

cc.setPhoneNo(s.nextLong());
System.out.println("====Display Cutomer details====");
System.out.println("CustId:"+cd.getCustId());
System.out.println("CustName:"+cd.getCustName());
System.out.println("CustCity:"+cd.getCustCity());
System.out.println("MailId:"+cc.getMailId());
System.out.println("PhoneNo:"+cc.getPhoneNo());
s.close();
}
}

o/p:

Enter the CustID:

A121

Enter the CustName:

ii
Raj

ath
Enter the CustCity:

Hyd

Enter the MailID:

aip
[email protected]

Enter the PhoneNo:


hM
9876541234

====Display Cutomer details====

CustId:A121
tes

CustName:Raj

CustCity:Hyd
a

MailId:[email protected]
nk

PhoneNo:9876541234
Ve

diagram:
ii
ath
aip
==================================================================

Assignment-1 :
hM
ProjectName : Comparable_App

packages,

p1 : GreaterValue,SmallerValue
tes

p2 : ComparableMainClass
a

Assignment-2 :
nk

ProjectName : Arithmetic_App

packages,
Ve

p1 :Addition,Subtraction,Multiplication,Division,ModDivision

p2 :ArithmeticMainClass

=========================================================================

faq:
define Access Modifiers?

=>Access Modifiers will specify the scope and visibility of programming components

within the Project.

=>The following are some important access modifiers:

1.public

2.private

ii
3.protected

ath
4.default

aip
1.public:

=>'public' programming components are accessed within the project.


hM
2.private:

=>'private' programming components are accessed only within the class.


tes

3.protected:
a

=>'protected' programing components are accessed within the package.


nk

Note:

=>'protected programming components can be accessed by the ChildClasses


Ve

declared outside the package.

4.default:

=>The programming components which are declared without any access modifiers

are known as "default"


=>'default' programming components are accessed within the package.

Diagram:

ii
ath
aip
hM
a tes

====================================================================
nk

faq:

define "import" statement?


Ve

=>"import" statement is used to make classes available from one package to

another package.

=>Importing process in Java can be done in three ways:

1.Using "import package_name.Class_name; "

2.Using "import package_name.*; "


3.Using "Fully Qualified names"

1.Using "import package_name.Class_name; "

=>In this importing process we specify the class_name to make it available to

current programming.

=>This importing process is also known as "Explicit Importing process".

ii
Ex:

ath
import java.util.Scanner;

import p1.CustomerDetails;

aip
import p1.CustContact;
hM
2.Using "import package_name.*; "

=>In this importing process all the classes from the package are available to

current running program.


tes

=>This importing process is also known as "Implicit Importing process"

Ex:
a

import java.util.*;
nk

import p1.*;
Ve

3.Using "Fully Qualified names":

=>The process of declaring Classes with package_names part of program code

are known as "Fully Qualified names".

Ex:

java.util.Scanner s = new java.util.Scanner(System.in);


p1.CustomerDetails cd = new p1.CustomerDetails();

p1.CustContact cc = new p1.CustContact();

============================================================================

ii
ath
aip
hM
a tes
nk
Ve
Dt : 26/11/2022(Queries)

this

this()

Constructor

getter methods and Setter methods

return type methods

ii
ath
package p1;

public class CheckNumber {

aip
public boolean verify(int n) {

if(n%2 == 0)
hM
{

return true;

}//end of if
tes

else

{
a

return false;
nk

}
Ve

package p2;

import java.util.Scanner;
import p1.CheckNumber;

public class MainClass {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);

System.out.println("Enter the number:");

int num = s.nextInt();

ii
CheckNumber ob = new CheckNumber();

ath
boolean b = ob.verify(num);

if(b)

aip
{

System.out.println("Even Number....");
hM
}//end of if

else

{
tes

System.out.println("Odd Number...");

}
a

s.close();
nk

}
Ve

-------------------------------------------------------------------------

package p1;
public class BookDetails {
//Instance Variables
public int code;
public String name,author;
//Constructor is used to initialize instance variables
public BookDetails(int code,String name,String author) {
//Local Variables
this.code=code;
this.name=name;
this.author=author;
}

//Getter method is used to display the data


public void getBookDetails() {
System.out.println("====BookDetails====");

ii
System.out.println("Code:"+code);
System.out.println("Name:"+name);

ath
System.out.println("Author:"+author);
}
}

package p2;

aip
hM
import java.util.*;

import p1.BookDetails;

public class MainClass {


tes

public static void main(String[] args) {

//Local Variables of main() method


a

Scanner s = new Scanner(System.in);


nk

System.out.println("Enter the code:");

int code = Integer.parseInt(s.nextLine());


Ve

System.out.println("Enter the name:");

String name = s.nextLine();

System.out.println("Enter the author:");

String author = s.nextLine();


BookDetails ob = new BookDetails(code,name,author);

//passing parameters to Constructor

ob.getBookDetails();//method call

s.close();

ii
ath
}

---------------------------------------------------------------------------------------------------

aip
package maccess;
public class Test {
//Constructor Chaining process using this()
public Test(int x) {
hM
System.out.println("****Test(x)*****");;
System.out.println("The value x:"+x);
}
public Test(int x,int y) {
this(x);
System.out.println("****Test(x,y)*****");
tes

System.out.println("The value y:"+y);


}
}
a
nk

package maccess;
public class MainClass {
Ve

public static void main(String[] args) {


Test ob = new Test(12,13);//Con_call_with_2_para
}
}
---------------------------------------------------------------------------------------------------------------------

package maccess;
public class User {
public String uName;
public long phNo;
public String getuName() {
return uName;
}
public void setuName(String uName) {
this.uName = uName;
}
public long getPhNo() {
return phNo;
}
public void setPhNo(long phNo) {
this.phNo = phNo;

ii
}

ath
}

package maccess;
import java.util.*;

aip
public class MainClass {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
User ob = new User();
hM
System.out.println("Enter the UserName:");
ob.setuName(s.nextLine());
System.out.println("Enter the PhoneNO:");
ob.setPhNo(s.nextLong());
System.out.println("===UserDetails===");
tes

String userName = ob.getuName();


long phoneNo = ob.getPhNo();
System.out.println("UName:"+userName);
System.out.println("PNO:"+phoneNo);
s.close();
a

}
nk

==============================================================================
Ve

Dt : 28/11/2022

faq:

define "static" import?

=>The "import statement" which is declared with "static" keyword is known as

"static import".
syntax:

import static package_name.Class_name.*;

Advantage:

=>Static members of one class can access the static members of another class

directly.

ii
ath
Note:

=>"static import" introduced by Java5(2004) version.

Ex:

aip
hM
Display.java

package test;
public class Display {
public static int a;
public static void dis() {
tes

System.out.println("*****dis()******");
System.out.println("The value a:"+a);
}
}
a
nk

MainClass.java(MainClass)

package maccess;
Ve

import java.util.*;

import static test.Display.*;

public class MainClass {

public static void main(String[] args) {

Scanner s = new Scanner(System.in);


System.out.println("Enter the value of a:");

a = s.nextInt();

dis();//Method call

s.close();

ii
o/p:

ath
Enter the value of a:

123

aip
*****dis()******

The value a:123


hM
==================================================================

faq:

define Encapsulation process?


tes

=>The process of binding all the programming components into a single unit class

is known as "Encapsulation Process"


a
nk

faq:

wt is the diff b/w


Ve

(i)Class in C++

(ii)Class in Java

=>Class in C++ can hold Variables and functions,but cannot hold main()

=>Class in Java can hold Variables,methods and main()


faq:

wt is the diff b/w

(i)functuon

(ii)Member function

(iii)Method

ii
=>The part of program which is executed outof main() program in c-lang,is known

ath
as function.

=>The functions which are declared within the class in c++ lang,are known as

aip
member functions.(Member functions can be declared inside or outside the class)

=>The functions which are declared only inside the class in Java lang are known
hM
as Methods.

Diagram:
a tes
nk
Ve
ii
ath
aip
hM
=======================================================================

*imp
tes

Strings in Java:

=>The sequenced collection of Characters which are represented in double quotes


a

is knwon as string.
nk

Ex:
Ve

"nit","hyd",...

=>The characters in string are organized based on index values.

=>strings in Java are not arrays

=>we use the following pre-defined classes from java.lang package to create

string objects:

1.String class
2.StringBuffer class

3.StringBuilder class

-------------------------------------------------------------------------------

ii
ath
aip
hM
a tes
nk
Ve
Dt : 29/11/2022

faq:

define Iterative Statements?

=>The statements which are used to execute some lines of program repeatedly are

known as Iterative Statements.

=>The following are some important Iterative Statements:

ii
1.while loop

ath
2.do-while loop

3.for loop

1.while loop:

aip
hM
=>In while looping structure the condition is checked first and if the condition

is true then the loop-body is executed,this process is repeated until the condition

is false.
tes

syntax:

while(condition)
a

{
nk

//loop-body

}
Ve

flowchart:
ii
ath
aip
hM
-------------------------------------------------------------------
tes

2.do-while loop:

=>In do-while looping structure the loop-body is executed first and then the
a

condition is checked,this process is repeated until the condition is false.


nk

syntax:

do
Ve

//loop_body

while(condition);
flowchart:

ii
ath
aip
hM
a tes

-----------------------------------------------------------------------
nk

3.for loop:

=>"for-loop" is more simple in representation when compared to while and do-while


Ve

loops,because Initialization,Condition and Incre/Decre declared in the same-line

syntax:

for(Initialization;Condition;Incre/Decre)

{
//Loop_body

flowchart:

ii
ath
aip
hM
tes

========================================================================
a

*imp
nk

1.String class:

=>"java.lang.String" class generate Immutable objects.


Ve

(The Objects once generated cannot be modified are known as Immutable Object)

=>"java.lang.String" class having 15 Constructors by Java17 version.

=>we use the following syntaxes to create "String class" objects:

syntax-1 : Using "String literal process"


String s1 = "hyd";

syntax-2 : Using "new" operator process

String s2 = new String("nit");

Diagram:

ii
ath
aip
hM
a tes
nk

Ex : DemoStrin1.java

package maccess;
Ve

public class DemoString1 {


public static void main(String[] args) {
String s1 = "hyd";//String object created using String
Literal process
System.out.println(s1.toString());
int len = s1.length();
System.out.println("length of s1:"+len);
char ch = s1.charAt(1);//Retrieving character based on
index value
System.out.println("char at index 1 : "+ch);
}
}

o/p:

hyd

length of s1:3

char at index 1 : y

ii
=====================================================================

ath
Ex:

wap to read a String and display the reverse of String?

Ex : DemoString2.java

aip
hM
package maccess;
import java.util.*;
public class DemoString2 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the String:");
tes

String str = s.nextLine();


int len = str.length();
System.out.println("====reverse of String====");
for(int i=len-1;i>=0;i--)
a

{
char ch = str.charAt(i);//6 5 4 3 2 1 0
nk

System.out.print(ch+" ");
}
Ve

s.close();
}
}

o/p:

Enter the String:

program
====reverse of String====

margorp

diagram:

ii
ath
aip
hM
a tes
nk

==================================================================
Ve

Assignment-1:

wap to read a String and display the count of Vowels?

i/p : program

o/p : count = 2
Assignmnet-2

wap to check the given String is palindrome String or not?

Note:

=>The reverse of String is equal to the given String is known as Palindrome

ii
String.

ath
======================================================================

faq:

aip
define toString() method?

=>toString() is a pre-defined method from String classes and which is used to


hM
display the content from the objects.

=>This toString() method is executed automatically when we display object

reference variable.
tes

Method Signature:
a

public java.lang.String toString();


nk

syntax:
Ve

String data = str.toString();

define length() method?

=>length() is also a pre-defined method used to find the length of String.


Method Signature:

public int length();

syntax:

int len = str.length();

ii
define charAt() method?

ath
=>charAt() is also a pre-defined method used to retrieve the character from the

String based on index value.

Method Signature:

aip
hM
public char charAt(int);

syntax:
tes

char ch = str.charAt(index);

==========================================================================
a
nk
Ve

You might also like