SlideShare une entreprise Scribd logo
1  sur  20
Core Java




Presenting overview of core java




     Presented by
     Uday Sharma                   1
Agenda

•   Try-Catch
•   Read Input from Keyboard
•   Control Flow
•   Looping
•   Array
•   Exercises
•   Inheritance
•   Overriding
•   Abstract
•   Interface
•   Packages
•   Project work


                                  2
Try-catch block

Try – catch block is useful to try statement or syntax if
there is any error catch block will handle exception
Syntax                                   Exception
try                                      int a=10;
{                                        int b=0;
                                         int c;
// Body--------------
                                         try{
}                                        c = a/b;
catch(Exception e)                       }
{                                        catch(Exception e)
// Body------------                      {
                                         System.out.println(e);
}
                                         }
                                                                  3
Read Integer Input
                     From Keyboard
try
{
int a;
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Enter value of a= ");
a = Integer.parseInt(br.readLine());
//float y = Float.parseFloat(stdin.readLine());-- For float
}
catch(Exception e){}


                                                              4
Read String Input
                      From Keyboard
try{
 while( (strLine = br.readLine()) != null)
 { if(strLine.equals("exit"))
    break;
   System.out.println("Line entered : " + strLine);
 }
  br.close();
 }
 catch(Exception e)
 {
 System.out.println("Error while reading line from console : " + e);
 }
                                                                       5
Control flow statement

• IF- ELSE        boolean blnStatus = true;
Syntax
 if() {             if(blnStatus==true) {
   body;            System.out.println("Status is true");
 }                  }
                    else {
 else {
                    System.out.println("Status is false");
   body;            }
 }




                                                             6
Nested if else

• IF- ELSE       int printOption =1;
Syntax           int scanOption =2;
                 int copyOption =3;
  if() {         int value = 1;
    body;            if(value==1) {
  }                  System.out.println(“Priting…..");
                     }
 else if() {        else if(value==2){
  body;              System.out.println(“Scanning…..");
                    }
 }                  else if(value==3){
 else {              System.out.println(“copyOption");
                    }
    body;          else {
  }                 System.out.println(“Machine either in
                 idle stage or switch off");
                     }                                      7
For Loop

Syntax
for( <initialization> ; <condition> ; <statement> ){
     <Block of statements>;
}

Example
for(int i=0 ; i < 5 ; i++)
{
     System.out.println(“i is : “ + i);
}


                                                       8
For loop example

• Build pyramid
*
**
***
****
*****
• Build pyramid 2
*****
****
***
**
*


                                       9
Group work

• Pyramid 3   • Numeric pyramid
   *             1
   **            12
   ***           123
   ****          1234
   *****         12345
   *****
   ****
   ***
   **
   *

                                  10
While loop

syntax
while(<boolean condition>){
     <Block of statements>;
 }

Example
 while(i < 5)
  {
    System.out.println("i is : " + i);
    i++;
  }

                                           11
Do while loop

Syntax
Do{
    <Block of statements>;
}while(<boolean condition>);

Example
 do
  {
    System.out.println("i is : " + i);
    i++;
  }while(i < 5);

                                              12
Switch Statement

Syntax
                            The switch statement is Java’s
switch (expression)
                            multiway branch statement. It
{                           provides an easy way to dispatch
case value 1 :              execution to different parts of
statement 1 ; break;        your code based on the value of
...                         an expression.
case value N :
statement N ; break;
default :
statements ; break;
}

                                                          13
Array in Java

Syntax
dataType[] arrayRefVar = new dataType[arraySize];
dataType[] arrayRefVar = {value0, value1, ..., valuek};
Example
Double[] myList = new double[10];




                                                          14
Design car

• Design car parts 4 tyre (1- 2 front tyre and 3-4 back
  tyre), 4 doors (1- 2 front doors and 3-4 back doors), 4
  headlight (2 front light and 2 break light), 1 body, 2
  Glass (front and rear glass), 1 Mirror, 4 seat (2 front
  seat (Left is driver seat), and 2 back seat) .




                                                            15
Java Exampe

Make saperate class for below mentioned all functionality
and attach all classes using interitance.
Note : Make super class Area with 2 memeber variable and
extend it another classes.

             Triangle
                                               Square
         Area = ½ × b × h
                                              Area = a2
             b = base
                                         a = length of side
        h = vertical height
            Rectangle                     Parallelogram
           Area = w × h                    Area = b × h
            w = width                        b = base
            h = height                  h = vertical height
                                                              16
Java Overriding

• The benefit of overriding is: ability to define a
  behavior that's specific to the sub class type. Which
  means a subclass can implement a parent calss
  method based on its requirement.
• In object oriented terms, overriding means to
  override the functionality of any existing method.




                                                          17
Animal Example




                 18
Class Name: Animal
hasEye

+Leg()
+Run()
+Jump()
+eye()
+Body()




                     19
Class Name: Girrafe
hasLeg
hasTail
hasColor
hasHeight
+Leg(hasLeg)
+Run()
+eye()
+Tail(hasTail)
+Body(hasColor,hasHeight)




                            20

Contenu connexe

Tendances

Test-driven development for TYPO3 (T3DD11)
Test-driven development for TYPO3 (T3DD11)Test-driven development for TYPO3 (T3DD11)
Test-driven development for TYPO3 (T3DD11)Oliver Klee
 
Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Sergey Platonov
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introductioncaswenson
 
Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Sergey Platonov
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVMRafael Winterhalter
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++Seok-joon Yun
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptSeok-joon Yun
 
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performanceRafael Winterhalter
 
Metaprogramming in julia
Metaprogramming in juliaMetaprogramming in julia
Metaprogramming in julia岳華 杜
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agentsRafael Winterhalter
 
модели акторов в с++ миф или реальность
модели акторов в с++ миф или реальностьмодели акторов в с++ миф или реальность
модели акторов в с++ миф или реальностьcorehard_by
 
Javascript basics
Javascript basicsJavascript basics
Javascript basicsFin Chen
 
Алексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуляАлексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуляSergey Platonov
 
Programming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
Programming Java - Lection 07 - Puzzlers - Lavrentyev FedorProgramming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
Programming Java - Lection 07 - Puzzlers - Lavrentyev FedorFedor Lavrentyev
 
20171127 當julia遇上資料科學
20171127 當julia遇上資料科學20171127 當julia遇上資料科學
20171127 當julia遇上資料科學岳華 杜
 

Tendances (20)

Test-driven development for TYPO3 (T3DD11)
Test-driven development for TYPO3 (T3DD11)Test-driven development for TYPO3 (T3DD11)
Test-driven development for TYPO3 (T3DD11)
 
Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++Kirk Shoop, Reactive programming in C++
Kirk Shoop, Reactive programming in C++
 
Learning Java 1 – Introduction
Learning Java 1 – IntroductionLearning Java 1 – Introduction
Learning Java 1 – Introduction
 
Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++Антон Нонко, Классические строки в C++
Антон Нонко, Классические строки в C++
 
Joel Falcou, Boost.SIMD
Joel Falcou, Boost.SIMDJoel Falcou, Boost.SIMD
Joel Falcou, Boost.SIMD
 
A topology of memory leaks on the JVM
A topology of memory leaks on the JVMA topology of memory leaks on the JVM
A topology of memory leaks on the JVM
 
Clang tidy
Clang tidyClang tidy
Clang tidy
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
Pro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScriptPro typescript.ch03.Object Orientation in TypeScript
Pro typescript.ch03.Object Orientation in TypeScript
 
An introduction to JVM performance
An introduction to JVM performanceAn introduction to JVM performance
An introduction to JVM performance
 
Metaprogramming in julia
Metaprogramming in juliaMetaprogramming in julia
Metaprogramming in julia
 
The definitive guide to java agents
The definitive guide to java agentsThe definitive guide to java agents
The definitive guide to java agents
 
E:\Plp 2009 2\Plp 9
E:\Plp 2009 2\Plp 9E:\Plp 2009 2\Plp 9
E:\Plp 2009 2\Plp 9
 
Oop 1
Oop 1Oop 1
Oop 1
 
Java generics final
Java generics finalJava generics final
Java generics final
 
модели акторов в с++ миф или реальность
модели акторов в с++ миф или реальностьмодели акторов в с++ миф или реальность
модели акторов в с++ миф или реальность
 
Javascript basics
Javascript basicsJavascript basics
Javascript basics
 
Алексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуляАлексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуля
 
Programming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
Programming Java - Lection 07 - Puzzlers - Lavrentyev FedorProgramming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
Programming Java - Lection 07 - Puzzlers - Lavrentyev Fedor
 
20171127 當julia遇上資料科學
20171127 當julia遇上資料科學20171127 當julia遇上資料科學
20171127 當julia遇上資料科學
 

Similaire à Core java (20)

Java introduction
Java introductionJava introduction
Java introduction
 
2. overview of c#
2. overview of c#2. overview of c#
2. overview of c#
 
Synapseindia reviews.odp.
Synapseindia reviews.odp.Synapseindia reviews.odp.
Synapseindia reviews.odp.
 
Java Tutorial | My Heart
Java Tutorial | My HeartJava Tutorial | My Heart
Java Tutorial | My Heart
 
Java tut1
Java tut1Java tut1
Java tut1
 
Java tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo CahersiveenJava tut1 Coderdojo Cahersiveen
Java tut1 Coderdojo Cahersiveen
 
Java tut1
Java tut1Java tut1
Java tut1
 
Javatut1
Javatut1 Javatut1
Javatut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Java tutorials
Java tutorialsJava tutorials
Java tutorials
 
Java tut1
Java tut1Java tut1
Java tut1
 
Tutorial java
Tutorial javaTutorial java
Tutorial java
 
Java Tut1
Java Tut1Java Tut1
Java Tut1
 
Java Tutorial
Java TutorialJava Tutorial
Java Tutorial
 
Repetition Structure
Repetition StructureRepetition Structure
Repetition Structure
 
Java fundamentals
Java fundamentalsJava fundamentals
Java fundamentals
 
Sam wd programs
Sam wd programsSam wd programs
Sam wd programs
 
JPC#8 Introduction to Java Programming
JPC#8 Introduction to Java ProgrammingJPC#8 Introduction to Java Programming
JPC#8 Introduction to Java Programming
 
02 - Prepcode
02 - Prepcode02 - Prepcode
02 - Prepcode
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 

Plus de Uday Sharma

Tftp client server communication
Tftp client server communicationTftp client server communication
Tftp client server communicationUday Sharma
 
Wat question papers
Wat question papersWat question papers
Wat question papersUday Sharma
 
Fundamentals of java --- version 2
Fundamentals of java --- version 2Fundamentals of java --- version 2
Fundamentals of java --- version 2Uday Sharma
 
Exercises of java tutoring -version1
Exercises of java tutoring -version1Exercises of java tutoring -version1
Exercises of java tutoring -version1Uday Sharma
 
Java tutor oo ps introduction-version 1
Java tutor  oo ps introduction-version 1Java tutor  oo ps introduction-version 1
Java tutor oo ps introduction-version 1Uday Sharma
 
Logistics final prefinal
Logistics final prefinalLogistics final prefinal
Logistics final prefinalUday Sharma
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel ProgrammingUday Sharma
 
Making Rules Project Management
Making Rules  Project ManagementMaking Rules  Project Management
Making Rules Project ManagementUday Sharma
 
Intelligent Weather Service
Intelligent Weather Service Intelligent Weather Service
Intelligent Weather Service Uday Sharma
 
India presentation
India presentationIndia presentation
India presentationUday Sharma
 

Plus de Uday Sharma (11)

Tftp client server communication
Tftp client server communicationTftp client server communication
Tftp client server communication
 
Wat question papers
Wat question papersWat question papers
Wat question papers
 
Fundamentals of java --- version 2
Fundamentals of java --- version 2Fundamentals of java --- version 2
Fundamentals of java --- version 2
 
Exercises of java tutoring -version1
Exercises of java tutoring -version1Exercises of java tutoring -version1
Exercises of java tutoring -version1
 
Java tutor oo ps introduction-version 1
Java tutor  oo ps introduction-version 1Java tutor  oo ps introduction-version 1
Java tutor oo ps introduction-version 1
 
Logistics final prefinal
Logistics final prefinalLogistics final prefinal
Logistics final prefinal
 
Presentation1
Presentation1Presentation1
Presentation1
 
Parallel Programming
Parallel ProgrammingParallel Programming
Parallel Programming
 
Making Rules Project Management
Making Rules  Project ManagementMaking Rules  Project Management
Making Rules Project Management
 
Intelligent Weather Service
Intelligent Weather Service Intelligent Weather Service
Intelligent Weather Service
 
India presentation
India presentationIndia presentation
India presentation
 

Dernier

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxpboyjonauth
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppCeline George
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
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
 
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
 
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
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
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
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 

Dernier (20)

Introduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptxIntroduction to AI in Higher Education_draft.pptx
Introduction to AI in Higher Education_draft.pptx
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
URLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website AppURLs and Routing in the Odoo 17 Website App
URLs and Routing in the Odoo 17 Website App
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
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
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
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
 
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
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 

Core java

  • 1. Core Java Presenting overview of core java Presented by Uday Sharma 1
  • 2. Agenda • Try-Catch • Read Input from Keyboard • Control Flow • Looping • Array • Exercises • Inheritance • Overriding • Abstract • Interface • Packages • Project work 2
  • 3. Try-catch block Try – catch block is useful to try statement or syntax if there is any error catch block will handle exception Syntax Exception try int a=10; { int b=0; int c; // Body-------------- try{ } c = a/b; catch(Exception e) } { catch(Exception e) // Body------------ { System.out.println(e); } } 3
  • 4. Read Integer Input From Keyboard try { int a; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Enter value of a= "); a = Integer.parseInt(br.readLine()); //float y = Float.parseFloat(stdin.readLine());-- For float } catch(Exception e){} 4
  • 5. Read String Input From Keyboard try{ while( (strLine = br.readLine()) != null) { if(strLine.equals("exit")) break; System.out.println("Line entered : " + strLine); } br.close(); } catch(Exception e) { System.out.println("Error while reading line from console : " + e); } 5
  • 6. Control flow statement • IF- ELSE boolean blnStatus = true; Syntax if() { if(blnStatus==true) { body; System.out.println("Status is true"); } } else { else { System.out.println("Status is false"); body; } } 6
  • 7. Nested if else • IF- ELSE int printOption =1; Syntax int scanOption =2; int copyOption =3; if() { int value = 1; body; if(value==1) { } System.out.println(“Priting….."); } else if() { else if(value==2){ body; System.out.println(“Scanning….."); } } else if(value==3){ else { System.out.println(“copyOption"); } body; else { } System.out.println(“Machine either in idle stage or switch off"); } 7
  • 8. For Loop Syntax for( <initialization> ; <condition> ; <statement> ){ <Block of statements>; } Example for(int i=0 ; i < 5 ; i++) { System.out.println(“i is : “ + i); } 8
  • 9. For loop example • Build pyramid * ** *** **** ***** • Build pyramid 2 ***** **** *** ** * 9
  • 10. Group work • Pyramid 3 • Numeric pyramid * 1 ** 12 *** 123 **** 1234 ***** 12345 ***** **** *** ** * 10
  • 11. While loop syntax while(<boolean condition>){ <Block of statements>; } Example while(i < 5) { System.out.println("i is : " + i); i++; } 11
  • 12. Do while loop Syntax Do{ <Block of statements>; }while(<boolean condition>); Example do { System.out.println("i is : " + i); i++; }while(i < 5); 12
  • 13. Switch Statement Syntax The switch statement is Java’s switch (expression) multiway branch statement. It { provides an easy way to dispatch case value 1 : execution to different parts of statement 1 ; break; your code based on the value of ... an expression. case value N : statement N ; break; default : statements ; break; } 13
  • 14. Array in Java Syntax dataType[] arrayRefVar = new dataType[arraySize]; dataType[] arrayRefVar = {value0, value1, ..., valuek}; Example Double[] myList = new double[10]; 14
  • 15. Design car • Design car parts 4 tyre (1- 2 front tyre and 3-4 back tyre), 4 doors (1- 2 front doors and 3-4 back doors), 4 headlight (2 front light and 2 break light), 1 body, 2 Glass (front and rear glass), 1 Mirror, 4 seat (2 front seat (Left is driver seat), and 2 back seat) . 15
  • 16. Java Exampe Make saperate class for below mentioned all functionality and attach all classes using interitance. Note : Make super class Area with 2 memeber variable and extend it another classes. Triangle Square Area = ½ × b × h Area = a2 b = base a = length of side h = vertical height Rectangle Parallelogram Area = w × h Area = b × h w = width b = base h = height h = vertical height 16
  • 17. Java Overriding • The benefit of overriding is: ability to define a behavior that's specific to the sub class type. Which means a subclass can implement a parent calss method based on its requirement. • In object oriented terms, overriding means to override the functionality of any existing method. 17