0% found this document useful (0 votes)
49 views157 pages

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)
49 views157 pages

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

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

Batch : Full Stack Java

[Link] (langauge)

[Link] (Technology)

[Link](Spring Core,Spring MVC,Spring JDBC,Spring Boot)

i
thi
[Link] Services(Frameworks)

ipa
[Link]

[Link]/CSS/JS

[Link]
Ma
sh
[Link] Basics - Selenium

[Link]
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:


[Link] Programming Components(Java Alphabets)

[Link] Programming Concepts

[Link] Oriented Programming features

[Link] Programming Components(Java Alphabets)

(a)Variables

i
thi
(b)Methods

(c)Blocks

ipa
(d)Constructors

(e)Classes

(f)Interfaces

(g)AbstractClasses
Ma
sh
[Link] 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

[Link] 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

[Link]

[Link]

[Link]

i
thi
Diagram:

ipa
[Link]:

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


Ma
establish communication b/w JavaProgram and Database product.

[Link]:
sh
=>Servlet means "Server program" and which is used to accept the request

from users/Clients through WebBrowser.


ate

[Link]:
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)

[Link]

[Link]

[Link](Construction)
Ma
[Link]
sh
[Link]
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

[Link]
[Link]

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

stages:

[Link]

[Link]

[Link]:

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.

[Link]:
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

[Link] (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:


[Link] Loader SubSystem

[Link] data Area

[Link] 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 => [Link]


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-[Link]\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[])

}
[Link]("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:
[Link]

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

[Link]("a value="+a);

[Link]("b value="+b);
Ma
[Link]("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
[Link] Datatypes

ath
[Link] Datatypes

aip
[Link] 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 : [Link]

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
[Link]("byte value="+b);

[Link]("short value="+s);

[Link]("int value="+i);
tes

[Link]("long value="+l);

[Link]("float value="+f);
a

[Link]("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 : [Link]

class DataTypes2
a

{
nk

public static void main(String[] args)

{
Ve

char ch = 'A';

int code = (int)ch;//TypeCasting

boolean b = true;

[Link]("char value="+ch);

[Link]("ASCII Code of A="+code);


[Link]("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 : [Link]

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

[Link]("Sub-1="+s1);
Ve

[Link]("Sub-2="+s2);

[Link]("Sub-3="+s3);

[Link]("Sub-4="+s4);

[Link]("Sub-5="+s5);

[Link]("Sub-6="+s6);
[Link]("TotMarks=="+totMarks);

[Link]("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 : [Link]

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;

[Link]("BSal="+bSal);

[Link]("HRA="+hra);

[Link]("DA="+da);

[Link]("TotSal="+totSal);

ii
}

ath
}

o/p:

aip
BSal=17453

HRA=16231.29
hM
DA=10995.39

TotSal=44679.68

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

*imp

[Link] 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:

[Link] definition

aip
[Link] creation

[Link] location
hM
[Link] Components

[Link] Types

[Link] Cloning
tes

[Link] Serializable

[Link] Locking
a

[Link] Collection(Grouping objects)


nk

[Link] 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 : [Link]

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();

[Link]("a value="+ob.a);
hM
[Link]("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

[Link]-defined classes

[Link] defined classes

[Link]-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

[Link] 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

[Link] datatype variables

[Link] datatype variables


Ve

[Link] 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.


[Link] 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:

[Link] Variables

[Link] Variables

ii
[Link] 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
[Link] 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:

[Link] methods

[Link] methods(Instance methods)


[Link] 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.

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

[Link] 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 : [Link]
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

[Link]("****static method m1()****");

//[Link]("a value:"+a);//Error
Ve

[Link]("b value:"+b);

void m2()//Instance method memory in Object

[Link]("****Instance method m2()*****");


[Link]("a value:"+a);

[Link]("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
[Link] without parameters

ath
[Link] with parameters

aip
[Link] without parameters:

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

[Link] 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:

[Link] type methods

[Link] type methods


[Link] 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

[Link] 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

[Link] Loader SubSystem

[Link] Data Area


a

[Link] Engine
nk

[Link] Loader SubSystem:


Ve

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

loaders.

[Link] 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

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

[Link] 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

[Link]() - to read byte data

[Link]() - to read short date


Ve

[Link]() - to read int date

[Link]() - to read long data

[Link]() - to read float data

[Link]() - to read double data

[Link]() - to read boolean data


[Link]() - to read String data

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

Scanner s = new Scanner([Link]);

=>"[Link]" in Java represent connecting OS-Buffer to Scanner class object.

=>The following are the syntaxes of methods:

ii
[Link]() - to read byte data

ath
Method Signature : public byte nextByte();

syntax : byte var = [Link]();

[Link]() - to read short date

aip
hM
Method Signature : public short nextShort();

syntax : short var = [Link]();


tes

[Link]() - to read int date

Method Signature : public int nextInt();


a

syntax : int var = [Link]();


nk

[Link]() - to read long data


Ve

Method Signature : public long nextLong();

syntax : long var = [Link]();

[Link]() - to read float data

Method Signature : public float nextFloat();


syntax : float var = [Link]();

[Link]() - to read double data

Method Signature : public double nextDouble();

syntax : double var = [Link]();

ii
[Link]() - to read boolean data

ath
Method Signature : public boolean nextBoolean();

syntax : boolean var = [Link]();

[Link]() - to read String data

aip
hM
Method Signature : public String nextLine();

syntax : String var = [Link]();


tes

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


a

[Link]
nk

import [Link];

class DemoMethods2
Ve

public static void main(String[] args)

Scanner s = new Scanner([Link]);

[Link]("Enter UserName:");
String name = [Link]();//will read String data

[Link]("Enter the MailId:");

String mailId=[Link]();

[Link]("Enter the PhoneNo:");

long phNo=[Link]();

[Link]("====UserDetails====");

ii
[Link]("UserName:"+name);

ath
[Link]("MailId:"+mailId);

[Link]("PhoneNo:"+phNo);

aip
}

}
hM
o/p:

Enter UserName:

raj
tes

Enter the MailId:

raj@[Link]
a

Enter the PhoneNo:


nk

9898981234

====UserDetails====
Ve

UserName:raj

MailId:raj@[Link]

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 : [Link]

import [Link];

ii
class DemoMethods3

ath
{

public static void main(String[] args)

aip
{

Scanner s = new Scanner([Link]);//Scanner object connected to Console


hM
[Link]("Enter the BookCode:");

String code = [Link]();

[Link]("Enter the BookName:");


tes

String name = [Link]();

[Link]("Enter the BookAuthor:");


a

String author = [Link]();


nk

[Link]("Enter the BookPrice:");

float price = [Link]();


Ve

[Link]("Enter the BookQty:");

int qty = [Link]();

[Link]("=====BookDetails=====");

[Link]("BookCode="+code);

[Link]("BookName="+name);
[Link]("BookAuthor="+author);

[Link]("BookPrice="+price);

[Link]("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 : [Link]

import [Link];

class DemoMethods4

ii
{

ath
public static void main(String[] args)

aip
Scanner s = new Scanner([Link]);

[Link]("Enter the AccNo:");


hM
long accNo = [Link]([Link]());

[Link]("Enter the CustName:");

String name = [Link]();


tes

[Link]("Enter the Balance:");

float bal = [Link]([Link]());


a

[Link]("Enter the AccType:");


nk

String accType = [Link]();

[Link]("====CustomerDetails====");
Ve

[Link]("AccNo:"+accNo);

[Link]("CustName:"+name);

[Link]("Balance:"+bal);

[Link]("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 = [Link]([Link]());

short var = [Link]([Link]());

int var = [Link]([Link]());


long var = [Link]([Link]());

float var = [Link]([Link]());

double var = [Link]([Link]());

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:

[Link] Operators

[Link] Operators

[Link] Operators

[Link]/Decrement Operators
[Link] Operators:

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

operations.

Operator Meaning

+ Addition

ii
- Subtraction

ath
* Multiplication

/ Division

aip
% ModDivision
hM
[Link] 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

[Link] 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

[Link]/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

[Link] statements

[Link] statements
a

[Link] statements
nk

[Link] 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

[Link] 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
[Link] 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:

[Link]

[Link]

ii
SubClasses : GreaterValue,SmallerValue

ath
MainClass : DemoMethods5

aip
program : [Link]

import [Link];
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([Link]);

[Link]("Enter the value-1:");

int v1 = [Link]();

[Link]("Enter the value-2:");

int v2 = [Link]();
if(v1>0 && v2>0)

if(v1==v2)

[Link]("Values are equal...");

ii
else

ath
{

[Link]("****Choice*****");

aip
[Link]("[Link]\[Link]");

[Link]("Enter the Choice:");


hM
int choice = [Link]();

switch(choice)

{
tes

case 1:

GreaterValue gv = new GreaterValue();


a

int r1 = [Link](v1,v2);
nk

[Link]("GreaterValue:"+r1);

break;//stop the switch


Ve

case 2:

SmallerValue sv = new SmallerValue();

int r2 = [Link](v1,v2);

[Link]("SmallerValue:"+r2);

break;
default:

[Link]("Invalid Choice...");

}//end of switch

else

ii
{

ath
[Link]("Invalid values...");

aip
}

}
hM
o/p:

Enter the value-1:

12
tes

Enter the value-2:

13
a

****Choice*****
nk

[Link]

[Link]
Ve

Enter the Choice:

SmallerValue:12

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

Execution flow of above program:


ClassFiles:

[Link]

[Link]

[Link](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:

[Link]

aip
[Link]

[Link]
hM
[Link]

[Link]
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:

[Link]

[Link]

ii
[Link]

ath
[Link]

[Link]

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

program : [Link]
tes

import [Link];

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([Link]);

ath
[Link]("Enter the int value1:");

int v1 = [Link]();

aip
[Link]("Enter the int value2:");

int v2 = [Link]();
hM
if(v1>0 && v2>0)

[Link]("****Choice*****");
tes

[Link]("[Link]\[Link]\[Link]\[Link]\[Link]");

[Link]("Enter the Choice:");


a

int choice = [Link]();


nk

switch(choice)

{
Ve

case 1:

Addition ad = new Addition();

int r1 = [Link](v1,v2);

[Link]("Sum:"+r1);

break;
case 2:

Subtraction sb = new Subtraction();

int r2 = [Link](v1,v2);

[Link]("Sub:"+r2);

break;

case 3:

ii
Multiplication ml = new Multiplication();

ath
int r3 = [Link](v1,v2);

[Link]("Mul:"+r3);

aip
break;

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

float r4 = [Link](v1,v2);

[Link]("Div:"+r4);
tes

break;

case 5:
a

ModDivision md = new ModDivision();


nk

int r5 = [Link](v1,v2);

[Link]("ModDiv:"+r5);
Ve

break;

default:

[Link]("Invalid Choice...");

}//end of switch

}
else

[Link]("Invalid values...");

ii
o/p:

ath
Enter the int value1:

12

aip
Enter the int value2:

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

[Link]

[Link]
tes

[Link]

[Link]
a

[Link]
nk

Enter the Choice:

4
Ve

Div:1.7142857

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

wap to read and display Employee details?

[Link] empName
[Link] empDesg

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

[Link] the desg is verified successfully,then read empId

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

[Link] the empId is validated,then read bSal

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

ii
[Link] the bSal is validated,then read hra and da

ath
=>The hra and da must greater than zero

[Link] all are validated successfully then calculate totSal.

Program : [Link]

aip
hM
import [Link];

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([Link]);

[Link]("Enter the EmpName:");


tes

String empName = [Link]();

[Link]("Enter the empDesg:");


a

String empDesg = [Link]().toUpperCase();


nk

CheckDesignation cd = new CheckDesignation();

boolean k = [Link](empDesg);
Ve

if(k)

[Link]("Enter the empId:");

String empId = [Link]();

int len = [Link]();


if(len==4)

[Link]("Enter the bSal:");

int bSal = [Link]();

if(bSal>=12000)

ii
[Link]("Enter the HRA:");

ath
float h= [Link]();

float hra = (h*bSal)/100;

aip
[Link]("Enter the DA:");

float d = [Link]();
hM
float da = (d*bSal)/100;

if(hra>0 && da>0)

{
tes

EmpTotalSalary ob = new EmpTotalSalary();

float totSal = [Link](bSal,hra,da);


a

[Link]("EmpName:"+empName);
nk

[Link]("EmpDesg:"+empDesg);

[Link]("EmpId:"+empId);
Ve

[Link]("BSal:"+bSal);

[Link]("TotSal:"+totSal);

}//end of if

else

{
[Link]("Imvalid hra and da..");

}//end of if

else

[Link]("Invalid bSal...");

ii
}

ath
}//end of if

aip
else

{
hM
[Link]("Invalid empId...");

}
tes

}//end of if

else
a

{
nk

[Link]("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?

[Link] stuName

[Link] stuBranch

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

ath
[Link] the branch is verified Successfully,then read stuRollNo

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

aip
[Link] 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:

[Link]
[Link]

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:

[Link] blocks

[Link] blocks(Instance blocks)

ii
ath
[Link] 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 : [Link]
class DemoBlock1 //MainClass

static int k=200;

public static void main(String[] args)

[Link]("****main()*****");

ii
[Link]("The value k:"+k);

ath
}

static

aip
{

[Link]("****static block****");
hM
[Link]("The value k:"+k);

}
tes

o/p:

****static block****
a

The value k:200


nk

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

The value k:200


Ve

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

Ex : [Link]

class Test //SubClass

static int z;
static

[Link]("****Static block****");

[Link]("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 = [Link]();
a

[Link]("*****main()******");
nk

[Link]("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:([Link])

ii
thi
ipa
Ma
Execution flow of above program([Link])
sh
ate
nk
Ve

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

[Link] 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 : [Link]

class BTest //SubClass


ate

int a = 10;
nk

static int b = 20;


Ve

a++;

b++;

[Link]("====Instance block====");

[Link]("The value a:"+a);


[Link]("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
[Link] without parameters

[Link] with parametes


hM
[Link] without parameters:

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

Constructors or Constructors without parameters.


a

Ex-program : [Link]
nk

class CTest1 //SubClass

{
Ve

int k=12;

CTest1()

[Link]("====CTest()====");

[Link]("The value k:"+k);


}

void dis()

[Link]("====dis()====");

[Link]("The value k:"+k);

ii
}

ath
class DemoCon1 //MainClass

aip
public static void main(String[] args)

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

[Link]();//Method_call

[Link]();
tes

[Link]();

}
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 : [Link]
Ve

class CTest2 //SubClass

CTest2()

{
[Link]("****CTest2()****");

return;

[Link]("****Instance block****");

ii
}

ath
static

aip
{

[Link]("****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()****
=================================================================

[Link] 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 : [Link]

ath
import [Link];

class CTest3 //SubClass

aip
{

CTest3(int x,int y,int z)


hM
{

[Link]("====CTest3(x,y,z)====");

[Link]("x:"+x);
tes

[Link]("y:"+y);

[Link]("z:"+z);
a

}
nk

CTest3(int x,int y)

{
Ve

[Link]("====CTest3(x,y)====");

[Link]("x:"+x);

[Link]("y:"+y);

CTest3(int x)
{

[Link]("====CTest3(x)====");

class DemoCon3 //MainClass

ii
public static void main(String[] args)

ath
{

Scanner s = new Scanner([Link]);

aip
[Link]("Enter the value of x:");

int x = [Link]();
hM
[Link]("Enter the value of y:");

int y = [Link]();

[Link]("Enter the value of z:");


tes

int z = [Link]();

[Link]("====Choice=====");
a

[Link]("1.CTest3(x,y,z)\n2.CTest3(x,y)\n3.CTest3(x)");
nk

[Link]("Enter the Choice:");

int choice = [Link]();


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
[Link]("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 : [Link]

import [Link];

ii
class CTest4 //SubClass

ath
{

CTest4(int x,int y,int z)

aip
{

this(x,y);//Con_2_para
hM
[Link]("====CTest3(x,y,z)====");

[Link]("x:"+x);

[Link]("y:"+y);
tes

[Link]("z:"+z);

}
a

CTest4(int x,int y)
nk

this(x);//Con_1_para
Ve

[Link]("====CTest3(x,y)====");

[Link]("x:"+x);

[Link]("y:"+y);

CTest4(int x)
{

[Link]("====CTest3(x)====");

[Link]("x:"+x);

class DemoCon4 //MainClass

ii
{

ath
public static void main(String[] args)

aip
Scanner s = new Scanner([Link]);

[Link]("Enter the value of x:");


hM
int x = [Link]();

[Link]("Enter the value of y:");

int y = [Link]();
tes

[Link]("Enter the value of z:");

int z = [Link]();
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 : [Link]

import [Link];

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

[Link]=userName;
hM
[Link]=passWord;

[Link]=firstName;

[Link]=lastName;
tes

void getUserRegistrationDetails()
a

{
nk

[Link]("====UserRegistrationDetails====");

[Link]("UserName:"+userName);
Ve

[Link]("PassWord:"+passWord);

[Link]("FirstName:"+firstName);

[Link]("LastName:"+lastName);

}
}

class DemoCon5 //MainClass

public static void main(String[] args)

Scanner s = new Scanner([Link]);

ii
[Link]("Enter the UserName:");

ath
String uName = [Link]();

[Link]("Enter the PassWord:");

aip
String pWord = [Link]();

[Link]("Enter the FirstName:");


hM
String fName = [Link]();

[Link]("Enter the LastName:");

String lName = [Link]();


tes

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


a
nk

[Link]();

}
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 : [Link]
import [Link];

class Product //SubClass

int code;

String name;

void getProduct()

ii
{

ath
[Link]("====ProductDetails====");

[Link]("ProductCode:"+code);

aip
[Link]("ProductName:"+name);

}
hM
}

class DemoCon6 //MainClass

{
tes

public static void main(String[] args)

{
a

Scanner s= new Scanner([Link]);


nk

Product ob = new Product();

[Link]("Enter the ProdCode:");


Ve

[Link] = [Link]([Link]());

[Link]("Enter the ProdName:");

[Link] = [Link]();

[Link]();
}

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 : [Link]
a

import [Link];
nk

class BookDetails //SubClass

{
Ve

int code;

String name,author;

void setCode(int code)

[Link]=code;
}

void setName(String name)

[Link]=name;

void setAuthor(String author)

ii
{

ath
[Link]=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([Link]);

BookDetails ob = new BookDetails();

[Link]("Enter the bCode:");

int bCode = [Link]([Link]());

ii
[Link](bCode);

ath
[Link]("Enter the bName:");

String bName = [Link]();

aip
[Link](bName);

[Link]("Enter the bAuthor:");


hM
String bAuthor = [Link]();

[Link](bAuthor);

[Link]("======BookDetails=====");
tes

[Link]("Code:"+[Link]());

[Link]("Name:"+[Link]());
a

[Link]("Author:"+[Link]());
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:

[Link]-Defined packages(Built-in packages)

[Link] defined packages

[Link]-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:

[Link] - Language package(default package)

aip
[Link] - Utility package

[Link] - Input/Output Streams packages


hM
[Link] - Networking package

*imp
tes

[Link] 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:

[Link]
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

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

[Link]

package p2;

ii
import [Link];

ath
import [Link];

public class EmpMainClass {

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

Scanner s = new Scanner([Link]);


hM
[Link]("Enter the bSal:");

int bSal = [Link]();

EmployeeSalary es = new EmployeeSalary();


tes

float totSal = [Link](bSal);

[Link]("BSal:"+bSal);
a

[Link]("TotSal:"+totSal);
nk

[Link]();

}
Ve

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

ProjectName : Customer_App

packages,

p1 : CustomerDetails,CustContact

p2 : CustMainClass

ii
[Link]

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

aip
public String getCustId() {
return custId;
}
hM
public void setCustId(String custId) {
[Link] = custId;
}

public String getCustName() {


return custName;
tes

public void setCustName(String custName) {


[Link] = custName;
a

}
nk

public String getCustCity() {


return custCity;
}
Ve

public void setCustCity(String custCity) {


[Link] = custCity;
}

[Link]
package p1;
public class CustContact {
public String mailId;
public long phoneNo;
public String getMailId() {
return mailId;
}
public void setMailId(String mailId) {
[Link] = mailId;
}
public long getPhoneNo() {

ii
return phoneNo;
}

ath
public void setPhoneNo(long phoneNo) {
[Link] = phoneNo;
}

[Link](MainClass)

aip
hM
package p2;
public class CustMainClass {
public static void main(String[] args) {
[Link] s = new [Link]([Link]);
[Link] cd = new [Link]();
[Link] cc = new [Link]();
tes

[Link]("Enter the CustID:");


[Link]([Link]());
[Link]("Enter the CustName:");
[Link]([Link]());
a

[Link]("Enter the CustCity:");


nk

[Link]([Link]());
[Link]("Enter the MailID:");
[Link]([Link]());
[Link]("Enter the PhoneNo:");
Ve

[Link]([Link]());
[Link]("====Display Cutomer details====");
[Link]("CustId:"+[Link]());
[Link]("CustName:"+[Link]());
[Link]("CustCity:"+[Link]());
[Link]("MailId:"+[Link]());
[Link]("PhoneNo:"+[Link]());
[Link]();
}
}

o/p:

Enter the CustID:

A121

Enter the CustName:

ii
Raj

ath
Enter the CustCity:

Hyd

Enter the MailID:

aip
raj@[Link]

Enter the PhoneNo:


hM
9876541234

====Display Cutomer details====

CustId:A121
tes

CustName:Raj

CustCity:Hyd
a

MailId:raj@[Link]
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:

[Link]

[Link]

ii
[Link]

ath
[Link]

aip
[Link]:

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


hM
[Link]:

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


tes

[Link]:
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.

[Link]:

=>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:

[Link] "import package_name.Class_name; "

[Link] "import package_name.*; "


[Link] "Fully Qualified names"

[Link] "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 [Link];

import [Link];

aip
import [Link];
hM
[Link] "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 [Link].*;
nk

import p1.*;
Ve

[Link] "Fully Qualified names":

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

are known as "Fully Qualified names".

Ex:

[Link] s = new [Link]([Link]);


[Link] cd = new [Link]();

[Link] cc = new [Link]();

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

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 [Link];
import [Link];

public class MainClass {

public static void main(String[] args) {

Scanner s = new Scanner([Link]);

[Link]("Enter the number:");

int num = [Link]();

ii
CheckNumber ob = new CheckNumber();

ath
boolean b = [Link](num);

if(b)

aip
{

[Link]("Even Number....");
hM
}//end of if

else

{
tes

[Link]("Odd Number...");

}
a

[Link]();
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
[Link]=code;
[Link]=name;
[Link]=author;
}

//Getter method is used to display the data


public void getBookDetails() {
[Link]("====BookDetails====");

ii
[Link]("Code:"+code);
[Link]("Name:"+name);

ath
[Link]("Author:"+author);
}
}

package p2;

aip
hM
import [Link].*;

import [Link];

public class MainClass {


tes

public static void main(String[] args) {

//Local Variables of main() method


a

Scanner s = new Scanner([Link]);


nk

[Link]("Enter the code:");

int code = [Link]([Link]());


Ve

[Link]("Enter the name:");

String name = [Link]();

[Link]("Enter the author:");

String author = [Link]();


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

//passing parameters to Constructor

[Link]();//method call

[Link]();

ii
ath
}

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

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

[Link]("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) {
[Link] = uName;
}
public long getPhNo() {
return phNo;
}
public void setPhNo(long phNo) {
[Link] = phNo;

ii
}

ath
}

package maccess;
import [Link].*;

aip
public class MainClass {
public static void main(String[] args) {
Scanner s = new Scanner([Link]);
User ob = new User();
hM
[Link]("Enter the UserName:");
[Link]([Link]());
[Link]("Enter the PhoneNO:");
[Link]([Link]());
[Link]("===UserDetails===");
tes

String userName = [Link]();


long phoneNo = [Link]();
[Link]("UName:"+userName);
[Link]("PNO:"+phoneNo);
[Link]();
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
[Link]

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

[Link]("*****dis()******");
[Link]("The value a:"+a);
}
}
a
nk

[Link](MainClass)

package maccess;
Ve

import [Link].*;

import static [Link].*;

public class MainClass {

public static void main(String[] args) {

Scanner s = new Scanner([Link]);


[Link]("Enter the value of a:");

a = [Link]();

dis();//Method call

[Link]();

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 [Link] package to create

string objects:

[Link] class
[Link] class

[Link] 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
[Link] loop

ath
[Link]-while loop

[Link] loop

[Link] 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

[Link]-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

[Link] 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

[Link] class:

=>"[Link]" class generate Immutable objects.


Ve

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

=>"[Link]" 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 : [Link]

package maccess;
Ve

public class DemoString1 {


public static void main(String[] args) {
String s1 = "hyd";//String object created using String
Literal process
[Link]([Link]());
int len = [Link]();
[Link]("length of s1:"+len);
char ch = [Link](1);//Retrieving character based on
index value
[Link]("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 : [Link]

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

String str = [Link]();


int len = [Link]();
[Link]("====reverse of String====");
for(int i=len-1;i>=0;i--)
a

{
char ch = [Link](i);//6 5 4 3 2 1 0
nk

[Link](ch+" ");
}
Ve

[Link]();
}
}

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 [Link] toString();


nk

syntax:
Ve

String data = [Link]();

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 = [Link]();

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 = [Link](index);

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

You might also like