You are on page 1of 25

Java Programming Language

SL-275-SE6

Java Programming Language

Module 1
Executing Your First Java Application

Java Programming Language

Objectives
Examine the Java Development Kit (JDK) software Examine Java application loading and executing Create a simple Java application

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 2 of 24

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
Java Programming Language Tools and Tools API Java SE Libraries Application development Application deployment Application execution

JDK

Deployment Technologies Platform Specific JVMs

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 3 of 24

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 a component of the JDK software. Nevertheless, for the purposes of providing a more complete discussion, it is treated as a pseudo component. Download URL: http://java.sun.com/javase/downloads/index.jsp
Java Programming Language
Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 4 of 24

Examining the JDK Support for Developing Java Technology Applications


The Java programming language The JDK tools The JDK libraries

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 5 of 24

The Java Programming Language


The Java programming language is a general-purpose, concurrent, strongly typed, class-based object-oriented language. The Java programming language is defined by the Java language specication. The primary building block of a Java technology application is a class.

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 6 of 24

Example of a Java Technology Class


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 package trader; import java.io.Serializable; public class Stock implements Serializable { private String symbol; private float price; public Stock(String symbol, float price){ this.symbol = symbol; this.price = price; } // Methods to return the private values of this object public String getSymbol() { return symbol; } public float getPrice() { return price; }

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 7 of 24

Example of a Java Technology Class


20 21 22 23 24 25 26 27 28 public void setPrice(float newPrice) { price = newPrice; } public String toString() { return "Stock: " + symbol + " } }

" + price;

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 8 of 24

The JDK Tools and Tools API

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 9 of 24

Basic Tools
Tool Name
javac java jdb javadoc jar

Function
The compiler for the Java programming language The launcher for Java technology applications The Java debugger The API document generator Java Archive (JAR) le creator and management tool

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 10 of 24

Advanced Tools
Tool Category
Security tools Internationalization tools Remote method invocation (RMI) tools

Comments
Implement security policies in applications Enable applications to be localized Create (network) distributed applications

Common object request Create network applications that are based on CORBA broker architecture technology (CORBA) tools Java deployment tools Java Plug-in tools Java web start tools Support application deployment Provide utilities for use with the Java Plug-in Used with Java web start technology

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 11 of 24

Advanced Tools
Tool Category
Java Monitoring and Management (JMX) console Java web services tools Experimental tools

Comments
Used in conjunction with JMX technology

Support Java web service application development Might not be available with future releases of the Java SE JDK

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 12 of 24

JDK Libraries

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 13 of 24

JDK Libraries
Library Name
java.lang java.util java.io java.math java.text javax.crypto java.net java.sql javax.swing

Sample Classes in Library


Enum, Float, String, Object ArrayList, Calendar, Date File, Reader, Writer BigDecimal, BigInteger DateFormat, Collator Cipher, KeyGenerator Socket, URL, InetAddress ResultSet, Date, Timestamp JFrame, JPanel

javax.xml.parsers DocumentBuilder, SAXParser

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 14 of 24

Java Technology API Documentation

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 15 of 24

JDK Deployment Technologies

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 16 of 24

The Java Virtual Machine (JVM)


What is a JVM implementation?
Java Technology Application

JVM

OS

Hardware Platform

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?
Module 1, slide 17 of 24

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

The JVM: Supported Platforms

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 18 of 24

The Java Runtime Environment (JRE)

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 19 of 24

Examining Java Technology Application Loading and Execution


Compile Runtime java Class loader TestGreeting.java Load from hard disk, network, or other source Bytecode verifier

javac

Hotspot Execution Engine

TestGreeting.class

Hardware

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 20 of 24

A Simple Java Application


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

javac TestGreeting.java java TestGreeting

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 21 of 24

Troubleshooting: Compile-Time Errors


javac: Command not found Greeting.java:4:cannot resolve symbol symbol : method printl (java.lang.String) location: class java.io.PrintStream System.out.printl("hi"); ^ Class and file naming Class count

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 22 of 24

Troubleshooting: Run-Time Errors


Can't find class TestGreeting Exception in thread "main" java.lang.NoSuchMethodError: main

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 23 of 24

Compiling and Running


TestGreeting.java Greeting.java Also compiles

Compile

javac

TestGreeting.class

Greeting.class

Also loads

JVM

Runtime

UNIX JVM

DOS JVM

JavaOS

Can run on multiple platforms

Java Programming Language


Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. Sun Services, Revision G

Module 1, slide 24 of 24

You might also like