Sie sind auf Seite 1von 24

Introduction to Java

Contents
• Java Language Features
• Java Environment
• Java Program Structure
• Java & Unicode

2
What is Java?
• Programming language
– Object-oriented

• Software development platform


– Hardware, OS independent

• Enterprise computing architecture


– Distribution and integration of resources
Java Language Features
• Machine Independent
• Object Oriented
• Supports National Character Sets

4
Java Environment

5
Installing SDK

6
Compilation
javac MyProgram.java
javac –classpath . MyProgram.java

– classpath and source options


– CLASSPATH environment variable

7
Execution
• java MyProgram
• java –classpath . MyProgram

8
Java Program Structure

9
Java & Unicode
• Unicode(16 bit code) character set
can represent characters of almost
all languages.
• Java supports Unicode both internally
and externally

10
Objects in Java

• Objects are reusable components.

• In Java, everything must be run


from a “class” file. This “class”
contains bytecode.

• Java source code has the


extension Xxx.java
Objects in Java

• If I write a Java program called:

Hello.java

then, when compiled, this


program will be called:

Hello.class
Objects in Java

• The combination of the data


variables
and the methods
that are used to
read,
write
or modify
those variables

is called a class.
Objects in Java

• Java has a rich collection of Class


Libraries.

• These are also known as the Java


API or Application Programming
Interface.

• To program in Java, you must

i.) Learn the Language, and


Objects in Java

• These class libraries greatly


simplify your job as a Java
programmer.

• They help you to write complex


programs quickly.

• To master Java, you must


master these class libraries.
Java Class Library

16
Java Class Library
• The Java class library is organized
into a number of packages:
– java.lang --- general
– java.awt --- GUI
– java.io --- I/O
– java.util --- utilities
– java.applet --- applet
– java.net --- networking
Compiling A Java
• You have Program
created a Java
program called Hello.java
• To compile it, you run the JDK
supplied utility called:
javac
C:\javac Hello.java
If this was successful, a file
called:
First Java Program
• The two largest varieties of
Java programs:

Applications

Applets
First Java Program

• A Java Application is a free-


standing program that is
capable of running directly in
the Java Virtual Machine.

• A Java Applet is a mini-


program that is much more
limited in its abilities. An Applet
can only run within the context
of an HTML browser.
A Java Application
// HelloWorld.java Our first Java Application

public class HelloWorld


{
public static void main( String args[])
{
System.out.println( “Hello World!” );
}
}

Now
The ourisApplication
This
double the
slashes is complete.
class name.
denote We havecomment.
a “C++”-style added the
Everymethod “main”.
Everything
single bit of Allline
oncode
the methods
in Java
after aresit
must
the lower
double case.
in curly
slashes is is a
main
brackets.
Class special
names method--it
ignored are
by the actually runs the program.
capitalized.
compiler.
Words within In
the name
any are also you
application, capitalized.
are always guaranteed that
This Java program
method main must be saved in a file with the exact
will run.
same name--matching the upper case--as you see in blue
above: HelloWorld.java
A Java Application

C:\>javac
HelloWorld.java

C:\>

• A successful compile of your


java program will return to a
bare cursor, as you see here.
A Java Application
C:\>javac
HelloWorld.java

C:\>java HelloWorld
Hello World!
• To run your compiled
Application, you enter lowercase
java HelloWorld on the command
line. • Notice,
the “.class” extension is omitted.
In Class Activity

Now load the JDK1.6,


the documentation,
change the class path and
write your first Java program.

Das könnte Ihnen auch gefallen