Java Notes
See also SMART notes and/or Files at http://teach.kralsite.com 

Editor

JEdit - editing java
Get this editor:
http://www.jedit.org/index.php?page=download

Getting Started
Get this code 
HelloWorldApp.java
/**
 * The HelloWorldApp class implements an application that
 * simply prints "Hello World!" to standard output.
 */
class HelloWorldApp {
    public static void main(String[] args) {
        System.out.println("Hello World!"); // Display the string.
    }
}

Unix / MacOS X

Open Terminal.app

$ echo $PATH
$ which java

$ java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-10M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)
$ cd ~
$ cd (wherever you put your code, you can drag it in with the Finder)
$ pwd
/Users/fkral/Projects/JavaCourse
$ ls
HelloWorldApp.java
$ javac HelloWorldApp.java 
$ ls
HelloWorldApp.class	HelloWorldApp.java
$ java HelloWorldApp
Hello World!
$ 	
http://docs.oracle.com/javase/tutorial/getStarted/cupojava/unix.html 

Windows
Edit the PATH variable by adding the file location that points to the location of your java installation. Point to the /bin directory (folder).

Example for Windows 7.   
Variable		Value
Path			 [a bunch of stuff separated by semicolons];C:\Program Files (x86)\Java\jdk1.7.0_01\bin

Setting Path on Windows
Windows 7
	1.	Select Computer from the Start menu
	2.	Choose System Properties from the context menu
	3.	Click Advanced system settings > Advanced tab
	4.	Click on Environment Variables, under System Variables, find PATH, and click on it.
	5.	In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
	6.	Reopen Command prompt window, and run your java code.
Windows XP
	1.	Start -> Control Panel -> System -> Advanced
	2.	Click on Environment Variables, under System Variables, find PATH, and click on it.
	3.	In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
	4.	Close the window.
	5.	Reopen Command prompt window, and run your java code.
Windows Vista
	1.	Right click My Computer icon
	2.	Choose Properties from the context menu
	3.	Click Advanced tab (Advanced system settings link in Vista)
	4.	In the Edit windows, modify PATH by adding the location of the class to the value for PATH. If you do not have the item PATH, you may select to add a new variable and add PATH as the name and the location of the class as the value.
	5.	Reopen Command prompt window, and run your java code.

http://java.com/en/download/help/path.xml

Open Command Prompt
> java -version
java version "1.6.0_27"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.6.0_27-b07)
Java HotSpot(TM) Client VM (build 1.6.0_27-b13, mixed mode, sharing)
> dir
> cd My Documents
> cd (wherever you put your code)
> dir
HelloWorldApp.class
HelloWorldApp.java
> javac HelloWorldApp.java
> dir
HelloWorldApp.class
HelloWorldApp.java
> java HelloWorldApp
Hello World!
> 

http://docs.oracle.com/javase/tutorial/getStarted/cupojava/win32.html 

What does public static void mean in Java?

public means that the method is visible and can be called from other objects of other types. Other alternatives are private, protected, package and package-private. See here for more details.

static means that the method is associated with the class, not a specific instance (object) of that class. This means that you can call a static method without creating an object of the class.

void means that the method has no return value. If the method returned an int you would writeint instead of void.

The combination of all three of these is most commonly seen on the main method which most tutorials will include.

http://stackoverflow.com/questions/2390063/what-does-public-static-void-mean-in-java 

Where does Java live?

Mac OS X

MacBook3:Commands fkral$ java -version
java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-10M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)
MacBook3:Commands fkral$ which java
/usr/bin/java

MacBook3:Contents fkral$ pwd
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents
MacBook3:Contents fkral$ ls -tal
total 0
drwxr-xr-x   7 root  wheel   238 Sep 12 10:51 Home
drwxr-xr-x  50 root  wheel  1700 Sep 12 10:51 Libraries
drwxr-xr-x   3 root  wheel   102 Sep 12 10:51 MacOS
drwxr-xr-x  21 root  wheel   714 Sep 12 10:51 Resources
drwxr-xr-x  10 root  wheel   340 Aug 31 18:07 .
-rw-r--r--   1 root  wheel   454 Aug 31 18:07 version.plist
-rw-r--r--   1 root  wheel  1963 Aug 31 18:02 Info.plist
drwxr-xr-x   3 root  wheel   102 Aug 31 17:40 ..

MacBook3:bin fkral$ pwd
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/bin
MacBook3:bin fkral$ ls -l
total 3208

-rwxr-xr-x  1 root  wheel  100480 Aug 31 18:00 jar
-rwxr-xr-x  1 root  wheel  100560 Aug 31 18:00 java
-rwxr-xr-x  1 root  wheel  100560 Aug 31 18:00 javac
-rwxr-xr-x  1 root  wheel  100560 Aug 31 18:00 javadoc
-rwxr-xr-x  1 root  wheel  100560 Aug 31 18:00 javah
-rwxr-xr-x  1 root  wheel  100560 Aug 31 18:00 javap

Windows 7

Java 7 (64 bit)
C Program Files Java

Java 6 (32 bit)
C Program Files (x86) Java