Java Intro - Merged
Java Intro - Merged
[Link] (langauge)
[Link] (Technology)
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
NASSCOM
Project
=============================================================
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
Construction rules.
nk
----------------------------------------------------------------
Java language:
Ve
part-1 : CoreJava(LKG)
part-2 : AdvJava(UKG)
part-1 : CoreJava:
(a)Variables
i
thi
(b)Methods
(c)Blocks
ipa
(d)Constructors
(e)Classes
(f)Interfaces
(g)AbstractClasses
Ma
sh
[Link] Programming Concepts:
(c)Multi-Threading process
nk
(f)Networking in Java
(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:
Note:
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]:
[Link]:
sh
=>Servlet means "Server program" and which is used to accept the request
[Link]:
nk
=>JSP stands for "Java Server Page" and which is response from Web
Application
Ve
faq:
Dt : 28/10/2022(Day-3)
Ma
Conclusion:
==============================================================
faq:
(i)Language
Ve
(ii)Technology
(iii)Framework
(i)Language:
rules.
Ex:
CoreJava
(ii)Technology:
i
thi
Ex:
AdvJava
ipa
(iii)Framework:
Ma
=>The Structure which is ready constructed and available for
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:
============================================================
Ve
Note:
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
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
=>In Java Language the Byte code is executed on JVM(Java Virtual Machine)
nk
Diagram:
Ve
i
thi
ipa
===============================================================
faq:
(i)Objective Code
Ma
(ii)Byte Code
sh
(i)Objective Code:
ate
Objective code.
nk
Dis-Advantage:
=>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
ipa
Advantage:
Ma
=>The ByteCode generated from one PlatForm can be executed on other
language
nk
Diagram:
Ve
i
thi
ipa
Ma
==============================================================
sh
ate
nk
Ve
Dt : 2/11/2022
faq:
=>The language formats which are understandable by the user are known as
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
Low Level Language formats and Low Level Language formats into High
Ve
Level Formats.
Dt : 3/11/2022
OAK language
"Java"..
1995
Java Versions:
ii
1998 - JDK 1.2
ath
2000 - JDK 1.3
aip
--------------------------------------
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
=========================================================
Java8
Java11
Java17
=======================================================
faq:
(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
(ii)JVM:
=>JVM Stands for "Java Virtual Machine" and which is used to execute
Java ByteCode.
[Link] Engine
ii
(iii)Java Library:
ath
=>Java Library will provide pre-defined ready constructed components
aip
=>we use "java" word to represent JavaLibrary.
Diagram:
a
nk
Ve
ii
ath
aip
hM
---------------------------------------------------------
(b)JRE:
tes
(C)JVM:
Ve
*imp
tes
Note:
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
define "class"?
i
thi
=>class is a collection of Variables,Methods and main()
ipa
Methods - are the actions
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:
i
thi
class Display
ipa
public static void main(String args[])
}
[Link]("Welcome to Java");
Ma
}
sh
============================================================
ate
D:\Demo141
nk
syntax:
Class_name.java
Ex:
[Link]
Note:
i
thi
=>Open CommandPrompt and perform "Compilation and Execution process"
ipa
press enter.
syntax:
Ma
javac Class_name.java
sh
Ex:
javac [Link]
ate
syntax:
java Class_name
Ve
Ex:
java Display
================================================================
Commands:
==============================================================
i
thi
ipa
Ma
sh
ate
nk
Ve
Dt : 5/11/2022
EX-program:
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:
faq:
(i)print()
(ii)println()
i
thi
(i)print():
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
int basicSalary;
float hra,da,totalSalary;
totSalary = basicSalary+hra+da;
da = 63% of basicSalary;
========================================================
i
thi
ipa
Ma
sh
ate
nk
Ve
Dt : 7/11/2022
Note:
==================================================================
ii
*imp
ath
Naming Conventions in Java:
aip
are known as Naming Conventions in Java.
hM
packages:
must be UpperCase.
Ve
Ex:
Employee
StudentResult
InputStreamReader
Variables and Methods :
rule : In Variables and Methods the first word in LowerCase and from
Ex : Methods
readLine()
ii
getSalary()
ath
Ex : Variables
aip
rollNumber
panCardNumber
hM
Keywords :
Ex:
a
static
nk
void
class
Ve
===================================================================
faq:
define Identifiers?
*imp
DataTypes in Java:
ii
[Link] Datatypes
ath
[Link] Datatypes
aip
[Link] Datatypes:
(a)Integer datatypes
(b)Float datatypes
tes
(c)Character datatype
(d)Boolean datatype
a
nk
(a)Integer datatypes:
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)
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:
Float datatypes.
tes
=>Types:
float - 4 bytes
a
double - 8 bytes
nk
Note:
values.
=>In the process of assigning float value we must use "F" or "f" in the
RHS of declaration.
Ex-program : [Link]
class DataTypes
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:
Ex:
'k','j','n',...
ii
=>Types:
ath
char - 2 bytes
aip
faq:
aip
=>The datatype which is represented in the form of true or false
boolean - 1 bit
tes
program : [Link]
class DataTypes2
a
{
nk
{
Ve
char ch = 'A';
boolean b = true;
[Link]("char value="+ch);
o/p:
char value=A
ii
boolean value=true
ath
=====================================================
faq:
aip
define TypeCasting process?
(a)Widening process
tes
(b)Narrowing process
a
nk
(a)Widening process:
char->byte->short->int->long->float->double
(b)Narrowing process:
double->float->long->int->short->byte->char
ii
====================================================================
ath
Assignment1:(Solution)
Program : [Link]
aip
hM
class StudentResult
int s1=90,s2=78,s3=77,s4=63,s5=93,s6=99;
a
[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)
program : [Link]
class EmployeeSalary
Ve
[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
or Referential datatypes.
(a)Class
(b)Interface
(c)Array
(d)Enum
============================================================
*imp
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] Sorting
==============================================================
Ve
Dt : 9/11/2022
*imp
define "object"?
ii
ath
Class_name obj_name = new Class_name();
===================================================================
aip
*imp
=>This "static" keyword will decide the memory location of programming components.
=>Based on "static" keyword programming components are categorized into two types:
tes
=>The programming components which are declared with "static" keyword are known
Ve
as "static programming components" and will get the memory within the class.
=>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
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
[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
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:
=>The variables which are declared with primitive datatypes like byte,short,
=>The variables which are declared with NonPrimitive datatypes like Class,
datatype variables
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"
aip
=>These static variables will get the memory within the class while class
=>The variables which are declared without "static" keyword are known as
tes
NonStatic variables
(a)Instance Variables
nk
(b)Local Variables
Ve
(a)Instance Variables:
=>The NonStatic variables which are declared outside the methods are known
=>These Instance variables will get the memory within the object while
=>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:
aip
=>There is no concept of static local variables in java,which means we cannot
========================================================================
nk
*imp
Methods in Java:
Ve
[Link] methods
=>The methods which are declared with "static" keyword are known as static
=>These static methods will get the memory within the class while class
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
--------------------------------------------------------------
a
=>The static methods which are already defined and available from JavaLib
=>The static methods which are defined by the user(programmer) are known
=====================================================================
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:
variables.
------------------------------------------------------------
=>The Instance methods which are defined and available from JavaLib are
ii
(ii)User defined Instance methods:
ath
=>The Instance methods which are defined by the User(Programmer) are known
aip
======================================================================
Ex-program : [Link]
hM
class DemoMethods1
{
nk
//[Link]("a value:"+a);//Error
Ve
[Link]("b value:"+b);
[Link]("b value:"+b);
DemoMethods1.m1();//method_call
ii
DemoMethods1 ob = new DemoMethods1();
ath
ob.m2();//method_call
aip
}
o/p:
hM
****static method m1()****
b value:20
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
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.
=>The methods which are declared with parameters are known as Parameterized
====================================================================
nk
faq:
define return_type?
Ve
=>The methods which will not return the value after method execution are known
=>The methods which are declared with "void" are known as NonReturn 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
[Link] Engine
nk
=>Class Loader SubSystem will load the class-file on to Runtime Data Area using
loaders.
=>This Runtime Data Area internally divided into the following partitions:
(a)Method Area
(b)Heap 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
=>The memory block where the objects are created is known as Heap Area.
tes
=>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:
=>The partition of Java Stack Area where the method is copied for execution is
automatically
ii
ath
aip
hM
tes
=============================================================================
a
nk
Ve
Dt : 12/11/2022
faq:
(i)Object
(ii)Object reference
ii
(i)Object:
ath
=>The memory generated to hold Instance members of class is known as Object.
(ii)Object reference:
aip
=>The address location where the object is created is known as Object reference.
Diagram:
a
nk
Ve
================================================================
=>Every method which is executing in Java Stack Area will have its own
ii
=>All these Program Counter Registers are opened in a separete memory block
ath
known as PC-Register 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
=>These Native methods are executed using JNI(Java Native method Interface)
a
======================================================================
[Link] Engine:
Ve
(a)Interpreter
(b)JIT(Just-In-Time) Compiler
(a)Interpreter:
instructions.
ii
ath
(b)JIT Compiler:
========================================================================
aip
faq:
in the middle of execution process and which is preferable for Server application
development.
tes
===========================================================================
Note:
a
===========================================================================
Ve
Ve
nk
ates
hM
aip
ath
ii
Dt : 14/11/2022
*imp
"Scanner" class:
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
=>we use the following syntax to create object for "Scanner" class:
ii
[Link]() - to read byte data
ath
Method Signature : public byte nextByte();
aip
hM
Method Signature : public short nextShort();
ii
[Link]() - to read boolean data
ath
Method Signature : public boolean nextBoolean();
aip
hM
Method Signature : public String nextLine();
[Link]
nk
import [Link];
class DemoMethods2
Ve
[Link]("Enter UserName:");
String name = [Link]();//will read String data
String mailId=[Link]();
long phNo=[Link]();
[Link]("====UserDetails====");
ii
[Link]("UserName:"+name);
ath
[Link]("MailId:"+mailId);
[Link]("PhoneNo:"+phNo);
aip
}
}
hM
o/p:
Enter UserName:
raj
tes
raj@[Link]
a
9898981234
====UserDetails====
Ve
UserName:raj
MailId:raj@[Link]
PhoneNo:9898981234
Diagram:
ii
ath
aip
hM
tes
=====================================================================
Assignment-1:
a
nk
Assignment-2:
==========================================================================
Dt : 15/11/2022
Assignment-1:(Solution)
Program : [Link]
import [Link];
ii
class DemoMethods3
ath
{
aip
{
[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
234.56
12
nk
=====BookDetails=====
BookCode=CS121
Ve
BookName=C-Lang
BookAuthor=B-Swamy
BookPrice=234.56
BookQty=12
==============================================================
Assignment-2:
Program : [Link]
import [Link];
class DemoMethods4
ii
{
ath
public static void main(String[] args)
aip
Scanner s = new Scanner([Link]);
[Link]("====CustomerDetails====");
Ve
[Link]("AccNo:"+accNo);
[Link]("CustName:"+name);
[Link]("Balance:"+bal);
[Link]("AccType:"+accType);
}
}
o/p:
6123456
Raj Kumar
ii
Enter the Balance:
ath
12000
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
information.
ii
ath
aip
hM
tes
=========================================================================
a
*imp
nk
Operators in Java:
Ve
=>Operators are the special symbols which are used to perform operations.
[Link] Operators
[Link] Operators
[Link] Operators
[Link]/Decrement Operators
[Link] Operators:
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
== Is Equal to
!= Not Equal to
[Link] Operators:
=>Logical Operators are used to compare two comparisions and generate boolean
result.
Operator Meaning
|| 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
Operator Meaning
ii
++ Increment
ath
-- Decrement
=========================================================================
aip
*imp
[Link] statements
[Link] statements
a
[Link] statements
nk
[Link] statements:
Ve
=>The statements which are used to select part of program for execution based
=>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
statements
a
=>Types:
nk
(a)break
(b)continue
Ve
(c)return
(d)exit
Note:
=================================================================
Note:
=>In the process of constructing Java Applications we must use one MainClass
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,
===========================================================
Assignment2:
a
Condition:
Ve
=>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
if(x>y)
a
{
nk
return x;
}
Ve
else
return y;
}
}
if(x<y)
ii
{
ath
return x;
aip
else
{
hM
return y;
}
tes
{
nk
{
Ve
int v1 = [Link]();
int v2 = [Link]();
if(v1>0 && v2>0)
if(v1==v2)
ii
else
ath
{
[Link]("****Choice*****");
aip
[Link]("[Link]\[Link]");
switch(choice)
{
tes
case 1:
int r1 = [Link](v1,v2);
nk
[Link]("GreaterValue:"+r1);
case 2:
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:
12
tes
13
a
****Choice*****
nk
[Link]
[Link]
Ve
SmallerValue:12
-----------------------------------------------------------------
[Link]
[Link]
[Link](MainClass)
ii
ath
aip
hM
a tes
nk
=======================================================================
parameters : v1,v2,x,y
Actual parameters : v1,v2
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:
=>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];
{
nk
{
Ve
return x+y;
{
int sub(int x,int y)
return x-y;
ii
{
ath
int mul(int x,int y)
aip
return x*y;
}
hM
}
{
tes
{
a
return (float)x/y;
nk
}
Ve
return x%y;
}
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]");
switch(choice)
{
Ve
case 1:
int r1 = [Link](v1,v2);
[Link]("Sum:"+r1);
break;
case 2:
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
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
4
Ve
Div:1.7142857
==============================================================
[Link] empName
[Link] empDesg
ii
[Link] the bSal is validated,then read hra and da
ath
=>The hra and da must greater than zero
Program : [Link]
aip
hM
import [Link];
{
tes
{
a
return switch(empDesg)
nk
default:yield false;
};
}
}
return bSal+hra+da;
ii
}
ath
}
aip
{
boolean k = [Link](empDesg);
Ve
if(k)
if(bSal>=12000)
ii
[Link]("Enter the HRA:");
ath
float h= [Link]();
aip
[Link]("Enter the DA:");
float d = [Link]();
hM
float da = (d*bSal)/100;
{
tes
[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:
SE
A121
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:
[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
aip
[Link] rollNo validated Successfully,then read six subject marks.
per
result
tes
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:
ii
=========================================================================
ath
define return_type switch?
aip
the result.
hM
syntax:
return switch(value)
{
tes
...
nk
};
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
[Link] 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
=>static block is executed only once with highest priority when the class is
Ve
=>static block can access static variables directly,but cannot access instance
variables directly.
Ex : [Link]
class DemoBlock1 //MainClass
[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
****main()*****
-------------------------------------------------------------------------
Ex : [Link]
static int z;
static
[Link]("****Static block****");
ii
{
ath
return z;
aip
}
{
tes
Test.z = 200;
int p = [Link]();
a
[Link]("*****main()******");
nk
}
Ve
o/p:
****Static block****
*****main()******
The value z:200
===========================================================
ii
ath
aip
hM
a tes
nk
Ve
Dt : 19/11/2022
ii
thi
ipa
Ma
Execution flow of above program([Link])
sh
ate
nk
Ve
============================================================
=>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.
int a = 10;
nk
a++;
b++;
[Link]("====Instance block====");
class DemoBlock3
ii
{
thi
BTest ob1 = new BTest();//Object
ipa
}
o/p:
Ma
====Instance block====
sh
The value a:11
====Instance block====
--------------------------------------------------------------
Ve
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:
aip
(i)Block
(ii)Method
hM
=>Blocks are executed automatically without calling,but methods are executed on
MethodCall.
tes
=>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
structure of Constructor:
Class_name(para_list)
//method_body
ii
}
ath
-----------------------------------------------------------------
aip
[Link] without parameters
=>The Constructors which are declared without parameters are known as 0-parameter
tes
Ex-program : [Link]
nk
{
Ve
int k=12;
CTest1()
[Link]("====CTest()====");
void dis()
[Link]("====dis()====");
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
====dis()====
---------------------------------------------------------
faq:
hM
wt is the diff b/w
(i)Constructor
(ii)Instance method
tes
=====================================================================
Dt : 22/11/2022
faq:
ii
faq:
ath
In wt situation default constructor is added?
aip
then default constructor is added.
hM
faq:
(i)Instance block
tes
(ii)Constructor
=>Both components are executed while object creation process,but Instance block
a
faq:
Ve
(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:
ii
method.
ath
faq:
aip
Can we declare "return" statement in Constructor?
faq:
tes
Ex : [Link]
Ve
CTest2()
{
[Link]("****CTest2()****");
return;
[Link]("****Instance block****");
ii
}
ath
static
aip
{
[Link]("****Static block****");
hM
}
{
nk
}
Ve
o/p:
****Static block****
****Instance block****
****CTest2()****
=================================================================
=>The Constructors which are declared with parameters are known as Parameterized
ii
Ex-program : [Link]
ath
import [Link];
aip
{
[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)====");
ii
public static void main(String[] args)
ath
{
aip
[Link]("Enter the value of x:");
int x = [Link]();
hM
[Link]("Enter the value of y:");
int y = [Link]();
int z = [Link]();
[Link]("====Choice=====");
a
[Link]("1.CTest3(x,y,z)\n2.CTest3(x,y)\n3.CTest3(x)");
nk
switch(choice)
case 1:
break;
case 2:
break;
case 3:
break;
ii
default:
ath
[Link]("Invalid Choice....");
}//end of switch
aip
}
}
hM
o/p:
11
tes
12
a
13
====Choice=====
Ve
1.CTest3(x,y,z)
2.CTest3(x,y)
3.CTest3(x)
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
Note:
aip
hM
=>when we want to execute multiple Constructors then we have to create multiple
Objects.
======================================================================
tes
faq:
faq:
=>The process of calling one constructor from another constructor using "this()"
=>"this()" is a Pre-defined format to call constructors from the same class and
-----------------------------------------------------------------
Ex : [Link]
import [Link];
ii
class CTest4 //SubClass
ath
{
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);
ii
{
ath
public static void main(String[] args)
aip
Scanner s = new Scanner([Link]);
int y = [Link]();
tes
int z = [Link]();
a
}
Ve
o/p:
11
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
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];
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);
}
}
ii
[Link]("Enter the UserName:");
ath
String uName = [Link]();
aip
String pWord = [Link]();
[Link]();
}
Ve
o/p:
nit.v
Raj
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:
faq:
=>when we want to load the data from Local variables to Instance variables,and
ii
==============================================================================
ath
*imp
aip
=>we can load the data to objects in three ways.
hM
(a)Using Constructor
(a)Using Constructor
a
=>We can use Constructor to initialize instance variables while Object creation
nk
process.
Ex:
Ve
above program
-------------------------------------------------------------------
=>we can also use Object reference Variables to load the data to objects.
Ex : [Link]
import [Link];
int code;
String name;
void getProduct()
ii
{
ath
[Link]("====ProductDetails====");
[Link]("ProductCode:"+code);
aip
[Link]("ProductName:"+name);
}
hM
}
{
tes
{
a
[Link] = [Link]([Link]());
[Link] = [Link]();
[Link]();
}
o/p:
123
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
Ex : [Link]
a
import [Link];
nk
{
Ve
int code;
String name,author;
[Link]=code;
}
[Link]=name;
ii
{
ath
[Link]=author;
aip
int getCode()
{
hM
return code;
String getName()
tes
return name;
a
}
nk
String getAuthor()
{
Ve
return author;
{
public static void main(String[] args)
ii
[Link](bCode);
ath
[Link]("Enter the bName:");
aip
[Link](bName);
[Link](bAuthor);
[Link]("======BookDetails=====");
tes
[Link]("Code:"+[Link]());
[Link]("Name:"+[Link]());
a
[Link]("Author:"+[Link]());
nk
}
Ve
o/p:
123
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:
=>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:
===================================================================
*imp
Packages in Java:
=>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:
aip
[Link] - Utility package
*imp
tes
=>The packages which are defined by the programmer are known as User defined
a
packages.
nk
syntax:
Ve
package package_name;
==========================================================================
Note:
[Link]
select the type : Eclipse IDE for Enterprise Java and Web Developers
=====================================================================
*imp
ii
Creating Java Project using IDE Eclipse:
ath
step-1 : Open IDE eclipse,while opening name the WorkSpace and click "Launch"
aip
hM
Click on File->new->Project->Java->select "Java Project" and click "Next"->
Note:
=>To increase font,Click on Window->Preferences->General->Appearance->
=======================================================================
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];
aip
public static void main(String[] args) {
[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;
}
}
nk
[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]([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:
A121
ii
Raj
ath
Enter the CustCity:
Hyd
aip
raj@[Link]
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
[Link]
[Link]
ii
[Link]
ath
[Link]
aip
[Link]:
[Link]:
a
Note:
[Link]:
=>The programming components which are declared without any access modifiers
Diagram:
ii
ath
aip
hM
a tes
====================================================================
nk
faq:
another package.
current programming.
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
Ex:
a
import [Link].*;
nk
import p1.*;
Ve
Ex:
============================================================================
ii
ath
aip
hM
a tes
nk
Ve
Dt : 26/11/2022(Queries)
this
this()
Constructor
ii
ath
package p1;
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];
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;
}
ii
[Link]("Code:"+code);
[Link]("Name:"+name);
ath
[Link]("Author:"+author);
}
}
package p2;
aip
hM
import [Link].*;
import [Link];
[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
package maccess;
public class MainClass {
Ve
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
}
nk
==============================================================================
Ve
Dt : 28/11/2022
faq:
"static import".
syntax:
Advantage:
=>Static members of one class can access the static members of another class
directly.
ii
ath
Note:
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].*;
a = [Link]();
dis();//Method call
[Link]();
ii
o/p:
ath
Enter the value of a:
123
aip
*****dis()******
faq:
=>The process of binding all the programming components into a single unit class
faq:
(i)Class in C++
(ii)Class in Java
=>Class in C++ can hold Variables and functions,but cannot hold main()
(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:
is knwon as string.
nk
Ex:
Ve
"nit","hyd",...
=>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:
=>The statements which are used to execute some lines of program repeatedly are
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
syntax:
do
Ve
//loop_body
while(condition);
flowchart:
ii
ath
aip
hM
a tes
-----------------------------------------------------------------------
nk
[Link] loop:
syntax:
for(Initialization;Condition;Incre/Decre)
{
//Loop_body
flowchart:
ii
ath
aip
hM
tes
========================================================================
a
*imp
nk
[Link] class:
(The Objects once generated cannot be modified are known as Immutable Object)
Diagram:
ii
ath
aip
hM
a tes
nk
Ex : [Link]
package maccess;
Ve
o/p:
hyd
length of s1:3
char at index 1 : y
ii
=====================================================================
ath
Ex:
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
{
char ch = [Link](i);//6 5 4 3 2 1 0
nk
[Link](ch+" ");
}
Ve
[Link]();
}
}
o/p:
program
====reverse of String====
margorp
diagram:
ii
ath
aip
hM
a tes
nk
==================================================================
Ve
Assignment-1:
i/p : program
o/p : count = 2
Assignmnet-2
Note:
ii
String.
ath
======================================================================
faq:
aip
define toString() method?
reference variable.
tes
Method Signature:
a
syntax:
Ve
syntax:
ii
define charAt() method?
ath
=>charAt() is also a pre-defined method used to retrieve the character from the
Method Signature:
aip
hM
public char charAt(int);
syntax:
tes
char ch = [Link](index);
==========================================================================
a
nk
Ve