1. Using IDEs: The first way
by which you can create and run a java program is by using the IDEs (Integrated
It is beneficial to use an IDE because of the following
· Automatic code generation.
· Autocompletion of codes.
· Warning as you type.
· IDE's usually have more semantic knowledge of
the language you're working in, and can show you possible problems while
typing. Refactoring is much more powerful than the "search replace".
· Organize imports (automatically adding
appropriate imports in Java, using directives in C#).
· Keeping a view of files,
errors/warnings/console/unit tests etc. and source code all on the screen at
the same time in a useful way.
· Integrated debugging, compilation, etc.
Thus various tasks like, Designing,
documentation, tracking, developing, building, analyzing, deploying, and
maintenance, key stepping stones in an enterprise application, can all be done
within an IDE. Thus it helps to code faster than you can do in a notepad or WordPad.
That’s why programmers mostly prefer IDE for developing and executing applications.
Examples of various IDEs are CodeLite, Code::Blocks, DialogBlocks, Eclipse,
NetBeans, Komodo IDE, Microsoft
Visual Studio and many more.
2. Using Command Line: You can also run a java program using
Command prompt. In this case you have to create your java program source code
in a text editor, like notepad or WordPad. Save that file with .java extension.
That’s it, the next thing you will be wishing is to compile and run that java program.
So now simply open a command prompt, locate the pointer to the particular
directory and folder where your java project is save. Set PATH to your JDK bin
\Program Files (x86)\Java\jdk1.8.0_31\bin
Suppose that the name of your java project is “HelloWorld.java”.
Next compile your java project by writing the following line:
C: \mywork> javac
If no error shows up it means your java program is correct
and is compiled.So now run the program by writing:
C: \mywork> java
That will give you the output of your program as:
3. Using JAR file: JAR (Java Archive)
file is a file that contains the class, image, and sound files for a Java
application or applet gathered into a single file and possibly compressed. When
a programmer gets a Java program development kit, a small program or utility
called "jar" is included. The jar utility lets the programmer create,
list, or extract the individual files from a JAR file. Creating JAR file and
running java program using it.
4. Using Batch file to execute a java
program: You can
execute a java program using a batch file also. It runs a program because, when
it is executed, the shell program (usually COMMAND.COM or cmd.exe) reads the
file and executes its commands. The sequence of commands contained in it are
executed sequentially in order and can be displayed on the screen to obtain the
How to create and execute a program
using a batch file.