- INTODUCTION OF JAVA
L.BASIC STRUCTURE OF PROGRAM,
2.ARCHITECTURE OF JAVA
3.DATA TYPES
4.VARIABLES
5.KEYWORDS AND IDENTIFIERS
6.OPERATORS AND TYPES
7.CONDITIONAL STATEMENTS.
8.SWITCH CASE STATEMENTS.
9.LOOPING STATEMENT
10.PATTERN PROGRAMMING.
GENERAL PROGRAMS BASED ON FOR AND WHILE LOOPS
11. METHODS AND METHOD OVERLOADING
12.VARIABLES AND ITS TYPES,
13.ACCESSING DATA MEMBER IN MEMBER FUNCTION
14,EXECUTION PROCESS
15.CONSTRUCTORS
16.CONSTRUCTOR OVERLOADING
17.THIS KEYWORD
18.CONSTRUCTOR CHAINING
19.UML DIAGRAMS
-OOPS
20,INHERITANCE
21. METHOD OVERRIDING AND SUPER KEYWORD
22.ABSTRACTION
23.INTERFACE
24, ACCESS SPECIFIER
25.ENCAPSULATION
26.POLYMORPHISM AND METHOD BINDING
27.GENERALISATION AND SPECIALISATION
28,TYPE CASTING
29.OBJECT CASTING
30,0BJECT CLASS
31,STRING CLASS
32.ARRAY PROGRAMMING.
33, EXCEPTION HANDLING
34, WRAPPER CLASSES.
35,COLLECTION FRAMEWORK
‘in| Satyaranjan Swain36.MAPS.
37.MULTUTHREADING
AUTHOR - - JAMES GOSLING
VENDOR - SUN MICRO SYSYTEM(ORACLE)
PROJECT NAME GREEN TEAM
TYPE OPEN SOURCE,
INITIAL NAME. ~ OAK
PRESENT NAME JAVA
EXT ~ java, class, jar
PRESENT VERSIO!
OPERATING SYSTEM
JAVAL4
ANY OPERATING SYSTEM
BASIS cH
PRINCIPLE - WORA(write once run anywhere)
-Web applications
-Mobile applications
~Client Server application
-Embeded Systems
-Robotics
-SAP
1, J2SENSEGAVA 2 STD EDITION)
2. 2EE/JEE(IAVA 2 ENTERPRISE EDITION)
3.J2ME/JME(IAVA 2 MICRO EDITION)
Version History of JAVA
IDK Alpha and Beta (1995)
IDK 1.0 (23rd Jan 1996)
IDK 1.1 (19th Feb 1997)
RSE 1.2 (8th Dec 1998)
RSE 1.3 (8th May 2000)
J2SE 1.4 (6th Feb 2002)
RSE 5.0 (30th Sep 2004)
Java SE 6 (11th Dec 2006)
Java SE 7 (28th July 2011)
Java SE 8 (18th Mar 2014)
Java SE 9 (21st Sep 2017)
Java SE 10 (20th Mar 2018)
Java SE 11 (11 September, 25th 2018)
Java SE 12 (15 March, 19th 2019)
Java SE 13 (15 September, 17th 2019)
Java SE 14 (14 March, 17th 2020)
Java SE 15 (15 Expected in September 2020)
FEATURES OF JAVA :-
atyaranjan SwainA ts of ED
Simple :
-Simple to leam(Syntax's)
Java is an object-oriented programming language. Everything in java is an object.
Object-oriented means we organize our software as a combination of different types of objects that incorporates.
Object-oriented programming (OOPS) is a methodology that simplifies software development and maintenace by
providing some rules,
Object
Class
Inheritance
Polymorphism
Abstraction
Encapuslation
-Can be used with any other language
-Java code can be run on multiple platforms, for example, Windows, Linux, Sun Solaris, Mac/OS, ete.
-Java code is compiled by the compiler and converted into byte code.
-This byte code is a platform-independent code because it can be run on multiple platforms, i.e., Write Once and Run
Anywhere(WORA).
-any problem happens only JVMUJAVA VIRTUAL MACHINE) will get effected but operating system is safe.
ost of things are automated
Ex: garbage collection
-Running multiple processeses(tasks) at same time
BASIC STRUCTURE OF PROGRAM
public class Demo. a
{
public static void main(String args{ )..
(2)
(sass aranjan Swain{
}
System.out.printin(""This is my first program");
}
Ex: public class Demo
It consists of 3 things
~ It indicates that program is accessible to other users or not
- There are 4 access modifiers in java public,private,protected and default
- in above section class is public so itis freely accessible
- All access modifiers will be in lower case.
= class is a keyword(reserrve word or predefine word) in java.
- Every program must start with class keyword
- all keyword must starts with smaller case so class-c is small,
Every class has some name i.e class name or program name or file name
- class name for standard should start with Capital letter
~ Java File name and class name must be same for remembering purpose
- class name can only be combination of A-Z,a-z,0-
Note:{//} >scope of class
public static void main(String args{ ] )
{
}
It consists of 5 parts
// LOGIC OF APP
void indicated no specific return type
if anyword contains( )~---> we can identified it as a method
Ex: main( )run( ),display( ) ete
‘in| Satyaranjan Swain-main is name of method
String args{ ]
String - S is capital
is statement can be written in 3 ways
L String argsf ]
2.String [ Jargs
3.String[ ] args
Note: In syntax of main method only String-S is capital remaining all words starting letters are small.
System.out printin(""This is my sample program");
system-——-> it is a pre define class[class System]
--> it is a dot operator,any word after it can be reference variable/object or method
.-> it is an object (predefine)
it is a method (predefine)
out
printIn( )~
-In simple printIn() is accessed through out object but out object is present in system class.
~System is a class which contains out object and out object is referring to printIn( )
-whatever we gave in double quotes that message will be printed as itis
For Mobile Execution
please install this app from play store:
AIDE-IDE FOR C++ AND JAVA(ANDROID) or DECODER(ANDROID)
JEDONA(OS)
atyaranjan Swain1.J2SE/JSE (java 2 std edition) - Basie/core java
2.J2BE/JEE (java 2 enterprise edition) - Full stack development
3.J2MEV/JME (java 2micro edition)
Void - no specific return type
Client server application - email
Web based application - any application with url
we can change position of public and static vice-versa.
printIn()----->print next message in new line
print()------>print next message in same line
example-1
public class Today
4
public static void main(String args [ ] )
{
System.out printIn("Hi Rohan");
System.out.print("Your order with id:1235 ");
System.out.printIn("is on the way.");
System.out.print("Please collect it");
3
}
Output
Hi Rohan
‘in| Satyaranjan SwainYour order with id:1235is on the way.
Please collect it
example-2
public class AboutMe
4
public static void main(String args| ])
{
System.out.printI("My Name is : Paul ");
System.out.printIn("I am 22 years old");
System.out.print("I have graduated from Osmania University ");
System.out.printIn("My Ambition is to be a programmer");
}
}
Output
My Name is : Paul I am 22 years old
Thave graduated from Osmania University My Ambition is to be a programmer
~---> if we put // in starting of statement it will be commented (not considred as
part of program)
Ex: //public class AboutMe
----> if we put // in ending of statement after that whatever we write it will not be
considred as part of program.
Ex: public class AboutMe//class declaration
class Today//class declaration
{
public static void main(String ags[ })//main method
{
//System.out.print("My Name is : Paul ");
//System.out.printin("T am 22 years old");
System.out.print("I have graduated from Osmania University ");
System.out_printin("My Ambition is to be a programmer");
‘in| Satyaranjan Swain}
}
Output
Thave graduated from Osmania University My Ambition is to be a programmer
public class MyInfo
4
public static void man(String args[ })
4
System.out.printIn("Name : Rohan \n DOB : 25-07-1993 \n Age:27");
}
Output
Name : Rohan
DOB : 25-07-1993
Age:27
STEP-1: Select n Editor (Notepad, Notepad++,Editplus or IDE-Integrated
development tool)
STEP-2: Write the logic of APP
STEP-3: Save the APP
STEP-4: Compilation
STEP-S: Execution
Note: In IDE's 75% of work is automatic
Ex: Eclipse, Net Beans, etc
(BD satyaranjan Swainedureka!
-whatever program we write it is called as SOURCEICOdE,
-source code should always save as ext " java"
-above program should save as Hello. java
Step-2: Compilation
-The process of converting our program into S¥St@niunderstandablerormn (bye
(C6de) is purpose of compiling a program.
-to compile a program go to cmd prompt and enter command as
~javac programname java
-Ex: javac Hello.java
-Compilation is done at once.
-During compilation, compiler will check SytaX/GtOrS like [ ], ;,),{ },,spellings
and case sensitivity.
-If anything is wrong we will get compile time error.
-If nothing is wrong there is one class [ile QT SCOTSMMED vith same
as .class,
Step-3:|EX@eution
-IVM -java virtual machine is responsible for execution of every java program
-IVM's can identify by ------> Public static void main (String [ ] args)
-it is like one software or one program.
(BD satyaranjan Swain-execution will happen in line by line manner
of program
-for executing program go to command prompt and enter command as
java programname
-Ex: java Hello
-Once we enter this command JVM will go to class file and take first line and
give to operating system for execution, once OS responds that i understood that
line and it sends second line and it continues till last line like this whole code of
class file gets executed.
- IF WE WANT TO DEVELOP AND EXECUTE JAVA PROGRAM IN OUR,
SYSYTEM WE HAVE TO INSATLL JDK(JRE,JVM,SUPPORTING TOOLS.
AND SUPPORTING CLASSES).
JDK = JRE Development Toot 4urek
JRE = JVM + Library Classes
OVERVIEW OF APP ENVIRONMENT
Sr
Zoo 0.g es
Ss Q - »
‘in| Satyaranjan Swain-IT IS RESPOM
‘SIBLE TO EXECUTE EVERY JAVA PROGRAM
Note: when we install JDK with that JVM and JRE are available.
(BD satyaranjan Swain- Ithelps JVM by taking code of class file line by line and give to OS.
DATA TYPES AND VARIABLES
2.Data Types
3.Variabies|
Data : Any information is called as data
For Ex: name,age,height,marks,percentage and
Data Type : it defines type of data.
Divided into 2 types
Primitive data type :
“These are system define data types
~These are fixed in there memory size
~These are 8 in numbers
Name Size Examples Default values
Lbyte 10,2,5(127 is max -128 is minimum) 0
true or false false
3.short 2byte 100,220. . . (32,767 to -32,768) 0
4.char 2 byte Aa empty space
5.int 4 byte 1,2,777...... . (2,147,483,647 is max) 0
6.float Abyte 0.2,0.3,33.666. 0.0
Tong 8 byte 33333333,6565655. 0
8.double 8 byte 0.343434343,99.5555555. ..... 0.0
-When we want 4-6 digits of accuracy we go for float else we use double
-byte,short,int,long is use for Numericals or integers
-double and float use for decimals
-when we store value greater than 2,147,438, 647 We use long and We heed (0 repesent with 'T)
Non primitive data type
-These are not fixed in there memoy size.
atyaranjan Swain1 String : it is used to represents group of char’s,
ex: java,manual testing. .
2.Arrays
(10,20. . ..100)
Note:
-char can be used for single characters
-If we have more than one character we should use String
-Using String we can represent any type of data(info)
Variables :
-Variables are used to store the data for printing or using it in future.
1 Variable Declaration
Syntax : Datatype variablename;
Ex: inta;
float b;
char ch;
tring
ible nam
-whenever we declare a variable one memory block will get created
2.Variable Initialisation
Syntax: Variablename-value;
2-100;
b=0.3333f//mandatory to write f
ch’A'y/mandatory to give"
s-"java"'y/mandatory to give
-we can declare and intialise a variable in single statement also
syntax: Datatype variablename=value;
int a=22;
float b=0.2345f;
Exampl
1 int a=22,b=33;//valid
2.int a=33,bi//valid
3.float percentage~60.0,//invali fis not present
float b=0.3343/defaultly it will be considered as doble to indicae that it is float We have to give D
4.char ch='AB';/invalid char can't be more than one character
integer can't store deimal values
7 String s="123",//valid----->System.out.printin("123"), 8,String d="3334+ghijk"y/valid
9.double marks=100,3434d;//valic in double d is optional
10g number-95039393930; valid engl we need SRESHEWE WS HOR TASTER
atyaranjan SwainGB: 2 return type which does not specify any particular return type
execution will ie start from main method
How to print data stored in variable
Ex: int age=45;
System.out printin(age);//45
char grad
System.out.printIn(grade);/A
>Data type
ariable name
Operator
data/value
B ‘Termination of statement
A)
-IVM is responsible to execute every java program.
-IVM //the identity of jvm is publie static... ifwe change that then jvm will tell identity is not found
{
public static void main(command line args)
3
-Execution of every java program will always start from main method
Because JVM only knows main method
-If main method is not there or main method syntax is changed ourfprogram Will not be executed),
-So, the answer is No we cannot change syntax of main method.
‘A) No we cannot keep main method as private because!
int
age:
-If we keep main method as private,
-We will get Error as Main Method not found in given class
LNG We can i Dain Letnod as Lon ssc bec
-If we keep main method as non static
Note:
ff we did not mention public.private or protected it wil be
considered as default ---->which means there is no need to write like " default class Mydetails " instead we write "
class Mydetails_" itself considerd_as there will be default accessmodifier
aN 5 655.0: ssex:0n siatic modifier, 1VM will consder it as
non static,
public class void main (String args [])"
> non static
(sass aranjan SwainOPERATORS :~
1 Arithemetie Operators
> Addition
- > Subtraction
\ ===> Division (output:Coefficient)
7 Multiplication
% => Mode (output:Remainder)
=>Create an Application which calculates
1.Addition of two numbers
2.Subtraction of two numbers
3.Multiplication of two numbers
4.Division of two numbers
5.Mode of two numbers
class Problems
{
public static void main (String args[ })
t
int a=10,b=5,c.de,g;
tin(c);
System.out printin(d);
System.out.printIn(e);
System.out printin();
System.out printin(g);
2.Operator Overloading :
- Overloading is one thing but plays multiple roles.
Ex; A person can be son,father,husban:
friend et
+ is an overloaded operator
because it act as addition as well as concatination.
(BD satyaranjan Swain1. int + int(int/float/double/long/char/short/byte)
x1: 1224233,
Ex2: 445.33+556,
Ex3: 6671453
2. char + byte)
Vi
Ex: char ch=65;
System.out.pintIn(ch); // A
- If any one operand is String plus operator will always act as concatination.
Ex: String s"java";
int a=123;
System.out.prntin(sta); // "java"+123--->"javal23"
‘System.out.prntin("T am "+S+" developer"); // "Tam java"+"developer"--->T am java developer
~ After concatination result will always be string
‘System.out.pmitin(123+" ");/ "123"
Ex: class BankInfo
{
public static void main(String args{ })
t
String accholdername="Rohan",
double currbalance=450000.0;
int minbal-3000;
System.out printin("The account holder name is: " + accholdemame);
System.out printin("'Current balance is:"+currbalance),
System.out printin("Minimum balance needsto maintain is :"+minbal);
}
}
Assignment
=> Create ann APP whch prints below information about book using datatypes and variables
bookname is : java
bookptice is : 550
bookpages is : 800
bookrating is : A
=> Create an Application which print the details of smartphone
Device name: Iphone
Device Price: 132000
ram : 64gb
Screen Size: 6.0"
=> Create an Application which print the details of Employee
Company Name: Infosys
Designaion: QA
Salary: 3.5LPA,
Experience: 2yrs
‘in| Satyaranjan Swain3.Assignment operator(
- itis use to assign or store the value into a variable.
Ex: int a= 10,b=30;
int e= arb;
4.Comparison operator(—) :
- it compares values and give output as boolean value.
5.Relational Operators
~ checks relationship between two values and result will be boolean
> greater
smaller
> greater than equals
> lesser than equals
> not equals
Result will be either true or false
6.Logical Operrators :
= it compares two inputs and if both inputs are true then output is true or else false.
~ itis represented as && (in below ex 0 indicate false, 1 indicate true)
ab a&&eb
meoe
OR
- it compares two inputs and if any one input is true then output is true or else false,
~ itis represented as | (in below ex 0 indicate false, 1 indicate true)
ab alb
0 0 0
o 1d
10 1
toroid
NOT (!)
(sass aranjan Swaininput output
oo1
1 0
These are the SEESEUUMOREEERISIERE hich have some ceserve meaning
- Various keywords in java are,
1
public, private, protected, static, final, abstract and return. _// System(not keyword) is predefined class, it should start
with capital letter,
2
if, sel if, si ch, case, break, continue, goto, const and default.
3
jo while
class, package, import, extends, implements, interface, new
try, catch, throw, throws, finally
6.Others
volatile, transient, synchronised, native ete
- These are the names given by programmer as per convention,
Ex: class name, variable name, method name and package name,
rule should be followed
convention -- if we don't follow also no problem
1.An identifier can be a combination of A-Z,a-z,0-9,S and _ but standard is,
class name : starts with capital(convention)
variable name: starts with small(convention)
‘method name: starts with small(convention)
package name: starts with small(convention)
2. *Ifan identifier contains more than one word spaces are not allowed.
class My program---->Invalid
(sass aranjan Swainint my age. ->Invalid
public static void display details)
class Myprogram----->valid
int mypercentage-—-->valid
3.*An identifier cannot starts with digit.
class 1A- Invalid
int 1Oae-------->Invalid
class Al ‘valid
int al0- >valid
4.class name contains more than one word for all words first letter should be capital
Ex: class MyFirstProgram(Convention)
5.lf method name and variable name contains more than one word from second word firstletter should be
capital(Convention)
Ex: int myAge;
Ex: public static void displayDetails( )
6.*A variable name and class name cannot be keyword.
Ex: class new--——~Invalid
(sass aranjan Swain7.Unary Operators
a) Increment operator :
- It increases the value by one.
for ex: a=10; increment a add +1 toa
~ It is denoted as +
- It is of two types
1 pre-inerement
2.posteinerement
b) Decrement operator
= It decreases the value by one.
for ex: a=10; decrement a subtract -1 to a
- It is denoted as --
= Itis of two types
Lpre-decrement
2.post-decrement
Types
- it is denoted as ++variablename
For Ex: int a=10; //11
int b=++a:/ipre increment-—-->10+1
SOP(b);//11
Ex2: int a=250;
‘ais incresed by 1 and then 251 is stored in b
(51
SoP(a);//51
- it is denoted as variablename ++
For ex: int a=10;//11
SOP(b);//10
preDecrement :
- the rule is first decrement value then print or assign it or store it in variable.
- itis denoted as --variablename
For ex]: int a=10;
int b=--a;//pre decrement
ex2: int a=250:
(sass aranjan Swainint b=--a;//a is decreased by 1 and then 249 is stored in b
ex3: int a=50;//49
=a; 1/50-1
SOP(a);//49
postDecrement :
- the rule is first print or assign it or store it in variable then decrement value.
- itis denoted as variablename-
For ex: int a=10;
int b=a-~//post decrement
SOP(b);//10
soP(a)yi/9
Exercise:
System.outprintin(H+a + a4);
i
101 + 101--->202
System.out.printin(++a + att + +a);
|
101 + 101 + 103-->305
3.int a=50;
Systemoutprintin@at+ + +ta + a- + ~a)
50 + 52 + 52 = 204
int a=100,b;
Expression _intial_value ofa final_value of b final_value of
100 101 101
100 100 101
100 99 99
100 100 99
7.Combinational or Compound Operators :
1.4= (compound addition assignment operator )
For Ex: a=a+b; can also be written as
a+=by/by using combinational or compound operator
Ex: c=atb/we cannot apply combinational operator
2. = (compound subtraction assignment operator )
3.*= (compound multiplication assignment operator )
4
5.
/= (compound division assignment operator )
%= (compound modulo assignment operator )
CONDITIONAL STA’
NTS
TYPE 1
- Depending on conditions it switches control flow of execution from one . oo.
atyaranjan SwainSyntax: If-else statement
if(condition) a
t as
1iSet of statements fica)
} ” m0
else 1 encore fe cad
{ 1
Jiset of statements aad
3 Yo toe
Note : >
- CErmenmwome mea
- writing else is not mandatory,we can add it as per our requirement.
- condition type must be boolean
+ if we have only one statement inside if { } then we can skip/omit flower brackets
- when if is true else will not be executed,
LWAP to check whether 10 and 20 are equal or not
2.WAP to check whether 10 is positive or negative
3.WAP to check whether pooja is eligible to cast a vote or not, pooja's age 21
4.WAP to check whether 22 is divisible in 4 or not
5.WAP to check whether 32 is even number or not
‘in| Satyaranjan Swainif(condition!)
{
1 if body
3
else if(condition2)
“| ogy of ett
{ {stamens tobe exces
, Helse if body 3 fase
else if(condition3) else if constoh2)
‘
elseif body by fe scondit
} {stamens io be exoased
else 5.b) If false
{ 5
else body else if aetoh)
} equi
ody he st
Type-3
if (Condition! LogicalOperator condition2) sxpirttse 28°
{ ~~
i body of if body ote os
} statements be executed
else
{ 7 rr statements outside te ielse
i body of else items case nese
}
- WAP to find greatest of 3 numbers a=10,b=27,
- WAP to check whether couples are eligible for mariage or not.
- WAP to check whether 10 is divisible in both 2 and 4,
- WAP to check whether 8 is divisible in either 3 or 4
class Eq
{
public static void main(String args{])
{
int nuns;
4f(numk2==0)
Systen.out.println(nun +"is divisible in 2 tables");
System.out.println(nun +"is also even number");
else
Systen.out.println(nunt"is not divisible in 2");
»
Conclusion:we cannot omit flower braces for conditional stat
Af there is more than one statement under if
(ES satyaranjan SwainCis Procedural Programming Language
Cwas developed by Dennis M Ritchie in
1972.
Java language was developed by James
Gosling in 1995
Tn the C declaration VaRaDIEMSMGSIAREEA | Th Tava, you con GSarCaaaBTS aS
‘the beginning of the block.
Coes not support multithreading Tava has Reta ORCAS
suppor pointers: Tava does not Suppor pointers:
#include
C does not havea Teature of overloading Java supporis method overfoading
‘functionality.
Cisplatin dependent language Tava is plafonmnindependenb language
rs Tava is package and class based language.
package java.util;
(BD satyaranjan
SwainLooping statements
- Loop is defined as repeated execution.
- Ifa part of code is repeatedly executing in our program rather than writing it multiple times, we can define it only once
inside loop and run it as many times as we want.
For example- print java 10 times or print 1 to 10 ete
- They are basically of 4 types
1. for
2. while
3. do while
4. for each(Enhanced or Advance for loop)
Without looping statements
{Without using loop//
class A
t
public static void main(String args{ ])
t
System.out printin("java");
System.out printin("java");
System.out printIn("java");
System.out printin("java");
System.out printin("java");
System.out printin("java");
System.out.printIn("java");
System.out printin(*java");
System.out printIn("java");
System.out printin("java"),
3
3
For Loop
class Loop
{
public static void main(String args [ })
‘System.out printin(" Java"); I body ofthe loop
} Ji statements tobe executed
t
3
2.WAP to print numbers fom | to 100, ile
‘in| Satyaranjan Swain{
public static void main(String args [ ])
si<=100;i++)
System.out.printIn(i;
public static void main(String args [ ])
{
int
for
{
}
t
System.out printIn(i);
)
“4.WAP to print all even numbers from | 10 30
class LoopEven
{
public static void main(String args [ ])
si<=30;i++)
ifGi%2—=0)
{
‘System.out printin(i);
i
3
class LoopEvenSum
{
public static void main(String args { ])
{
int i,sum=0;
for(
{
S44)
if(i%2--0)
{
sum=sum+i;
}
}
System. out printin("Final sum value is: "+sum);
‘in| Satyaranjan Swainclass LoopEvenProduct
{
public static void main(String args [ ])
{
int i,product=1;
for(i=1;i<=10;i++)
{
if(i%02—0)
product=product*is
}
3
System.out printIn("Final product value is: "+product);
5
3
class Factorial
{
public static void main(String args [ ])
{
int i,fact=1;
forli=Sit
{
fact=fact*i;
}
System.out printIn("Fa
t
}
torial value is: "+fact);
class MultiplicationTable
{
public static void main(String args{ })
{
int num-3;
for(int i=1;i<=10;i++)
{
System. out printIn(num+"*"+i+"="+(num*i);
(BD satyaranjan
Swainclass SumPdt
public static void main (String args [ ])
{
int sum=0,pdt=1;
for(int i-1;i<-10;i+4)
{
sum=sum+i;
}
System.out printin("Sum value is :"
+sum);
for(int j=1;j<=10;+4)
{
pdt=pdt*j;
}
System.out.printIn("Produet value is :" + pdt);
ount
public static void main(String args{ ])
int count=0,num=5;
for(int i=1;i<=30;i++)
{
if(i%num==0)
{
count=count+1; /feount+
}
3
‘System.out.printin("Final count is : "count );
}
class Fibnocei
{
public static void main(String args{ J)
{
f1=1,12;
System.outlprint(f="");
System.out,print(fl" ");
for(int i=1;i<=6:i++)
{
D=fHfl;
(ES satyaranjan SwainSystem.out\prini(i2+" ");
ffl;
class SwapNum!
{
publie static void main(String args{ ])
{
int a=10,b=20,c;
ca; /ie=10
a=b; Ha=20
bec; {b=10
System.out.printin("After swapping : " tat" 1b);
ss SwapNum2 /without using third variable
public static void main(String args{ ])
int a=10,b=20:
‘System.out.printIn("After swapping : "+a+" " +b);
y
_1.WAP to cheek whether number 13 is prime number or not
‘lass PrimeNumber
{
public static void main(String args{ ])
t
int num = 13;
boolean flag = true;
for(int i= 2; i< num; ++i)
1 condition for nonprme number
if(num % i 0)
{
flag = false;
break;
+
}
if (flag—true)
System.out.printin(num +" is a prime number. ");
else
System.out.printin(num +" is not a prime number. ");
atyaranjan Swaint
public static void main(String args{ J)
t
int num=4,n=2,a=1 pow;
for(int i=Li<=njit+)
{
pow-a*num ;
a=pow;
ifti=n)
eas pe +" to the oa of nt "iss" sess
3
i
(Gattis predetine class
‘pow(num,square) is a method
import statement is for using classes of one package into our own class or own package.
public static void main(String args{ J)
{
HH for( ; ;) for(default;true;)
for(int i=1; si-4)
{
System.out printin("java");
While Loop
ssyifase
class WLoop!
{
public static void main(String args{ ])
{
imiel; Tet eat
while(i<=30)
{
System.out printin(i);
iH
}
‘in| Satyaranjan Swainclass WLoop2
{
public static void main(String args })
{
int i=30;
while(i>=5)
{
System.out printin(i);
i
}
}
}
jass WLoop3
public static void main(String args{ ])
{
int i-30;
while(i>=5)
{
}
System.out.printin();
}
Sais
GED: the above program once condition is false JVM come out of loop and print i value only once,
‘And i value is no more 30 it changes to 4 means whatever we did in while loop with i is going to updated
class PrintCharacters
{
publie static void main(String argsf ])
{
char ch1="A’,
while(ch!
atyaranjan Swain1
System.out.print(ch1);
chi;
}
System.out printin(” ");
while(ch2>'A’)
{
System.out print(ch2);
ch2
i
System.out.printin(" ");
char ch3-'A',
while(ch3<="
1
}
")
3
class ReverseNumber
{
public static void main(String args [ })
System. out printin("Reverse of num is : "+rev);
3
}
Jiworking
while(123>0) while(12>0) while(1>0) while(0>0)
rem=123%10—rem=3_rem=12%10—rer rem=1%10—rem=1
num=123/10—num=12— num=12/10—num=1 num=1/10---num=0
rev=(0*10)+3-—tev-3_—_tev=(3*10)+2—-tev=32 rey~(32#10)+1-—rev-321
atyaranjan Swain>(Pallindrome Number: if we reverse number we should get original number. For ex: 121,111,121
class PallindromeNumber
{
public statie void m
{
int num=121 rev=0,rem(fempenum
‘String args [ })
Sagres of num is : "+tev);
System.out printin("your number is Pallindrome number");
3
else
{
System.out printin("your number is not Pallindrome number
-(Atmsitong Number) Any number we take individually add and cube it, we should get same number.
153-=->1°3+5°343"3-n--->14125-27153
class ArmstrongNumber
{
public static void main(String args [ ])
t
int num=153,rev=0,rem(femp=nums
aS : ao of num is : "+rev);
System.out printin("your number is Armstrong number");
}
else
atyaranjan Swain{
System.out.printin("your number is not Armstrong number");
}
3
t
Jiworking
while(153>0) while(15>0) while(1>0) while(0>0)
rem=153%10—-rem=3 rem=15%10-—rem=5 rem=1%10--rem=1
num=153/10-—num=15 num=15/10—num=1 num=1/10-—num=0
rey=27+(5#5*5)---rev=152 re
52+(1*1#1)-—-rev-153
class Demo
{
public static void main(String args{ })
{
int a=10;//1 1/12/13
do
t
Syste a i / | body of the loop
System =2)
{
System.out.print(” ");
3
else
{
‘System.out print("*");
}
3
System.out.printin(" ");
BY
3
class Star3
t
public static void main(String args{ J)
{
forint i=Lji<=4:i4-4)
for(int j=1;j<=4:5++)
{
if(1%2==0) /i==2i—=4)
{
System.out.print("#");
}
else
{
System.outprint("*");
}
}
System.out printin(" ");
yy
4.
class Stard.
‘in| Satyaranjan Swainpublic static void main(String args{ ])
for(int i= 1si<=4;i1-+)
for(int j=1j<=4)++)
‘ iti =2\i=4/(4%2-=0)
Seno print("#");
else
‘System.out print("*");
}
System.out printin(” ");
class StarS
{
public static void main(String argsf ])
for(int i=1si<—a;it+)
forint j=1:j<=4:)+-+)
t
iti)
{
System.out print("*");
else
‘System.out.print(" ");
}
System.out.printIn( );
}
3
‘in| Satyaranjan Swainclass Pattern6
{
public static void main(String args[ ])
{
fortint i=1;i<-3,i+4)
‘ for(int j=1;j<=3,5+4)
‘ System.out.print(i);
System out. printin();
BY
7
class Pattern?
{
public static void main(String argsf ])
{
for(int i=1si<=3;i1-+)
‘ for(int j=1;j<=3;5+4)
‘ System.out print(j);
"system cout_printing;
By
8
class Pattern’,
{
public static void main(String args{ })
for(int j-1j<-3;i++)
System.out.print(a);
abt
3
System.out.println();
‘in| Satyaranjan Swainclass Pattern9
{
public static void main(String argsf })
for(int j=1;j<=3:)++)
t
System.out.print(ch);
}
ch+t;
System.out.printin);
wy
10.
class Pattern10
{
public static void main(String args| ])
{
for(int i=1;i<-3;i1+)
System.out.print(ch);
chit;
}
System.out.printin(;
wy
uM.
class Pattern 1
{
public static void main(String args{ })
for(int j=1j<-3:++)
System.out print(ch);
chi;
}
System.out printin();
uy
‘in| Satyaranjan Swain