module 1 - executing your first java application

Upload: arif-rakhman

Post on 04-Jun-2018

223 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/13/2019 Module 1 - Executing Your First Java Application

    1/25

    Java Programming Language

    Java Programming Language

    SL-275-SE6

  • 8/13/2019 Module 1 - Executing Your First Java Application

    2/25

    Java Programming Language

    Module 1

    Executing Your First Java Application

  • 8/13/2019 Module 1 - Executing Your First Java Application

    3/25

    Java Programming Language Module 1, slide 2 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Objectives

    Examine the Java Development Kit (JDK) software

    Examine Java application loading and executing Create a simple Java application

  • 8/13/2019 Module 1 - Executing Your First Java Application

    4/25

    Java Programming Language Module 1, slide 3 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Examining the JDK Software

    The JDK contains components to perform the following tasks:

    Develop Java technology applications Deploy Java technology applications

    Execute Java technology applications

    JDK

    Java Programming Language

    Tools and Tools API

    Java SE Libraries

    Deployment Technologies

    Platform Specific JVMs

    Applicationdevelopment

    Applicationdeployment

    Applicationexecution

  • 8/13/2019 Module 1 - Executing Your First Java Application

    5/25

    Java Programming Language Module 1, slide 4 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Components of the JDK

    The Java programming language

    Tools and tools API Deployment technologies

    Java Platform, Standard Edition (Java SE) libraries

    Java Virtual Machine (JVM)Strictly speaking the Java programming language is not acomponent of the JDK software. Nevertheless, for thepurposes of providing a more complete discussion, it is

    treated as a pseudo component.

    Download URL:http://java.sun.com/javase/downloads/index.jsp

  • 8/13/2019 Module 1 - Executing Your First Java Application

    6/25

    Java Programming Language Module 1, slide 5 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Examining the JDK Support for DevelopingJava Technology Applications

    The Java programming language The JDK tools

    The JDK libraries

  • 8/13/2019 Module 1 - Executing Your First Java Application

    7/25

    Java Programming Language Module 1, slide 6 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    The Java Programming Language

    The Java programming language is a general-purpose,concurrent, strongly typed, class-based object-orientedlanguage.

    The Java programming language is defined by theJavalanguage specification.

    The primary building block of a Java technologyapplication is aclass.

  • 8/13/2019 Module 1 - Executing Your First Java Application

    8/25

    Java Programming Language Module 1, slide 7 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Example of a Java Technology Class

    1 package trader;2 import java.io.Serializable;

    3 public class Stock implements Serializable {4 private String symbol;5 private float price;67 public Stock(String symbol, float price){8 this.symbol = symbol;

    9 this.price = price;10 }1112 // Methods to return the private values of this object13 public String getSymbol() {14 return symbol;15 }1617 public float getPrice() {18 return price;19 }

  • 8/13/2019 Module 1 - Executing Your First Java Application

    9/25

    Java Programming Language Module 1, slide 8 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Example of a Java Technology Class

    2021 public void setPrice(float newPrice) {

    22 price = newPrice;23 }2425 public String toString() {26 return "Stock: " + symbol + " " + price;27 }

    28 }

  • 8/13/2019 Module 1 - Executing Your First Java Application

    10/25

    Java Programming Language Module 1, slide 9 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    The JDK Tools and Tools API

  • 8/13/2019 Module 1 - Executing Your First Java Application

    11/25

    Java Programming Language Module 1, slide 10 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Basic Tools

    Tool Name Function

    javac The compiler for the Java programming languagejava The launcher for Java technology applications

    jdb The Java debugger

    javadoc The API document generator

    jar Java Archive (JAR) file creator and management tool

  • 8/13/2019 Module 1 - Executing Your First Java Application

    12/25

    Java Programming Language Module 1, slide 11 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Advanced Tools

    Tool Category Comments

    Security tools Implement security policies in applicationsInternationalizationtools

    Enable applications to be localized

    Remote methodinvocation (RMI) tools

    Create (network) distributed applications

    Common object requestbroker architecture(CORBA) tools

    Create network applications that are based on CORBAtechnology

    Java deployment tools Support application deployment

    Java Plug-in tools Provide utilities for use with the Java Plug-in

    Java web start tools Used with Java web start technology

  • 8/13/2019 Module 1 - Executing Your First Java Application

    13/25

    Java Programming Language Module 1, slide 12 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Advanced Tools

    Tool Category Comments

    Java Monitoring andManagement (JMX)console

    Used in conjunction with JMX technology

    Java web services tools Support Java web service application development

    Experimental tools Might not be available with future releases of the JavaSE JDK

  • 8/13/2019 Module 1 - Executing Your First Java Application

    14/25

    Java Programming Language Module 1, slide 13 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    JDK Libraries

  • 8/13/2019 Module 1 - Executing Your First Java Application

    15/25

    Java Programming Language Module 1, slide 14 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    JDK Libraries

    Library Name Sample Classes in Library

    java.lang Enum, Float, String, Objectjava.util ArrayList, Calendar, Date

    java.io File, Reader, Writer

    java.math BigDecimal, BigInteger

    java.text DateFormat, Collatorjavax.crypto Cipher, KeyGenerator

    java.net Socket, URL, InetAddress

    java.sql ResultSet, Date, Timestamp

    javax.swing JFrame, JPanel

    javax.xml.parsers DocumentBuilder, SAXParser

  • 8/13/2019 Module 1 - Executing Your First Java Application

    16/25

    Java Technology APIDocumentation

  • 8/13/2019 Module 1 - Executing Your First Java Application

    17/25

    Java Programming Language Module 1, slide 16 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    JDK Deployment Technologies

  • 8/13/2019 Module 1 - Executing Your First Java Application

    18/25

    Java Programming Language Module 1, slide 17 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    The Java Virtual Machine (JVM)

    What is a JVMimplementation?

    Are JVM implementations platform dependent?

    Are Java technology applications platform dependent?

    What is a Java Hotspot JVM implementation?

    What is a Java Hotspot client JVM implementation?

    What is a Java Hotspot server JVM implementation?

    Java Technology Application

    JVM

    OS

    Hardware Platform

  • 8/13/2019 Module 1 - Executing Your First Java Application

    19/25

    Java Programming Language Module 1, slide 18 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    The JVM: Supported Platforms

  • 8/13/2019 Module 1 - Executing Your First Java Application

    20/25

    Java Programming Language Module 1, slide 19 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    The Java Runtime Environment (JRE)

  • 8/13/2019 Module 1 - Executing Your First Java Application

    21/25

    Java Programming Language Module 1, slide 20 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Examining Java Technology ApplicationLoading and Execution

    Compile

    TestGreeting.java

    TestGreeting.class

    javac

    Runtime

    Classloader

    Bytecodeverifier

    Hotspot Execution Engine

    Hardware

    Load fromhard disk,network,

    orother

    source

    java

  • 8/13/2019 Module 1 - Executing Your First Java Application

    22/25

    Java Programming Language Module 1, slide 21 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    A Simple Java Application

    1 //2 // Sample "Hello World" application3 //4 public class TestGreeting {5 public static void main (String[] args) {6 Greeting hello = new Greeting();7 hello.greet();8 }

    9 }

    1 public class Greeting {2 public void greet() {3 System.out.println("hi");4 }

    5 }6

    javac TestGreeting.java

    java TestGreeting

  • 8/13/2019 Module 1 - Executing Your First Java Application

    23/25

    Java Programming Language Module 1, slide 22 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Troubleshooting: Compile-Time Errors

    javac: Command not found

    Greeting.java:4:cannot resolve symbolsymbol : method printl (java.lang.String)location: class java.io.PrintStreamSystem.out.printl("hi");

    ^

    Class and file naming

    Class count

  • 8/13/2019 Module 1 - Executing Your First Java Application

    24/25

    Java Programming Language Module 1, slide 23 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Troubleshooting: Run-Time Errors

    Can't find class TestGreeting

    Exception in thread "main"java.lang.NoSuchMethodError: main

  • 8/13/2019 Module 1 - Executing Your First Java Application

    25/25

    Java Programming Language Module 1, slide 24 of 24Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

    Compiling and Running

    JVM

    Compile

    TestGreeting.java

    TestGreeting.class

    javac

    Greeting.java

    Greeting.class

    Also compiles

    Run

    time

    Also loads

    UNIX

    JVM

    DOS

    JVMJavaOS

    Can run on multiple platforms