<== Back to Index
Intro to Java
Michael Xue (shiue)

2.2.06

No quizzes/tests/homework/grades

only labs.

Book: Core Java 2 Volume 1-Fundamentals (ISBN: 0-13-148202-5)

1. Java
 -programming language that allows you to write applications

 a. need Java compiler
	i. write instructions in Java
	ii. name program with .java extension
	iii. java compiler translates from english to bytecode
		a. converts it to .class extension
		b. looks like gibberish if you look at it

 b. next you need Jave Runtime (JVM - Java Virtual Machine)
	i. interprets bytcode and runs program

 -This is the process for a java application

 -The Java Compiler and the JVM are free downloads from Sun Microsystems


2. Setting up the Java Compiler and JVM
 -we will be using the Command Prompt for alot of this

 a. The compiler and Virtual Machine are bundled in J2SE (Java 2 Special Edition)
 	-can also be called Jdk or Java 2

 b. Download and install the Jdk
	-download to C:\ and install to C:\jdk1.5.0_06\

 c. Put the bin directory on a "path"

 - at this point you want to type "exit" to get out of command window, then re-open it

 - verify the version you are using by typing "javac -version" and "java -version"

3. Your first Jave Program!

 a. First we need to create the source file

 b. Next do a DIR on your directory (enter "dir" and hit enter at the command prompt)
	-you will see Hello.java in your directoy

 c. Next we will take the source file and compile it to get our binary
	i. Type javac Hello.java
	   -if it comes back with nothing it means it was successfull

 d. Next we will run it
	i. Type java Hello into the command prompt
	   -It should print out "Hello, world!"

 e. If it works, celebrate with a hamsterdance. You have created, compiled, and run your first program!


4. You can also write programs to run online

 a. You set up a web-server with an html page. Inside the html you embed a component. This
    is called an "applet". It is written in Java.

 b. Someone goes to your html page, and when they get there the web server gives them your
    html page with your applet in it. Your applet will run in the browser's JVM. They can
    then use your program.

	-There are some concerns over security. However the JVM in the browser is more of
	 a sandbox. Therefor it cannot read or write to your hardrive. This way it can not
	 add information to your hardrive, or steal information from the hardrive. However
	 you can make a secure applet with a certificate that allows the user to decide
	 if they want to program to read/write to their hardrive.

 c. Create a source file called Hi.html (notepad Hi.html) and Hi.java with your code inside
    -to make comments use /* */(in document) or //(at end of line)

 d. now compile your .java file (javac Hi.java)

 e. you now need a web server to serve your conent, but for now we will "short circuit" this.

 f. enter "appletviewer Hi.html" into the command prompt
    -This will pop up the applet viewer to show you your applet. You should see "Hi, world!"
     Time for another Hamsterdance...

	Run my applet



Some Java examples:

Michael Xue's Homepage

<== Back to Index