SlideShare une entreprise Scribd logo
1  sur  48
Object Oriented Programming with Java
Topic ,[object Object],[object Object],[object Object],[object Object]
C++ vs. Java ,[object Object],[object Object],[object Object],[object Object],[object Object]
C++ vs. Java ,[object Object],√ × API √ × Interface and Package × √ Pointers × √ Header files × √ Global variables × √ Template classes × √ Operator overloading × √ Multiple Inheritance √ √ Single Inheritance Inheritance √ √ Dynamic √ √ Static Binding √ √ Polymorphism √ √ Data abstraction and encapsulation in Java in C++ Features
C++ vs. Java ,[object Object],[object Object],[object Object]
Fundamentals of Java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Tools Available for Java Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Tools Available for Java Programming ,[object Object],[object Object],[object Object],[object Object],[object Object]
Tools Available for Java Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Tools Available for Java Programming ,[object Object],[object Object],[object Object],[object Object],[object Object]
Third Part Tools for Java Programming ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Other Third Part Tools  ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Programming in Java ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Building a Java Application ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How to  edit  this program? ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
How to  compile  this program? ,[object Object],[object Object],[object Object],[object Object],[object Object]
How to  compile  this program? ,[object Object],[object Object],[object Object]
How to  execute  this program? ,[object Object],[object Object],[object Object],[object Object]
Building a Java Application
Building a Java Application Step 1: Edit and Save
Building a Java Application Step 1: Edit and Save
Building a Java Application Step 1: Edit and Save
Building a Java Application Step 1: Edit and Save
Building a Java Application Step 2: Compile
Building a Java Application Step 2: Compile
Building a Java Application Step 3: Execute
Building a Java Applet ,[object Object]
Building a Java Applet ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Building a Java Applet   Edit  ->  Save  ->  Compile ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Building a Java Applet   Execution ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],<applet code = HelloJava.class width = 200 height = 100> </applet>
More on Java Application Structure of a Java Application ,[object Object],[object Object],[object Object],[object Object],[object Object],// Hello Java Application // class  HelloWorldApp {   public static void   main ( String args[ ] )  {   System.out.println  (&quot;Hello  Java !&quot;);    } }
General Structure of an Application
Example: Square Root Calculation /* * One more simple Java Application * * This application computes square root * */ // This is also a comment (one line comment) import java.lang.Math; class SquareRoot  { public static void main (String args[ ]) { double x = 45;  // Variable declaration and initialization   double y;   // Declaration of another variable   y = Math.sqrt (x);   System.out.println(&quot;Square root of &quot;+ x +&quot;=&quot; + y); } }
Application with Multiple Classes // Application with more than one classes  //  class FirstClass {    intidNo;   iIdNo = 555;   public static void print(  ) {    System.out.println ( &quot; First Class citizen&quot;  + idNo );    } } class SecondClass {    int idNo;   idNo = 111;   public startic void print(  ) {   System.out.println ( &quot; Second Class citizen &quot; + idNo) ;   } }
Application with Multiple Classes (contd..) public class PeopleAppln {   FirstClass female;   SecondClass male;   public static void main( String args[ ] ) {   System.out.print(&quot;People from Java World&quot;);   female.print( );   male.print( );   } }
Application without any Class! // Edit the following program as HelloNoClass.java public static void main (String args[ ] ) {   System.out.println( &quot;Hello Classless Java!]); } Type following two commands to run the Hello.java Application : javac HelloNoClass.java // To compile java  HelloNoClass // To run the program
Communication to Java Application ,[object Object],[object Object],[object Object],[object Object]
Command Line Arguments ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Get Input using  DataInputStream
Get Input using  DataInputStream Calculator Program import java.io.*; class InterestCalculator { public static void main(String args[ ] ) {   Float principalAmount = new Float(0);   Float rateOfInterest = new Float(0);   int numberOfYears = 0;     DataInputStream in = new DataInputStream(System.in);   String tempString;   System.out.print(&quot;Enter Principal Amount: &quot;);   System.out.flush();   tempString = in.readLine();   principalAmount = Float.valueOf(tempString);
Calculator Program (contd..)   System.out.print(&quot;Enter Rate of Interest: &quot;);   System.out.flush();   tempString = in.readLine();   rateOfInterest = Float.valueOf(tempString);   System.out.print(&quot;Enter Number of Years: &quot;);   System.out.flush();     tempString = in.readLine();   numberOfYears = Integer.parseInt(tempString);   // Input is over: calculate the interest   int interestTotal = principalAmount*rateOfInterest*numberOfYears;     System.out.println(&quot;Total Interest = &quot; + interestTotal); } }
Applet Revisited ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Structure of an Applet
Basic Methods in Applet ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Example: Use of init( ) // Use of init( ) method in an applet // import java.awt .Graphics ; import java.applet.Applet; public class HelloWorld extends Applet { public void init( ) {   resize(200,200); } public void paint (Graphics g ) {    g.drawString ( &quot; Hello World !&quot;, 50, 25 ); } }
One More Example: Use of init( ) // Use of  init( ) to pass value through HTML to applet // import java.awt . *; import java.applet. * ; public class RectangleTest extends applet { int x, y, w, h;  public void init (  ) {   x  = Integer.parseInt(get Parameter (&quot; xValue&quot; ));   y  = Integer.parseInt(get Parameter (&quot; yValue&quot; ));   w = Integer.parseInt(get Parameter (&quot; wValue&quot; ));   h  = Integer.parseInt(get Parameter (&quot; hValue&quot; ));  }  public void paint ( Graphics g ) {    g.drawRect (x, y, w, h ); } }
One More Example: Use of init( ) Corresponding HTML document containing this applet and providing  parameter values will be : < applet code = &quot; RectangleTest&quot; width = 150  height = 100 >  < param name = xValue  value = 20 >  < param name = yValue  value = 40 >  <param name  = wValue  value = 100> < param name = hValue  value = 50 > < /applet >
Application vs. Applet ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Contenu connexe

Similaire à Javalecture 1

Similaire à Javalecture 1 (20)

Chapter 2.1
Chapter 2.1Chapter 2.1
Chapter 2.1
 
1.introduction to java
1.introduction to java1.introduction to java
1.introduction to java
 
Introduction to java programming part 1
Introduction to java programming   part 1Introduction to java programming   part 1
Introduction to java programming part 1
 
JAVA introduction and basic understanding.pptx
JAVA  introduction and basic understanding.pptxJAVA  introduction and basic understanding.pptx
JAVA introduction and basic understanding.pptx
 
Java platform
Java platformJava platform
Java platform
 
Java lab1 manual
Java lab1 manualJava lab1 manual
Java lab1 manual
 
Unit of competency
Unit of competencyUnit of competency
Unit of competency
 
Curso de Programación Java Básico
Curso de Programación Java BásicoCurso de Programación Java Básico
Curso de Programación Java Básico
 
Introduction
IntroductionIntroduction
Introduction
 
Java introduction
Java introductionJava introduction
Java introduction
 
JAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptxJAVA ALL 5 MODULE NOTES.pptx
JAVA ALL 5 MODULE NOTES.pptx
 
OOPS JAVA.pdf
OOPS JAVA.pdfOOPS JAVA.pdf
OOPS JAVA.pdf
 
Introduction to Software Development
Introduction to Software DevelopmentIntroduction to Software Development
Introduction to Software Development
 
Java introduction
Java introductionJava introduction
Java introduction
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
 
Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)Java Semimar Slide (Cetpa)
Java Semimar Slide (Cetpa)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)Java programming basics notes for beginners(java programming tutorials)
Java programming basics notes for beginners(java programming tutorials)
 
Java basics notes
Java basics notesJava basics notes
Java basics notes
 
INTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATIONINTRODUCTION TO JAVA APPLICATION
INTRODUCTION TO JAVA APPLICATION
 

Dernier

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 

Dernier (20)

Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 

Javalecture 1

  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19. Building a Java Application
  • 20. Building a Java Application Step 1: Edit and Save
  • 21. Building a Java Application Step 1: Edit and Save
  • 22. Building a Java Application Step 1: Edit and Save
  • 23. Building a Java Application Step 1: Edit and Save
  • 24. Building a Java Application Step 2: Compile
  • 25. Building a Java Application Step 2: Compile
  • 26. Building a Java Application Step 3: Execute
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32. General Structure of an Application
  • 33. Example: Square Root Calculation /* * One more simple Java Application * * This application computes square root * */ // This is also a comment (one line comment) import java.lang.Math; class SquareRoot { public static void main (String args[ ]) { double x = 45; // Variable declaration and initialization double y; // Declaration of another variable y = Math.sqrt (x); System.out.println(&quot;Square root of &quot;+ x +&quot;=&quot; + y); } }
  • 34. Application with Multiple Classes // Application with more than one classes // class FirstClass { intidNo; iIdNo = 555; public static void print( ) { System.out.println ( &quot; First Class citizen&quot; + idNo ); } } class SecondClass { int idNo; idNo = 111; public startic void print( ) { System.out.println ( &quot; Second Class citizen &quot; + idNo) ; } }
  • 35. Application with Multiple Classes (contd..) public class PeopleAppln { FirstClass female; SecondClass male; public static void main( String args[ ] ) { System.out.print(&quot;People from Java World&quot;); female.print( ); male.print( ); } }
  • 36. Application without any Class! // Edit the following program as HelloNoClass.java public static void main (String args[ ] ) { System.out.println( &quot;Hello Classless Java!]); } Type following two commands to run the Hello.java Application : javac HelloNoClass.java // To compile java HelloNoClass // To run the program
  • 37.
  • 38.
  • 39. Get Input using DataInputStream
  • 40. Get Input using DataInputStream Calculator Program import java.io.*; class InterestCalculator { public static void main(String args[ ] ) { Float principalAmount = new Float(0); Float rateOfInterest = new Float(0); int numberOfYears = 0; DataInputStream in = new DataInputStream(System.in); String tempString; System.out.print(&quot;Enter Principal Amount: &quot;); System.out.flush(); tempString = in.readLine(); principalAmount = Float.valueOf(tempString);
  • 41. Calculator Program (contd..) System.out.print(&quot;Enter Rate of Interest: &quot;); System.out.flush(); tempString = in.readLine(); rateOfInterest = Float.valueOf(tempString); System.out.print(&quot;Enter Number of Years: &quot;); System.out.flush(); tempString = in.readLine(); numberOfYears = Integer.parseInt(tempString); // Input is over: calculate the interest int interestTotal = principalAmount*rateOfInterest*numberOfYears; System.out.println(&quot;Total Interest = &quot; + interestTotal); } }
  • 42.
  • 43. Structure of an Applet
  • 44.
  • 45. Example: Use of init( ) // Use of init( ) method in an applet // import java.awt .Graphics ; import java.applet.Applet; public class HelloWorld extends Applet { public void init( ) { resize(200,200); } public void paint (Graphics g ) { g.drawString ( &quot; Hello World !&quot;, 50, 25 ); } }
  • 46. One More Example: Use of init( ) // Use of init( ) to pass value through HTML to applet // import java.awt . *; import java.applet. * ; public class RectangleTest extends applet { int x, y, w, h; public void init ( ) { x = Integer.parseInt(get Parameter (&quot; xValue&quot; )); y = Integer.parseInt(get Parameter (&quot; yValue&quot; )); w = Integer.parseInt(get Parameter (&quot; wValue&quot; )); h = Integer.parseInt(get Parameter (&quot; hValue&quot; )); } public void paint ( Graphics g ) { g.drawRect (x, y, w, h ); } }
  • 47. One More Example: Use of init( ) Corresponding HTML document containing this applet and providing parameter values will be : < applet code = &quot; RectangleTest&quot; width = 150 height = 100 > < param name = xValue value = 20 > < param name = yValue value = 40 > <param name = wValue value = 100> < param name = hValue value = 50 > < /applet >
  • 48.