Sunteți pe pagina 1din 10

Java Introduction

• Designed by a team at Sun in 1990-1991


• It is a merging of C and Object Oriented Programming
concepts
• All of the basic instructions are C (loops, branches,
functions, variables and types).
• Java is a pure object oriented programming language;
C++, merely added OOP concepts onto existing C
• Designers of Java only kept those features of C that
helped them, making Java a simpler language
• Supports distributed operation and platform
independence, one of the primary needs of internet
based programming.

1
Java is both compiled and
interpreted!

2
Java Platform
• The java Virtual Machine JVM
• The Java Application Programming
Interface (API)

3
Java Program Types
• Applications: An application is a
standalone program that runs directly on
the Java platform

• Applets: An Applet is a program that


adheres to certain conventions that allow it
to run within a Java-enabled browser

4
Simple Java Program
/**The HelloWorldApp class implements an
application that simply displays "Hello
World!" to the standard output. */

class HelloWorldApp {
public static void main(String args []) {
System.out.println("Hello World!");
//Display the string.
}
}

5
Your First Cup Of Java
A Checklist 

• To write your first program, you need:


– The JavaTM 2 Platform, Standard Edition:
To download the SDK click here
– A text editor: for example NotePad. 

6
Your First Cup Of Java
Creating Your First Application
• Create a source file: Copy the class HelloWorldApp in
your file and save it as HelloWorldApp.java
 
• Compile the source file into a bytecode file: to
compile your program to bytecode run the command
javac HelloWorldApp.java.

• Check the output of your compilation: The compiler


should have generated a Java bytecode file,
HelloWorldApp.class 

• Run the program contained in the bytecode file:


Java HelloWorldApp 7
TroubleShooting
Javac
The name specified is not recognized as an internal or external
command, operable program or batch file.

• If you receive this error, Windows cannot


find the Java compiler, javac:
– If the SDK is installed in C:\jdk1.4 at the
prompt you would type the following
command  
C:\jdk1.4\bin\javac HelloWorldApp.java
– Or, you can update the path variable
8
TroubleShooting
Javac
• Update the PATH variable : Microsoft
Windows NT, 2000, and XP : To set the PATH
permanently Choose Start, Settings, Control
Panel, and double-click System. On Microsoft
Windows NT, select the Environment tab; on
Microsoft Windows 2000 select the Advanced
tab and then Environment Variables. Look for
"Path" in the User Variables and System
Variables. If you're not sure where to add the
path, add it to the right end of the "Path" in the
User Variables. A typical value for PATH is:
C:\j2sdk1.4.2_<version>\bin

9
TroubleShooting
Exception in thread "main"
java.lang.NoClassDefFoundError: HelloWorldApp

• If you receive this error, java cannot find your bytecode


file, HelloWorldApp.class:
– One of the places java tries to find your bytecode file
is your current directory. So, if your bytecode file is in
C:\java, you should change your current directory to
that.
– Or, use the option classpath <path> to specify the
path of the needed files, example:
Java –classpath c:\java HelloWorldApp 10

S-ar putea să vă placă și