SlideShare a Scribd company logo
1 of 39
Control Statements
Language Fundamental
Command Line Arguments
1
www.infoviaan.com
Command Line Argument
Animal
Human
public class CommandLineArgument
{
public static void main(String args[])
{
System.out.println(“Hello ” +args[0]);
}
}
Compile : - javac CommandLineArgument.java
Run:- java CommandLineArgument info viaan Lecture
class args[0] args[1] args[2]
Output:- Hello info
Run:- java CommandLineArgument “info viaan” Lecture
class args[0] args[1]
2
www.infoviaan.com
Command Line Argument
Animal
Human
public class NoOfArg
{
public static void main(String ar[])
{
System.out.println(“You passed total no. of
arguments: ”+ar.length);
}
}
Compile : - javac NoOfArg.java
Run:- java NoOfArg Hello I am good
1 2 3 4
Output:- You passed total no. of arguments: 4
3
www.infoviaan.com
Control Statements
Animal
• Control the flow of program
Control
Statements
Decision Making
Statements
Looping Statements
if else
Ladder if else
Nested if else
Switch case
do...while
for
while
for each
4
www.infoviaan.com
Program - if else
• An if statement can be followed by an optional else
statement, which executes when the Boolean expression is
false.
public class TestIfElse {
public static void main(String[] args) {
int age = Integer.parseInt(args[0]);
if (age > 17)
System.out.println("You are Eligibe
for Vote :)");
else
System.out.println("Sorry! You Are
not eligible :(");
}
}
5
www.infoviaan.com
Program - Nested if..else
public class Nested {
public static void main(String[] args) {
int a, b, c;
a = 113; b = 88; c = 95;
if (a > b) {
if (a > c) {
System.out.println("A is biggest " + a);
} else {
System.out.println("C is boggest " + c);
}
} else {
if (b > c)
System.out.println("B is biggest " + b);
else
System.out.println("C is Biggest " + c);
}
}
} 6
www.infoviaan.com
Switch statement
• A switch statement allows a variable to be tested for
equality against a list of values.
• Each value is called a case, and the variable being
switched on is checked for each case.
7
www.infoviaan.com
Program - Switch
public class Switch {
public static void main(String[] args) {
int i = 2;
switch (i) {
case 1: System.out.println(“Addition");
break;
case 2:System.out.println(“Subtraction");
break;
case 3:System.out.println(“Mulplication");
break;
default: System.out.println(“Not
Available");
}
}
}
8
www.infoviaan.com
Program - Switch with
String (Java 5)public class Switch {
public static void main(String[] args) {
String c = “Ram";
switch (c) {
case “Ram":System.out.println(“Lord");
break;
case "Shani": System.out.println(“Dev");
break;
case “RamDev“: System.out.println(“BaBa");
break;
default: System.out.println(“People");
}
}
}
9
www.infoviaan.com
Loop
• while - allows code to be executed repeatedly based on
a given Boolean condition
• do...while - executes a block of code at least once, and
then repeatedly executes the block, or not, depending
on a given boolean condition at the end of the block
• for – it specifying iteration, which allows code to be
executed repeatedly
• for each (java 5) - used to access each successive value
in a collection of values. Arrays and Collections
10
www.infoviaan.com
While Loop
11
www.infoviaan.com
Program - While Loop
public class TestWhile {
public static void main(String[] args) {
int i = 1;
while (i <= 5) {
System.out.println("Hello "+i);
i++;
}
}
}
12
www.infoviaan.com
do While Loop
13
www.infoviaan.com
Program – do While Loop
public class TestDo {
public static void main(String[] args) {
int i = 1;
do {
System.out.println("Hello " +
i);
i++;
} while (i <= 5);
}
}
14
www.infoviaan.com
for Loop
15
www.infoviaan.com
Program - for Loop
public class TestForLoop {
public static void main(String[] args) {
int n = 4;
int fact = 1;
for (int i = 1; i <= n; i++) {
fact = fact * i;
}
System.out.println("Factorial Value is = "
+ fact);
}
}
16
www.infoviaan.com
Loop
While(condition)
{
}
For( ; conditionalstatement;
)
{
}
17
www.infoviaan.com
Loop
18
www.infoviaan.com
Nested Loop
• A nested loop is a (inner) loop that appears in the
loop body of another (outer) loop.
• The inner or outerloop can be any type: while, do
while, or for.
• For example, the inner loop can be a while loop while
an outer loop can be a for loop. Of course, they can
be the same kind of loops too.
19
www.infoviaan.com
Programs - Nested Loop
public class TestNestedLoop {
public static void main(String[] args) {
for (int i = 1; i <= 5; i++) {
for (int j = 1; j <= i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
20
www.infoviaan.com
For each Loop(java 5)
• Access value directly from array or collection.
for(type variable : array){
//statement
}
Program : -
public class TestForEach{
public static void main(String[] args) {
int ar[]= {10,20,30,40,50};
for (int i : ar) {
System.out.println(i);
}
}
} 21
www.infoviaan.com
Array
Animal
Human
• An array is a container object that holds a fixed
number of values of a single type.
• It’s reference data type, which contain 2 byte
memory for holding address
• Advantages:
• Contiguous memory allocation
• Collection of similar data types
• Limitations:
• Can’t store dissimilar data types
• Not resizable
22
www.infoviaan.com
Declare an Array
Animal
Human
1. int x[] = {10,20,30,40,50}; //memory allocate at
compile time
2. int x[] = new int[5];
3. int x[] = new int[]{10,20,30,40,50}; //memory
allocate at runtime
• Which one is better to use?
Knows the elements - 3
Don't know the elements -2
23
www.infoviaan.com
One-D Array
Animal
Human
int a[] = new int[9];
a[0] = 10;
a[1] = 20;
…..
a[8] = 90;
or
int a[] = {10, 20, 30, 40, 50, 60, 70, 80, 90};
int size = a.length;
a[0]
a[1]
a[2]
a[3]
a[4]
a[5]
a[6]
a[7]
a[8]
1000
1000
10
20
30
40
50
60
70
80
90
4 B
2 B
24
www.infoviaan.com
One-D Array
Animal
char c[] = new char[7];
c[0] = ‘A’;
c[1] = ‘V’;
…
Or
char c[] = {‘A’, ’V’, ’R’, ’T’, ’E’, ’T’, ’P’};
String names[] = new String[5];
name[0] = “Ram”;
name[1] = “Lakhan”;
…
Or
String names[] = {“Ram”, ”Lakhan”, ”Sita”, “Hanuman”,
“Ramayana”};
25
www.infoviaan.com
Programs – One_D_Array
public class TestOneDArray {
public static void main(String[] args) {
char ar[]= {'X','Y','Z','A','@'};
for (char c : ar) {
System.out.println(c);
}
}
}
26
www.infoviaan.com
Copy an Array
Animal
• To copy an arrays value to another use System.ArrayCopy()
method, which take 5 arguments.
System.ArrayCopy(copyFrom, 2, copyTo, 0, 5);
Start index
Start index
No. of elements
27
www.infoviaan.com
Programs – Copy Array
public class TestArrayCopy {
public static void main(String[] args) {
char cf[] = { 'X', 'Y', 'Z', 'A', 'W' };
char ct[] = new char[4];
System.arraycopy(cf, 1, ct, 0, 4);
System.out.println(ct);
}
}
28
www.infoviaan.com
2D array
Animal
Human
29
www.infoviaan.com
Array of Array/ 2D array
Animal
Human
Two types
• Square Array
• Zagged Array
1. int x[][]={
{10,20,30},
{10},
{10,20}
};
2. int x[][]=new int[3][];
3. int x[][]=new int[][] {
{10,20,30},
{10},
{10,20}
}; 30
www.infoviaan.com
2D array
Animal
Human
31
www.infoviaan.com
2D array
Animal
Human
32
www.infoviaan.com
Programs - TwoDArray
public class TestTwoD {
public static void main(String[] args) {
int x[][] = { { 12, 23, 67, 89 },
{ 89, 78, 67 },
{ 12, 34, 78 } };
int i=0;
while(i<x.length) {
int j=0;
while(j<x[i].length) {
System.out.print(x[i][j]+" ");
j++;
}
System.out.println();
i++;
}
}
}
33
www.infoviaan.com
3D array
Animal
Human
34
www.infoviaan.com
QA
1. What is difference between while and do..while loop?
2. Switch case work with which of the followings.
Byte,short,int,long,float,double,String
3. Difference between for in and for loop.
4. What happens when we forget to put a break statement in a
case clause of a switch?
5. Which method is given parameter via command line
arguments?
6. How many arguments can be passed to main()?
7. Which loop will execute the body of loop even when condition
controlling the loop is initially false?
8. Which of the jump statements can skip processing remainder
of code in its body for a particular iteration?
9. Why java uses String array as command Line Argument?
35
www.infoviaan.com
QA
1. What is the index of Brighton in the following array?
String[] skiResorts = { "Whistler Blackcomb", "Squaw Valley",
"Brighton", "Snowmass", "Sun Valley", "Taos" };
2. Write an expression that refers to the string Brighton within
the array.
3. What is the value of the expression skiResorts.length?
4. What is the index of the last item in the array?
5. What is the value of the expression skiResorts[4]?
36
www.infoviaan.com
Module Project 1
Ross is an event organizer. He has received data regarding the
participation of employees in two different events. Some employees
have participated in only one event and others have participated in
both events. Ross now needs to count the number of employees who
have taken part in both events. The records received by Ross consist
of employee ids, which are unique. Write a program that accepts the
employee ids participating in each event (the first line relates to the
first event and the second line relates to the second event). The
program should print the number of common employee ids in both
the events.
Suppose the following input is given to the program, where each line
represents a different event:
1001,1002,1003,1004,1005
1106,1008,1005,1003,1016,1017,1112
Now the common employee ids are 1003 and 1005, so the program
should give the output as:
2
www.infoviaan.com
Module Project 2
Write a java code to find the distance from Mumbai to major
cities of India.
Hint: Create an String array of major cities and integer array of
distances. User gives the city name and the same is searched in
the respective array and displays result.
www.infoviaan.com
Get in Touch
Thank You
www.infoviaan.com
39
www.infoviaan.com

More Related Content

What's hot

JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and OperatorsSunil OS
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Nishan Barot
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript TutorialBui Kiet
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)Sujit Majety
 
Exception Handling
Exception HandlingException Handling
Exception HandlingSunil OS
 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data TypesTareq Hasan
 
Hibernate
Hibernate Hibernate
Hibernate Sunil OS
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File HandlingSunil OS
 
Function-Definition, Need, Declaration, Definition, Arguments, Return Value
Function-Definition, Need, Declaration, Definition, Arguments, Return ValueFunction-Definition, Need, Declaration, Definition, Arguments, Return Value
Function-Definition, Need, Declaration, Definition, Arguments, Return Valuemanish maurya
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to JavascriptAmit Tyagi
 
Control structures in java
Control structures in javaControl structures in java
Control structures in javaVINOTH R
 

What's hot (20)

JAVA Variables and Operators
JAVA Variables and OperatorsJAVA Variables and Operators
JAVA Variables and Operators
 
Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.Final JAVA Practical of BCA SEM-5.
Final JAVA Practical of BCA SEM-5.
 
Interfaces in java
Interfaces in javaInterfaces in java
Interfaces in java
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
 
JUnit 4
JUnit 4JUnit 4
JUnit 4
 
Spring boot jpa
Spring boot jpaSpring boot jpa
Spring boot jpa
 
Introduction to java (revised)
Introduction to java (revised)Introduction to java (revised)
Introduction to java (revised)
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Java string handling
Java string handlingJava string handling
Java string handling
 
Java
JavaJava
Java
 
Java: Primitive Data Types
Java: Primitive Data TypesJava: Primitive Data Types
Java: Primitive Data Types
 
Hibernate
Hibernate Hibernate
Hibernate
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
JAVA OOP
JAVA OOPJAVA OOP
JAVA OOP
 
Java Input Output and File Handling
Java Input Output and File HandlingJava Input Output and File Handling
Java Input Output and File Handling
 
Function-Definition, Need, Declaration, Definition, Arguments, Return Value
Function-Definition, Need, Declaration, Definition, Arguments, Return ValueFunction-Definition, Need, Declaration, Definition, Arguments, Return Value
Function-Definition, Need, Declaration, Definition, Arguments, Return Value
 
Introduction to Javascript
Introduction to JavascriptIntroduction to Javascript
Introduction to Javascript
 
C++ oop
C++ oopC++ oop
C++ oop
 
Javascript
JavascriptJavascript
Javascript
 
Control structures in java
Control structures in javaControl structures in java
Control structures in java
 

Similar to Java Language fundamental

Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Ayes Chinmay
 
4java Basic Syntax
4java Basic Syntax4java Basic Syntax
4java Basic SyntaxAdil Jafri
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentalsHCMUTE
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iiiNiraj Bharambe
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and ClassesIntro C# Book
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)Chhom Karath
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECSreedhar Chowdam
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lecturesMSohaib24
 
Computer java programs
Computer java programsComputer java programs
Computer java programsADITYA BHARTI
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introductioncaswenson
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIjagriti srivastava
 

Similar to Java Language fundamental (20)

Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
Internet and Web Technology (CLASS-16) [Basic Elements of Java Program] | NIC...
 
Java 5 and 6 New Features
Java 5 and 6 New FeaturesJava 5 and 6 New Features
Java 5 and 6 New Features
 
4java Basic Syntax
4java Basic Syntax4java Basic Syntax
4java Basic Syntax
 
Pattern Matching in Java 14
Pattern Matching in Java 14Pattern Matching in Java 14
Pattern Matching in Java 14
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Core java pract_sem iii
Core java pract_sem iiiCore java pract_sem iii
Core java pract_sem iii
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
Introduction to Java Programming Part 2
Introduction to Java Programming Part 2Introduction to Java Programming Part 2
Introduction to Java Programming Part 2
 
CH1 ARRAY (1).pptx
CH1 ARRAY (1).pptxCH1 ARRAY (1).pptx
CH1 ARRAY (1).pptx
 
Chapter i(introduction to java)
Chapter i(introduction to java)Chapter i(introduction to java)
Chapter i(introduction to java)
 
What is new in Java 8
What is new in Java 8What is new in Java 8
What is new in Java 8
 
Java
JavaJava
Java
 
Jvm a brief introduction
Jvm  a brief introductionJvm  a brief introduction
Jvm a brief introduction
 
Java Notes
Java Notes Java Notes
Java Notes
 
Java Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPRECJava Notes by C. Sreedhar, GPREC
Java Notes by C. Sreedhar, GPREC
 
Core java
Core javaCore java
Core java
 
object oriented programming java lectures
object oriented programming java lecturesobject oriented programming java lectures
object oriented programming java lectures
 
Computer java programs
Computer java programsComputer java programs
Computer java programs
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 

Recently uploaded

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphThiyagu K
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxSayali Powar
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdfQucHHunhnh
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxmanuelaromero2013
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 

Recently uploaded (20)

Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Z Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot GraphZ Score,T Score, Percential Rank and Box Plot Graph
Z Score,T Score, Percential Rank and Box Plot Graph
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptxPOINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
POINT- BIOCHEMISTRY SEM 2 ENZYMES UNIT 5.pptx
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
How to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptxHow to Make a Pirate ship Primary Education.pptx
How to Make a Pirate ship Primary Education.pptx
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 

Java Language fundamental

  • 1. Control Statements Language Fundamental Command Line Arguments 1 www.infoviaan.com
  • 2. Command Line Argument Animal Human public class CommandLineArgument { public static void main(String args[]) { System.out.println(“Hello ” +args[0]); } } Compile : - javac CommandLineArgument.java Run:- java CommandLineArgument info viaan Lecture class args[0] args[1] args[2] Output:- Hello info Run:- java CommandLineArgument “info viaan” Lecture class args[0] args[1] 2 www.infoviaan.com
  • 3. Command Line Argument Animal Human public class NoOfArg { public static void main(String ar[]) { System.out.println(“You passed total no. of arguments: ”+ar.length); } } Compile : - javac NoOfArg.java Run:- java NoOfArg Hello I am good 1 2 3 4 Output:- You passed total no. of arguments: 4 3 www.infoviaan.com
  • 4. Control Statements Animal • Control the flow of program Control Statements Decision Making Statements Looping Statements if else Ladder if else Nested if else Switch case do...while for while for each 4 www.infoviaan.com
  • 5. Program - if else • An if statement can be followed by an optional else statement, which executes when the Boolean expression is false. public class TestIfElse { public static void main(String[] args) { int age = Integer.parseInt(args[0]); if (age > 17) System.out.println("You are Eligibe for Vote :)"); else System.out.println("Sorry! You Are not eligible :("); } } 5 www.infoviaan.com
  • 6. Program - Nested if..else public class Nested { public static void main(String[] args) { int a, b, c; a = 113; b = 88; c = 95; if (a > b) { if (a > c) { System.out.println("A is biggest " + a); } else { System.out.println("C is boggest " + c); } } else { if (b > c) System.out.println("B is biggest " + b); else System.out.println("C is Biggest " + c); } } } 6 www.infoviaan.com
  • 7. Switch statement • A switch statement allows a variable to be tested for equality against a list of values. • Each value is called a case, and the variable being switched on is checked for each case. 7 www.infoviaan.com
  • 8. Program - Switch public class Switch { public static void main(String[] args) { int i = 2; switch (i) { case 1: System.out.println(“Addition"); break; case 2:System.out.println(“Subtraction"); break; case 3:System.out.println(“Mulplication"); break; default: System.out.println(“Not Available"); } } } 8 www.infoviaan.com
  • 9. Program - Switch with String (Java 5)public class Switch { public static void main(String[] args) { String c = “Ram"; switch (c) { case “Ram":System.out.println(“Lord"); break; case "Shani": System.out.println(“Dev"); break; case “RamDev“: System.out.println(“BaBa"); break; default: System.out.println(“People"); } } } 9 www.infoviaan.com
  • 10. Loop • while - allows code to be executed repeatedly based on a given Boolean condition • do...while - executes a block of code at least once, and then repeatedly executes the block, or not, depending on a given boolean condition at the end of the block • for – it specifying iteration, which allows code to be executed repeatedly • for each (java 5) - used to access each successive value in a collection of values. Arrays and Collections 10 www.infoviaan.com
  • 12. Program - While Loop public class TestWhile { public static void main(String[] args) { int i = 1; while (i <= 5) { System.out.println("Hello "+i); i++; } } } 12 www.infoviaan.com
  • 14. Program – do While Loop public class TestDo { public static void main(String[] args) { int i = 1; do { System.out.println("Hello " + i); i++; } while (i <= 5); } } 14 www.infoviaan.com
  • 16. Program - for Loop public class TestForLoop { public static void main(String[] args) { int n = 4; int fact = 1; for (int i = 1; i <= n; i++) { fact = fact * i; } System.out.println("Factorial Value is = " + fact); } } 16 www.infoviaan.com
  • 19. Nested Loop • A nested loop is a (inner) loop that appears in the loop body of another (outer) loop. • The inner or outerloop can be any type: while, do while, or for. • For example, the inner loop can be a while loop while an outer loop can be a for loop. Of course, they can be the same kind of loops too. 19 www.infoviaan.com
  • 20. Programs - Nested Loop public class TestNestedLoop { public static void main(String[] args) { for (int i = 1; i <= 5; i++) { for (int j = 1; j <= i; j++) { System.out.print("*"); } System.out.println(); } } } 20 www.infoviaan.com
  • 21. For each Loop(java 5) • Access value directly from array or collection. for(type variable : array){ //statement } Program : - public class TestForEach{ public static void main(String[] args) { int ar[]= {10,20,30,40,50}; for (int i : ar) { System.out.println(i); } } } 21 www.infoviaan.com
  • 22. Array Animal Human • An array is a container object that holds a fixed number of values of a single type. • It’s reference data type, which contain 2 byte memory for holding address • Advantages: • Contiguous memory allocation • Collection of similar data types • Limitations: • Can’t store dissimilar data types • Not resizable 22 www.infoviaan.com
  • 23. Declare an Array Animal Human 1. int x[] = {10,20,30,40,50}; //memory allocate at compile time 2. int x[] = new int[5]; 3. int x[] = new int[]{10,20,30,40,50}; //memory allocate at runtime • Which one is better to use? Knows the elements - 3 Don't know the elements -2 23 www.infoviaan.com
  • 24. One-D Array Animal Human int a[] = new int[9]; a[0] = 10; a[1] = 20; ….. a[8] = 90; or int a[] = {10, 20, 30, 40, 50, 60, 70, 80, 90}; int size = a.length; a[0] a[1] a[2] a[3] a[4] a[5] a[6] a[7] a[8] 1000 1000 10 20 30 40 50 60 70 80 90 4 B 2 B 24 www.infoviaan.com
  • 25. One-D Array Animal char c[] = new char[7]; c[0] = ‘A’; c[1] = ‘V’; … Or char c[] = {‘A’, ’V’, ’R’, ’T’, ’E’, ’T’, ’P’}; String names[] = new String[5]; name[0] = “Ram”; name[1] = “Lakhan”; … Or String names[] = {“Ram”, ”Lakhan”, ”Sita”, “Hanuman”, “Ramayana”}; 25 www.infoviaan.com
  • 26. Programs – One_D_Array public class TestOneDArray { public static void main(String[] args) { char ar[]= {'X','Y','Z','A','@'}; for (char c : ar) { System.out.println(c); } } } 26 www.infoviaan.com
  • 27. Copy an Array Animal • To copy an arrays value to another use System.ArrayCopy() method, which take 5 arguments. System.ArrayCopy(copyFrom, 2, copyTo, 0, 5); Start index Start index No. of elements 27 www.infoviaan.com
  • 28. Programs – Copy Array public class TestArrayCopy { public static void main(String[] args) { char cf[] = { 'X', 'Y', 'Z', 'A', 'W' }; char ct[] = new char[4]; System.arraycopy(cf, 1, ct, 0, 4); System.out.println(ct); } } 28 www.infoviaan.com
  • 30. Array of Array/ 2D array Animal Human Two types • Square Array • Zagged Array 1. int x[][]={ {10,20,30}, {10}, {10,20} }; 2. int x[][]=new int[3][]; 3. int x[][]=new int[][] { {10,20,30}, {10}, {10,20} }; 30 www.infoviaan.com
  • 33. Programs - TwoDArray public class TestTwoD { public static void main(String[] args) { int x[][] = { { 12, 23, 67, 89 }, { 89, 78, 67 }, { 12, 34, 78 } }; int i=0; while(i<x.length) { int j=0; while(j<x[i].length) { System.out.print(x[i][j]+" "); j++; } System.out.println(); i++; } } } 33 www.infoviaan.com
  • 35. QA 1. What is difference between while and do..while loop? 2. Switch case work with which of the followings. Byte,short,int,long,float,double,String 3. Difference between for in and for loop. 4. What happens when we forget to put a break statement in a case clause of a switch? 5. Which method is given parameter via command line arguments? 6. How many arguments can be passed to main()? 7. Which loop will execute the body of loop even when condition controlling the loop is initially false? 8. Which of the jump statements can skip processing remainder of code in its body for a particular iteration? 9. Why java uses String array as command Line Argument? 35 www.infoviaan.com
  • 36. QA 1. What is the index of Brighton in the following array? String[] skiResorts = { "Whistler Blackcomb", "Squaw Valley", "Brighton", "Snowmass", "Sun Valley", "Taos" }; 2. Write an expression that refers to the string Brighton within the array. 3. What is the value of the expression skiResorts.length? 4. What is the index of the last item in the array? 5. What is the value of the expression skiResorts[4]? 36 www.infoviaan.com
  • 37. Module Project 1 Ross is an event organizer. He has received data regarding the participation of employees in two different events. Some employees have participated in only one event and others have participated in both events. Ross now needs to count the number of employees who have taken part in both events. The records received by Ross consist of employee ids, which are unique. Write a program that accepts the employee ids participating in each event (the first line relates to the first event and the second line relates to the second event). The program should print the number of common employee ids in both the events. Suppose the following input is given to the program, where each line represents a different event: 1001,1002,1003,1004,1005 1106,1008,1005,1003,1016,1017,1112 Now the common employee ids are 1003 and 1005, so the program should give the output as: 2 www.infoviaan.com
  • 38. Module Project 2 Write a java code to find the distance from Mumbai to major cities of India. Hint: Create an String array of major cities and integer array of distances. User gives the city name and the same is searched in the respective array and displays result. www.infoviaan.com
  • 39. Get in Touch Thank You www.infoviaan.com 39 www.infoviaan.com