Selasa, 02 Maret 2010

java beginner - setting classpath windows dan hello world =)

kalo kita udah nginstal java sdk dan jre dengan cara klik next next next
terus kita mau jalanin hello world nya kita kudu nambahin class path nya java dulu supaya code java kita bisa di compile dimana saja

berikut contoh program hello world nya

//mulai
class hello
{
public static void main(String args[])
{
System.out.println("Hello World!");
}
}
//akhir hello.java

lalu kita simpan di misalnya c:\fixu\hello.java
nama class dan nama file.javanya harus sama lho...

terus kita setting path windows berikut caranya


Setting Path on Windows
For 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.
sumber dari http://www.java.com/en/download/help/path.xml
disitu juga ada setting path untuk unix dan operating system yang lainnya lho

sudah dicoba dan berhasil lho... =)

kalo kita sudah berhasil setting path lalu masuk command prompt run>cmd
set directory utama c:\fixu tempat kita menaruh file .java

jalankan command
javac hello.java

kalo berhasil nanti keluar file hello.class

lalu ketikkan
java hello
kalo berhasil nanti muncul tulisan hello world !!! di command prompt anda

selamat mencoba =)
salam W0_ow

Tidak ada komentar: