Java 1
Java 1
Java 1
What is Java?
A programming language
Fully buzzword-compliant:
A simple, object oriented, distributed, interpreted, robust, secure, architecture neutral, portable, high performance, multithreaded, dynamic language. From: Java: An Overview James Gosling, Sun Microsystems, February 1995.
Java is a phenomenon
Took the world by storm in 1995 when introduced with the HotJava web Browser Quickly integrated with Netscape browser
Some History
1993 Oak project at Sun small, robust, architecture independent, Object-Oriented, language to control interactive TV. didnt go anywhere 1995 Oak becomes Java Focus on the web 1996 Java 1.0 available 1997 (March) Java 1.1 - some language changes, much larger library, new event handling model 1997 (September) Java 1.2 beta huge increase in libraries including Swing, new collection classes, J2EE 1998 (October) Java 1.2 final (Java2!) 2000 (April) Java 1.3 final 2001 Java 1.4 final (assert) 2004 Java 1.5 (parameterized types, enum, ) (Java5!) 2005 J2EE 1.5
What is Java?
Java is a general-purpose, high-level programming language.
The features of Java
Java program is both compiled and interpreted. Write once, run anywhere
Features of Java
Simple Architecture-neutral Object-Oriented Distributed Compiled Interpreted Statically Typed Multi-Threaded Garbage Collected Portable High-Performance Robust Secure Extensible Well-Understood
Applet
Run under a Java-Enabled Browser
Midlet
Run in a Java-Enabled Mobile Phone
Servlet
Run on a Java-Enabled Web Server
Switchlet
ByteCode produced on any platform may be executed on any other platform which supports a VM
compiled code
CPU
The JIT
Just-In-Time compiler Translates bytecode into machine code at runtime
1-time overhead when run initiated Performance increase 10-30 times
Java API
Collection of readymade software components that provide many useful capabilities. Grouped into libraries (packages) of related components. Core API
Essentials: Object, String, Input and Output... Applets Networking Internationalization Security Software Components Object Serialization Java Database Connectivity (JDBC)
Since Java is object-oriented, programs are organized into modules called classes, which may have data in variables and subroutines called methods. Each program is enclosed in a class definition. main() is the first method that is run.
class HelloWorld { public static void main (String[] args) { System.out.println(Hello World!); } }
The notation class.method or package.class.method is how to refer to a public method (with some exceptions). Syntax is similar to C - braces for blocks, semicolon after each statement. One difference: upper and lower case matter!
<html><head> <title>Simple Hello Page</title> </head> <body> Name of your applet class. My Java applet says: <applet code=HelloWorldApplet.class width=150 height=25> </applet> </body></html>
The browser will use a rectangle of width 150 pixels and height 25 pixels to display the applet within the other html.
import java.awt.Graphics;
public class HelloWorldApplet extends java.applet.Applet { public void paint (Graphics g) { g.drawString(Hello World!, 5, 25); } }
The paint method displays a graphics object on the screen - one of the standard methods that takes the place of main for applets.
No main method
Yes, applets have a main method... ...but it's in the browser, not in your code! More about that later in the course