Java Intro - Merged
Java Intro - Merged
1.CoreJava (langauge)
2.AdvJava (Technology)
i
thi
4.Web Services(Frameworks)
ipa
5.Oracle
6.HTML/CSS/JS
7.Anguler
Ma
sh
8.Testing Basics - Selenium
9.DevSecOps
ate
Duration : 5 to 6 months
nk
Advantages:
Ve
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
2.Java 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
1.JDBC
2.Servlet
3.JSP
i
thi
Diagram:
ipa
1.JDBC:
2.Servlet:
sh
=>Servlet means "Server program" and which is used to accept the request
3.JSP:
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)
1.Analysis
2.Design
3.Coding(Construction)
Ma
4.Testing
sh
5.Deployment
ate
Note:
============================================================
Ve
Note:
extention
Test.c
Test.cpp
Test.java
=>After Saving the program,the program will have the following two
stages:
1.Compilation
2.Execution
1.Compilation:
i
thi
=>The process of checking the program constructed according to the rules
ipa
=>After Compilation process is successfull,
=>c and c++ languages generate Objective code and Java lang generate
Byte Code.
2.Execution:
Ma
=>The process of running Compiled codes and checking the required output
sh
is generated or not,is known as Execution process.
=>In C and c++ languages the Objective Code is converted into executable
ate
=>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.
3.Execution 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-17.0.4.1\bin;
hM
step-4 : Click "ok" for three times,then path is setted
================================================================
a tes
nk
Ve
Dt : 4/11/2022
*imp
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[])
}
System.out.print("Welcome to Java");
Ma
}
sh
============================================================
ate
D:\Demo141
nk
syntax:
Class_name.java
Ex:
Display.java
Note:
i
thi
=>Open CommandPrompt and perform "Compilation and Execution process"
ipa
press enter.
syntax:
Ma
javac Class_name.java
sh
Ex:
javac Display.java
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;
System.out.println("a value="+a);
System.out.println("b value="+b);
Ma
System.out.println("The sum="+c);
sh
}
}
ate
o/p:
nk
a value=10
b value=20
Ve
The sum=30
D:\Demo141>
========================================================
Note:
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
1.Primitive Datatypes
ath
2.NonPrimitive Datatypes
aip
1.Primitive 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 : DataTypes.java
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
System.out.println("byte value="+b);
System.out.println("short value="+s);
System.out.println("int value="+i);
tes
System.out.println("long value="+l);
System.out.println("float value="+f);
a
System.out.println("double value="+d);
nk
}
Ve
o/p:
byte value=127
short value=32767
int value=34562345
long value=9898981234
float value=12.34
double value=1234.56
=============================================================
ii
ath
aip
hM
a tes
nk
Ve
Dt : 8/11/2022
(c)Character datatype:
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 : DataTypes2.java
class DataTypes2
a
{
nk
{
Ve
char ch = 'A';
boolean b = true;
System.out.println("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 : StudentResult.java
aip
hM
class StudentResult
int s1=90,s2=78,s3=77,s4=63,s5=93,s6=99;
a
System.out.println("Sub-1="+s1);
Ve
System.out.println("Sub-2="+s2);
System.out.println("Sub-3="+s3);
System.out.println("Sub-4="+s4);
System.out.println("Sub-5="+s5);
System.out.println("Sub-6="+s6);
System.out.println("TotMarks=="+totMarks);
System.out.println("Percentage="+per);
o/p:
Sub-1=90
ii
Sub-2=78
ath
Sub-3=77
Sub-4=63
aip
Sub-5=93
Sub-6=99
hM
TotMarks==500
Percentage=83.333336
===========================================================
tes
Assignment2:(Solution)
program : EmployeeSalary.java
class EmployeeSalary
Ve
System.out.println("BSal="+bSal);
System.out.println("HRA="+hra);
System.out.println("DA="+da);
System.out.println("TotSal="+totSal);
ii
}
ath
}
o/p:
aip
BSal=17453
HRA=16231.29
hM
DA=10995.39
TotSal=44679.68
========================================================
tes
*imp
2.NonPrimitive Datatypes:
a
or Referential datatypes.
(a)Class
(b)Interface
(c)Array
(d)Enum
============================================================
*imp
or Referential datatypes
ii
ath
Levels in Object Oriented programming:
1.Object definition
aip
2.Object creation
3.Object location
hM
4.Object Components
5.Object Types
6.Object Cloning
tes
7.Object Serializable
8.Object Locking
a
10.Objects 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 : Test.java
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();
System.out.println("a value="+ob.a);
hM
System.out.println("b value="+Test.b);
}
tes
o/p:
a value=10
a
b value=20
nk
Diagram:
Ve
ii
ath
aip
hM
============================================================
tes
*imp
(a)Class:
a
1.Pre-defined classes
1.Pre-defined classes:
=>The classes which are already defined and available from JavaLib are known as
Pre-defined classes or Built-in classes.
Ex:
String
System
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:
1.Static Variables
2.NonStatic Variables
ii
1.Static 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
1.static 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 : DemoMethods1.java
hM
class DemoMethods1
{
nk
//System.out.println("a value:"+a);//Error
Ve
System.out.println("b value:"+b);
System.out.println("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
1.Methods without parameters
ath
2.Methods with parameters
aip
1.Methods without parameters:
=>The methods which are declared without parameters are known as 0-parameter
hM
methods or Methods without parameters.
=>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
3.Execution 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
======================================================================
3.Execution 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
1.nextByte() - to read byte data
ath
Method Signature : public byte nextByte();
aip
hM
Method Signature : public short nextShort();
ii
7.nextBoolean() - to read boolean data
ath
Method Signature : public boolean nextBoolean();
aip
hM
Method Signature : public String nextLine();
DemoMethods2.java
nk
import java.util.Scanner;
class DemoMethods2
Ve
System.out.println("Enter UserName:");
String name = s.nextLine();//will read String data
String mailId=s.nextLine();
long phNo=s.nextLong();
System.out.println("====UserDetails====");
ii
System.out.println("UserName:"+name);
ath
System.out.println("MailId:"+mailId);
System.out.println("PhoneNo:"+phNo);
aip
}
}
hM
o/p:
Enter UserName:
raj
tes
raj@gmail.com
a
9898981234
====UserDetails====
Ve
UserName:raj
MailId:raj@gmail.com
PhoneNo:9898981234
Diagram:
ii
ath
aip
hM
tes
=====================================================================
Assignment-1:
a
nk
Assignment-2:
==========================================================================
Dt : 15/11/2022
Assignment-1:(Solution)
Program : DemoMethods3.java
import java.util.Scanner;
ii
class DemoMethods3
ath
{
aip
{
System.out.println("=====BookDetails=====");
System.out.println("BookCode="+code);
System.out.println("BookName="+name);
System.out.println("BookAuthor="+author);
System.out.println("BookPrice="+price);
System.out.println("BookQty="+qty);
ii
o/p:
ath
Enter the BookCode:
CS121
aip
Enter the BookName:
C-Lang
hM
Enter the BookAuthor:
B-Swamy
234.56
12
nk
=====BookDetails=====
BookCode=CS121
Ve
BookName=C-Lang
BookAuthor=B-Swamy
BookPrice=234.56
BookQty=12
==============================================================
Assignment-2:
Program : DemoMethods4.java
import java.util.Scanner;
class DemoMethods4
ii
{
ath
public static void main(String[] args)
aip
Scanner s = new Scanner(System.in);
System.out.println("====CustomerDetails====");
Ve
System.out.println("AccNo:"+accNo);
System.out.println("CustName:"+name);
System.out.println("Balance:"+bal);
System.out.println("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.
1.Arithmetic Operators
2.Relational Operators
3.Logical Operators
4.Increment/Decrement Operators
1.Arithmetic Operators:
operations.
Operator Meaning
+ Addition
ii
- Subtraction
ath
* Multiplication
/ Division
aip
% ModDivision
hM
2.Relational Operators:
=>Relational operators are used to compare two values and generate boolean
reasult.
tes
Operator Meaning
== Is Equal to
!= Not Equal to
3.Logical 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
4.Increment/Decrement Operators:
=>Increment operator will increment the value by 1 and decrement operator will
Operator Meaning
ii
++ Increment
ath
-- Decrement
=========================================================================
aip
*imp
1.Selection statements
2.Iterative statements
a
3.Branching statements
nk
1.Selection statements:
Ve
=>The statements which are used to select part of program for execution based
=>Types:
(a)Simple if
(b)if-else
(c)Nested if
(d)Ladder if-else
(e)switch-case
2.Iterative statements:
=>The statements which are used to execute some lines of program repeatedly
ii
are known as Iterative Statements or Repeatitive Statements or Looping Structures
ath
=>Types:
(a)while loop
aip
(b)do-while loop
(c)for loop
hM
3.Branching statements:
=>The statements which are used to transfer the execution-control from one
tes
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:
1.GreaterValue
2.SmallerValue
ii
SubClasses : GreaterValue,SmallerValue
ath
MainClass : DemoMethods5
aip
program : DemoMethods5.java
import java.util.Scanner;
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 = s.nextInt();
int v2 = s.nextInt();
if(v1>0 && v2>0)
if(v1==v2)
ii
else
ath
{
System.out.println("****Choice*****");
aip
System.out.println("1.GreaterValue\n2.SmallerValue");
switch(choice)
{
tes
case 1:
int r1 = gv.greater(v1,v2);
nk
System.out.println("GreaterValue:"+r1);
case 2:
int r2 = sv.smaller(v1,v2);
System.out.println("SmallerValue:"+r2);
break;
default:
System.out.println("Invalid Choice...");
}//end of switch
else
ii
{
ath
System.out.println("Invalid values...");
aip
}
}
hM
o/p:
12
tes
13
a
****Choice*****
nk
1.GreaterValue
2.SmallerValue
Ve
SmallerValue:12
-----------------------------------------------------------------
GreaterValue.class
SmallerValue.class
DemoMethods5.class(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:
1.add
aip
2.sub
3.mul
hM
4.div
5.modDiv
tes
SubClasses : Addition,Subtraction,Multiplication,Division,ModDivision
MainClass : DemoMethods6
a
========================================================================
nk
Ve
Dt : 17/11/2022
Assignment:(Solution)
wap to read two int values and perform the following operations based of user
choice:
1.add
2.sub
ii
3.mul
ath
4.div
5.modDiv
aip
SubClasses : Addition,Subtraction,Multiplication,Division,ModDivision
hM
MainClass : DemoMethods6
program : DemoMethods6.java
tes
import java.util.Scanner;
{
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(System.in);
ath
System.out.println("Enter the int value1:");
int v1 = s.nextInt();
aip
System.out.println("Enter the int value2:");
int v2 = s.nextInt();
hM
if(v1>0 && v2>0)
System.out.println("****Choice*****");
tes
System.out.println("1.add\n2.sub\n3.mul\n4.div\n5.modDiv");
switch(choice)
{
Ve
case 1:
int r1 = ad.add(v1,v2);
System.out.println("Sum:"+r1);
break;
case 2:
int r2 = sb.sub(v1,v2);
System.out.println("Sub:"+r2);
break;
case 3:
ii
Multiplication ml = new Multiplication();
ath
int r3 = ml.mul(v1,v2);
System.out.println("Mul:"+r3);
aip
break;
case 4:
hM
Division dv = new Division();
float r4 = dv.div(v1,v2);
System.out.println("Div:"+r4);
tes
break;
case 5:
a
int r5 = md.modDiv(v1,v2);
System.out.println("ModDiv:"+r5);
Ve
break;
default:
System.out.println("Invalid Choice...");
}//end of switch
}
else
System.out.println("Invalid values...");
ii
o/p:
ath
Enter the int value1:
12
aip
Enter the int value2:
7
hM
****Choice*****
1.add
2.sub
tes
3.mul
4.div
a
5.modDiv
nk
4
Ve
Div:1.7142857
==============================================================
1.read empName
2.read empDesg
ii
5.If the bSal is validated,then read hra and da
ath
=>The hra and da must greater than zero
Program : DemoMethods7.java
aip
hM
import java.util.Scanner;
{
tes
{
a
return switch(empDesg)
nk
default:yield false;
};
}
}
return bSal+hra+da;
ii
}
ath
}
aip
{
boolean k = cd.verify(empDesg);
Ve
if(k)
if(bSal>=12000)
ii
System.out.println("Enter the HRA:");
ath
float h= s.nextFloat();
aip
System.out.println("Enter the DA:");
float d = s.nextFloat();
hM
float da = (d*bSal)/100;
{
tes
System.out.println("EmpName:"+empName);
nk
System.out.println("EmpDesg:"+empDesg);
System.out.println("EmpId:"+empId);
Ve
System.out.println("BSal:"+bSal);
System.out.println("TotSal:"+totSal);
}//end of if
else
{
System.out.println("Imvalid hra and da..");
}//end of if
else
System.out.println("Invalid bSal...");
ii
}
ath
}//end of if
aip
else
{
hM
System.out.println("Invalid empId...");
}
tes
}//end of if
else
a
{
nk
System.out.println("Invalid empDesg...");
}
Ve
o/p:
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:
1.read stuName
2.read stuBranch
ii
=>stuBranch must be in CIVIL or MECH or EEE or ECE or CSE,else "Invalid branch"
ath
3.If the branch is verified Successfully,then read stuRollNo
aip
4.If 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:
1.GreaterValue
2.SmallerValue
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
1.static blocks
ii
ath
1.static blocks:
=>The blocks which are declared with "static" keyword are known as static blocks
aip
or Class blocks.
hM
syntax:
static
{
tes
//statements
}
a
nk
=>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 : DemoBlock1.java
class DemoBlock1 //MainClass
System.out.println("****main()*****");
ii
System.out.println("The value k:"+k);
ath
}
static
aip
{
System.out.println("****static block****");
hM
System.out.println("The value k:"+k);
}
tes
o/p:
****static block****
a
****main()*****
-------------------------------------------------------------------------
Ex : DemoBlock2.java
static int z;
static
System.out.println("****Static block****");
ii
{
ath
return z;
aip
}
{
tes
Test.z = 200;
int p = Test.getValue();
a
System.out.println("*****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(DemoBlocks2.java)
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++;
System.out.println("====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
1.Constructors without parameters
=>The Constructors which are declared without parameters are known as 0-parameter
tes
Ex-program : DemoCon1.java
nk
{
Ve
int k=12;
CTest1()
System.out.println("====CTest()====");
void dis()
System.out.println("====dis()====");
ii
}
ath
class DemoCon1 //MainClass
aip
public static void main(String[] args)
{
hM
CTest1 ob = new CTest1();//Con_Call
ob.dis();//Method_call
ob.dis();
tes
ob.dis();
}
a
}
nk
o/p:
====CTest()====
Ve
====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 : DemoCon2.java
Ve
CTest2()
{
System.out.println("****CTest2()****");
return;
System.out.println("****Instance block****");
ii
}
ath
static
aip
{
System.out.println("****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 : DemoCon3.java
ath
import java.util.Scanner;
aip
{
System.out.println("====CTest3(x,y,z)====");
System.out.println("x:"+x);
tes
System.out.println("y:"+y);
System.out.println("z:"+z);
a
}
nk
CTest3(int x,int y)
{
Ve
System.out.println("====CTest3(x,y)====");
System.out.println("x:"+x);
System.out.println("y:"+y);
CTest3(int x)
{
System.out.println("====CTest3(x)====");
ii
public static void main(String[] args)
ath
{
aip
System.out.println("Enter the value of x:");
int x = s.nextInt();
hM
System.out.println("Enter the value of y:");
int y = s.nextInt();
int z = s.nextInt();
System.out.println("====Choice=====");
a
System.out.println("1.CTest3(x,y,z)\n2.CTest3(x,y)\n3.CTest3(x)");
nk
switch(choice)
case 1:
break;
case 2:
break;
case 3:
break;
ii
default:
ath
System.out.println("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 : DemoCon4.java
import java.util.Scanner;
ii
class CTest4 //SubClass
ath
{
aip
{
this(x,y);//Con_2_para
hM
System.out.println("====CTest3(x,y,z)====");
System.out.println("x:"+x);
System.out.println("y:"+y);
tes
System.out.println("z:"+z);
}
a
CTest4(int x,int y)
nk
this(x);//Con_1_para
Ve
System.out.println("====CTest3(x,y)====");
System.out.println("x:"+x);
System.out.println("y:"+y);
CTest4(int x)
{
System.out.println("====CTest3(x)====");
System.out.println("x:"+x);
ii
{
ath
public static void main(String[] args)
aip
Scanner s = new Scanner(System.in);
int y = s.nextInt();
tes
int z = s.nextInt();
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 : DemoCon5.java
import java.util.Scanner;
ii
String userName,passWord,firstName,lastName;
ath
UserRegistration(String userName,String passWord,String firstName,
String lastName)
aip
{ //Local Variables memory in method
this.userName=userName;
hM
this.passWord=passWord;
this.firstName=firstName;
this.lastName=lastName;
tes
void getUserRegistrationDetails()
a
{
nk
System.out.println("====UserRegistrationDetails====");
System.out.println("UserName:"+userName);
Ve
System.out.println("PassWord:"+passWord);
System.out.println("FirstName:"+firstName);
System.out.println("LastName:"+lastName);
}
}
ii
System.out.println("Enter the UserName:");
ath
String uName = s.nextLine();
aip
String pWord = s.nextLine();
ob.getUserRegistrationDetails();
}
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 : DemoCon6.java
import java.util.Scanner;
int code;
String name;
void getProduct()
ii
{
ath
System.out.println("====ProductDetails====");
System.out.println("ProductCode:"+code);
aip
System.out.println("ProductName:"+name);
}
hM
}
{
tes
{
a
ob.code = Integer.parseInt(s.nextLine());
ob.name = s.nextLine();
ob.getProduct();
}
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 : DemoCon7.java
a
import java.util.Scanner;
nk
{
Ve
int code;
String name,author;
this.code=code;
}
this.name=name;
ii
{
ath
this.author=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
ob.setCode(bCode);
ath
System.out.println("Enter the bName:");
aip
ob.setName(bName);
ob.setAuthor(bAuthor);
System.out.println("======BookDetails=====");
tes
System.out.println("Code:"+ob.getCode());
System.out.println("Name:"+ob.getName());
a
System.out.println("Author:"+ob.getAuthor());
nk
}
Ve
o/p:
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
java.util - 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:
https://www.eclipse.org/downloads/
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
EmployeeSalary.java
package p1;
public class EmployeeSalary {
public float calculate(int bSal) {
return bSal+(0.93F*bSal)+(0.63F*bSal);
}
}
EmpMainClass.java
package p2;
ii
import java.util.Scanner;
ath
import p1.EmployeeSalary;
aip
public static void main(String[] args) {
System.out.println("BSal:"+bSal);
a
System.out.println("TotSal:"+totSal);
nk
s.close();
}
Ve
===========================================================================
Dt : 25/11/2022
ProjectName : Customer_App
packages,
p1 : CustomerDetails,CustContact
p2 : CustMainClass
ii
CustomerDetails.java
ath
package p1;
public class CustomerDetails {
public String custId,custName,custCity;
aip
public String getCustId() {
return custId;
}
hM
public void setCustId(String custId) {
this.custId = custId;
}
}
nk
CustContact.java
package p1;
public class CustContact {
public String mailId;
public long phoneNo;
public String getMailId() {
return mailId;
}
public void setMailId(String mailId) {
this.mailId = mailId;
}
public long getPhoneNo() {
ii
return phoneNo;
}
ath
public void setPhoneNo(long phoneNo) {
this.phoneNo = phoneNo;
}
CustMainClass.java(MainClass)
aip
hM
package p2;
public class CustMainClass {
public static void main(String[] args) {
java.util.Scanner s = new java.util.Scanner(System.in);
p1.CustomerDetails cd = new p1.CustomerDetails();
p1.CustContact cc = new p1.CustContact();
tes
cd.setCustCity(s.nextLine());
System.out.println("Enter the MailID:");
cc.setMailId(s.nextLine());
System.out.println("Enter the PhoneNo:");
Ve
cc.setPhoneNo(s.nextLong());
System.out.println("====Display Cutomer details====");
System.out.println("CustId:"+cd.getCustId());
System.out.println("CustName:"+cd.getCustName());
System.out.println("CustCity:"+cd.getCustCity());
System.out.println("MailId:"+cc.getMailId());
System.out.println("PhoneNo:"+cc.getPhoneNo());
s.close();
}
}
o/p:
A121
ii
Raj
ath
Enter the CustCity:
Hyd
aip
raj@gmail.com
CustId:A121
tes
CustName:Raj
CustCity:Hyd
a
MailId:raj@gmail.com
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
1.public
2.private
ii
3.protected
ath
4.default
aip
1.public:
3.protected:
a
Note:
4.default:
=>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 java.util.Scanner;
import p1.CustomerDetails;
aip
import p1.CustContact;
hM
2.Using "import package_name.*; "
=>In this importing process all the classes from the package are available to
Ex:
a
import java.util.*;
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 java.util.Scanner;
import p1.CheckNumber;
ii
CheckNumber ob = new CheckNumber();
ath
boolean b = ob.verify(num);
if(b)
aip
{
System.out.println("Even Number....");
hM
}//end of if
else
{
tes
System.out.println("Odd Number...");
}
a
s.close();
nk
}
Ve
-------------------------------------------------------------------------
package p1;
public class BookDetails {
//Instance Variables
public int code;
public String name,author;
//Constructor is used to initialize instance variables
public BookDetails(int code,String name,String author) {
//Local Variables
this.code=code;
this.name=name;
this.author=author;
}
ii
System.out.println("Code:"+code);
System.out.println("Name:"+name);
ath
System.out.println("Author:"+author);
}
}
package p2;
aip
hM
import java.util.*;
import p1.BookDetails;
ob.getBookDetails();//method call
s.close();
ii
ath
}
---------------------------------------------------------------------------------------------------
aip
package maccess;
public class Test {
//Constructor Chaining process using this()
public Test(int x) {
hM
System.out.println("****Test(x)*****");;
System.out.println("The value x:"+x);
}
public Test(int x,int y) {
this(x);
System.out.println("****Test(x,y)*****");
tes
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) {
this.uName = uName;
}
public long getPhNo() {
return phNo;
}
public void setPhNo(long phNo) {
this.phNo = phNo;
ii
}
ath
}
package maccess;
import java.util.*;
aip
public class MainClass {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
User ob = new User();
hM
System.out.println("Enter the UserName:");
ob.setuName(s.nextLine());
System.out.println("Enter the PhoneNO:");
ob.setPhNo(s.nextLong());
System.out.println("===UserDetails===");
tes
}
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
Display.java
package test;
public class Display {
public static int a;
public static void dis() {
tes
System.out.println("*****dis()******");
System.out.println("The value a:"+a);
}
}
a
nk
MainClass.java(MainClass)
package maccess;
Ve
import java.util.*;
a = s.nextInt();
dis();//Method call
s.close();
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 java.lang package to create
string objects:
1.String class
2.StringBuffer class
3.StringBuilder class
-------------------------------------------------------------------------------
ii
ath
aip
hM
a tes
nk
Ve
Dt : 29/11/2022
faq:
=>The statements which are used to execute some lines of program repeatedly are
ii
1.while loop
ath
2.do-while loop
3.for loop
1.while loop:
aip
hM
=>In while looping structure the condition is checked first and if the condition
is true then the loop-body is executed,this process is repeated until the condition
is false.
tes
syntax:
while(condition)
a
{
nk
//loop-body
}
Ve
flowchart:
ii
ath
aip
hM
-------------------------------------------------------------------
tes
2.do-while loop:
=>In do-while looping structure the loop-body is executed first and then the
a
syntax:
do
Ve
//loop_body
while(condition);
flowchart:
ii
ath
aip
hM
a tes
-----------------------------------------------------------------------
nk
3.for loop:
syntax:
for(Initialization;Condition;Incre/Decre)
{
//Loop_body
flowchart:
ii
ath
aip
hM
tes
========================================================================
a
*imp
nk
1.String class:
(The Objects once generated cannot be modified are known as Immutable Object)
Diagram:
ii
ath
aip
hM
a tes
nk
Ex : DemoStrin1.java
package maccess;
Ve
o/p:
hyd
length of s1:3
char at index 1 : y
ii
=====================================================================
ath
Ex:
Ex : DemoString2.java
aip
hM
package maccess;
import java.util.*;
public class DemoString2 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("Enter the String:");
tes
{
char ch = str.charAt(i);//6 5 4 3 2 1 0
nk
System.out.print(ch+" ");
}
Ve
s.close();
}
}
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 = str.charAt(index);
==========================================================================
a
nk
Ve