Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

Java 

How to compile and run a Java program [basic tut I've done for no0bz]

Well you should use a tutorial, but for people who dont want to program in java but just want to compile and run java applications , or n00b programmers then here is a basic tutorial (coz i'm fucking sick of people asking).

How to compile a java program?

First to compile the program you need the jdk (java developement kit) installed which can be downloaded from http://java.sun.com/ then you should create a batch file for your environment variables so you dont have to write the full path every time in the console (this is the quik/cowboy way), example:

PATH = C:\WINDOWS\system32\jdk1.5.0_04\bin

And save that as Autoexec.bat note that was just an example, it wont necassaraly be in that dir, just the for the bin folders in the jdk and use that path.

Now for an example we have a HelloWorld.java program that you have downloaded, put it in C:\ for example, when you save it make-sure you save in all files (rather than a txt document) as HelloWorld.java.

Go into the command prompt and change to certain directory, in our example:

>cd c:\ (change the directory to c:\)

c:\> (result)

then you want to compile the program, depending on if you've done the Autoexec.bat file correctly, you can simply call the compiler with javac followed by the a space and java file, so in our example:

c:\>javac HelloWorld.java

If it compiles sucessfully then it will just go back to C:\>

c:\>

You will notice that in c:\ next to you HelloWorld.java program is a HelloWorld.class file (that is actually an executable file... read below on how to run it).



How to run java programs?

Well first i'll say that java programs (unless you create an exe) is platform independant, you dont need the jdk to run java programs! all you need is the jre (java runtime enviroment) and JVM installed which most computers allready have pre-installed, or you've had it installed whilst on the the web to view certain sites and chat ect (trust me most computers in the world have it installed even if you dont know it).

So concluding the java HelloWorld program....

To call the jre to execute the class file, in our example before you simply type in java followed by a space and the class file name (without the class extension) so... out example:

c:\>java HelloWorld

Thats it! now your program will execute. Go to my site here for more info on java.
Thank you for this post sir!
could not find or load Main.java (im trying it on another thing i made)


Possibly Related Threads...
Thread / Author Replies Views Last Post
[C] by F.A.S.TMar 6, 2019 04:22 AM 10 538 Mar 6, 2019 04:22 AM
Last Post: F.A.S.T
[Java] by ttb32394Aug 21, 2018 09:05 AM 0 143 Aug 21, 2018 09:05 AM
Last Post: ttb32394
[Java] by ttb32394Aug 20, 2018 06:26 PM 3 254 Aug 20, 2018 06:26 PM
Last Post: GoodVibes