In the previous post I posted about Java programming language. JAVA can be compiled in 2 ways. The first way is to use IDE (Integrated Development Environtment) for example Netbeans. The second way is to use a text editor such as Notepad or Notepad + + and then the code will be compiled by using the commands in the Command Promt (CMD).
On this post I will share how to compile Java programs using a text editor. First we write java code in Notepad or Notepad + + and then save in any location with the same name as the class that was created, dont forget to save in .Java Extension. For example, save the name coba.java
After that go to the command prompt by clicking start, accesories, and then select the command prompt or by typing cmd in the run window. Type the command javac coba.java, and it will be :
Why does this happen? This will happen when we put the java program outside the bin folder
of java. Then how to compile java using a text editor by write the command in cmd? Read this carefully :
1. Right click on My Computer and click Properties and select Advanced System Settings (win7)
2. In the System Properties click environtment variables tab, and so another window will pop up
3. Edit the Path variable by clicking the edit command button on the variable path and enter
the location of your java bin files.
For example this is my java bin files location :
C: \ Program Files (x86) \ Java \ jdk1.6.0_10 \ bin;
4. After changing the path let's try again compiling via commandprompt. Suppose we write java code in notepad and we store it in mydocuments, and the file name is coba.java (the file name must has the same name as the class name).
5. The result will be like this :
To download notepad++ click HERE
To download my java program example click HERE
The file is .txt format. Open, click save as, and save it in .java format (but don't change the file name)
Tidak ada komentar:
Posting Komentar