Udjuni.com

udjuni.com search:




Compiling and executing a java program


Java source code is always stored in a file with a .java file extension. Once you have created your source code, you simply save it with a .java extension and it is ready to be compiled. To compile your java code, you use the following command:
javac your_filename.java 

Note that javac is all small caps. javac is the name of the java compiler. It takes your class and convert it into a file with a .class file (usually called "class files"). This file will have the same name as your java file, except it will have the .class file extension instead of .java. This will be the file that the java interpreter is going to execute.


Executing java code



Once your source code files (.java files) are compiled, you can now execute these files for as many times as you like. Remember, if your file has errors, it will not be compiled until all errors are fixed. To execute a java class, you use the following command:
 java your_class_name


Note here, that you do not need to specify the .class file extension, java will know and look for the a .class file with the specified name.

For example, let us take a look at the code bellow:


public class HelloWorld {

public static void main(String[] args){

System.out.println("Hello there!!!");
}


}


Save the file as HelloWorld.java. Now, to compile this file, we will issue the following command:

javac HelloWorld.java 


This will compile the code and produce a file names HelloWorld.class

To execute that file we issue the following command:
java HelloWorld


This will print Hello there!!! on the computer screen.




RELATED ARTICLES:


Introduction to Java programming
Computer program as we learned in the posting Introduction to Programming

Starting to program in Java
Most java developers would describe it as an innovative programming language that enables a developer to write what is called "Applets" or pieces of java code that can be embedded in web pages. In addition to this benefit, compiled java code can be run on a variety of

Java variables and data types
A variable is defined as a named piece of memory that a java program uses to store data. Each of these storage pieces can only store data of a certain type. In other words, if you defined as variable of type integer, that variable can only hold inte

breaking code periodic table


PL/SQL code blocks
Like any procedural language, the basic unit of PL/SQL program is a block. Within those blocks you find statements that are executed as a unit. In PL/SQL, blocks are further classified into different categories that include; Labeled blocks - this are used to give a c

Introduction to Programming
What exactly is programming? Programming can be defined as the art of telling a computer to do whatever you want it to. If you are reading this posting you probably started off with switching the computer on and then opened the browser that got you to this page. Every comp

Starting to Program in PHP
As defined in the posting “Introduction to programming”, is the art of giving step-by-step instructions to a computer telling it to do whatever you want. There are many programming languages ranging from what is termed first generation languages which are represented in strings of binary digits (zer

Did not find it? Try udjuni.com search:







© 2009 UdjunI LLC. All rights reserved | Privacy policy | Tutorial Index | RSS Feed