How to Compile and Run Java Programs

Hi there this is my first time to write an article in www.sourcecodester.com how to compile and run java programs. Most of the times there are miss conceptions that compiling and running java programs is very diffucult and hard to understand this article try to help you understand the basic concepts of it. I believe if you have a good and strong fundamentals in programming you will succeed in whatever endeavors that you have in mind. I have observed being an Computer Instructor most Computer Instructor in other colleges and universities these days those not teach the very basic in how to compile and run java programs using java commands in console windows. Most of them are more relying on IDE's that is widely available over the Internet like JC Creator, TextPad, NetBeans and Blue Jay to name a few to write and run their programs in Java. There is no problem with that however there are some situation in programming that requires the beginners how to install and properly configure the Java Development Kit thats a big problem on them because they dont know how to compile and run the Java programs properly. Presuming we have already install the JDK ( Java Development Kit ) in our computer it, provides two commands for you to compile and run Java programs. "javac class_name.java" - Compiles a Java program stored a file named with the program class name. "java -cp . class_name" - Runs a compiled Java program. "-cp ." specifies the current directory as the class path. Let's try these commands with a very simple Java program. Use NotePad to enter the following Java program into a file called Hello.java: // Here is our sample program in Java class Hello { public static void main(String[] a) { System.out.println("Hello world!"); } } Then compile this program in a command window with the "javac" command: C:\>\progra~1\java\jdk1.6.0_02\bin\javac Hello.java To execute the program, use the java command: C:\>\progra~1\java\jdk1.6.0_02\bin\java Hello Hello world! Congratulations, you have successfully entered, compiled and executed your first Java program. I hope this article help everyone who is interested in Java programming. Personally I love doing Java Programming all the time. It takes a lot of courage, patience and dedication in order to succeed. Take care always and Happy Programming. If you have some questions or comments you can send me an email at [email protected] . People here in the Philippines who wish to contact me can reach me in my mobile phone number 09296768375 . Regards,

Mr. Jake Rodriguez Pomperada, MAED - Instructional Technology

Add new comment