Getting Started
(
[Link]
tutorial/getStarted/
[Link])
Objectives
• About the Java Technology
• What can Java Technology do?
• How can Java support platform-
independence?
• Java Platform
• Set up Environment Variables
• The first Java program in the
NetBeans
• Structure of a Java program.
About the Java Technology(1)
History
– 1990, James Gosling, Bill Joy, Patrick Naughton(Sun
Microsystem) developed the Oak language for
embedding programs to devices such as VCR, PDA
(personal data assistant). The Oak programs require:
- Platform independent/- Extremely reliable/ - Compact
– 1993, interactive TV and PDA failed, Internet and Web
were introduced, Sun change the Oak to an internet-
development environment with a new project, named
Java.
– 1994, the Sun’s HotJava Browser was introduced
(written using Java). It showed the strength of Java
applets and abilities to develop Java application.
About the Java Technology(2)
History…
•Embedded Systems (1991 – 1994)
• A client – side Wonder (1995 – 1997)
•Moved into the Middle – tier (1997 – to
present)
• Future: may gain more success
About the Java Technology(3)
The Java Programming Language is a high-
level language. It’s characteristics:
Simple Architecture neutral
Object oriented Portable
Distributed High performance
Multithreaded Robust
Dynamic linking Secure
What can Java Technology do?
Using Java, we can:
• Development Tools. Desktop Application
• Application ( Console App, GUI
Programming Apps)
Interface (API). Web-based Applications
Network-based
• Deployment Applications
Technologies. Game
• User Interface Distributed
Applications
Toolkits. Embedding
• Integration Application
Libraries. (Apps on Devices)
How can Java support platform-
independence?
[Link] (plain text)
Java Compiler
[Link]
Platform-Independent
Java byte-code: [Link]
Java Runtime Interpreter / Java Virtual
Machine ([Link])
IBM Macintosh Sparc
Java Virtual Machine
• The Java Virtual Machine is an
abstract computing machine.
Like a real computing machine,
it has an instruction set and
manipulates various memory
areas at run time. It is
reasonably common to
implement a programming
language using a virtual
machine; the best-known
virtual machine may be the
P-Code machine of UCSD
Pascal. [Link]
More details:
[Link]
Java Platform
• A platform is the hardware or software
environment in which a program runs.
• The Java platform has two components:
• The Java Virtual Machine
• The Java Application Programming Interface
(API)
Operating System
Set up Environment Variables
After installing JavaSE
(Java Development Kit Standard
Edition),
environment
variables should be
setup to point to the
folder in which JavaSE
is installed.
Steps: My Computer/
Properties/
Advanced/Environment
Variables/System
Variables/ Path/ Edit
Why? The point at the beginning of the CLASSPATH means that
classes will be searched first in the current working folder.
The first Java program in the NetBeans
This program will show the string “Hello
World” to the screen.
Steps
1- Create a new Java NetBeans project 2-
Add a Java class
3 Write code
4 Compile/Run the program
Step 1- New
Project
If this option is
checked,
NetBeans will
automatically
generate a
class, named
Main, for the
project.
If this option is not checked,
we can create some programs
in one project.
New Project…: Initial Project Structure
In Windows Explorer
In NetBeans
Step 2: Add
a Java Class
Package:
Subdirectory of the
folder Project/SRC
Read
recommendation
In this demo, we do not specify
package intentionally
Add a Java
Class…
In Windows Explorer In NetBeans
Step 3: Write code
Step 4: 4 ways to Compile/Run program
in NetBeans
Result:
End users run Java Programs
Users can not run Java programs in NetBeans but
in Java Runtime Environment (jre) installed
([Link]) and related files
Syntax for running a Java program:
Re-try it using Helloworld, helloworld Give comments
End users run Java Programs…
If the environment
variable was setup
with “.;”, we can run it
at the working folder
as:
K: Change working drive to K
cd Change working directory
End users run Java Programs…
Developer
should support
end users an
easier way to
run the
program: a
BAT file
Explain JDK and its tools
javac (Java compiler)
java (Java interpreter)
A Closer Look at the "Hello
World!" Application
• Comments
• Traditional /*this is a comment*/
• Comment to line end //this is an end of line comment
• Class declaration
• public class ClassName { ... }
• For example: public class HelloWord { ... }
• The main Method – Entry point of Java program
• public static void main(String[] args) {..}
• public and static can be written in either order
• The main method accepts a single argument: an array of
elements of type String. A demonstration for passing strings to
the main method will be presented in the next session.
Common Problems (and Their
Solutions)
• Compiler Problems
'javac' is not recognized as an internal or external
command, operable program or batch file
->Updating the PATH variable in the JDK
• Syntax Errors (All Platforms)
• Semantic Errors
• Runtime Problems
• Exception in thread "main"
[Link]
Classname
• Could not find or load main class
[Link]
is
incorrect
Try and Explore
Change To – If no error, try run it
public class HelloWorld public class HelloWorld2
public class HelloWorld class HelloWorld2
public static void main(String[] args) public static void main(String args[])
public static void main(String[] args) public void main(String[] args)
public static void main(String[] args) void main(String[] args)
Summary
• An overview of Java technology as a
whole.
• What to download, what to install, and
what to type, for creating a simple "Hello
World!" application.
• Discusses the "Hello World!" application.
• Trouble compiling or running the
programs.