1. Using IDEs: The first wayby which you can create and run a java program is by using the IDEs (IntegratedDevelopment Environment).
It is beneficial to use an IDE because of the followingreasons:
· Automatic code generation.
· Autocompletion of codes.
· Warning as you type.
· IDE's usually have more semantic knowledge ofthe language you're working in, and can show you possible problems whiletyping. Refactoring is much more powerful than the "search replace".
· Organize imports (automatically addingappropriate 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 atthe same time in a useful way.
· Integrated debugging, compilation, etc.
Thus various tasks like, Designing,documentation, tracking, developing, building, analyzing, deploying, andmaintenance, key stepping stones in an enterprise application, can all be donewithin 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, MicrosoftVisual Studio and many more.
2. Using Command Line: You can also run a java program usingCommand prompt. In this case you have to create your java program source codein 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 particulardirectory and folder where your java project is save. Set PATH to your JDK bindirectory, like:
C:\mywork>set path=C:\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> javacHelloWorld.java
If no error shows up it means your java program is correctand is compiled.So now run the program by writing:
C: \mywork> javaHelloWorld
That will give you the output of your program as:
Hello World!
3. Using JAR file:
JAR (Java Archive)file is a file that contains the class, image, and sound files for a Javaapplication or applet gathered into a single file and possibly compressed. Whena programmer gets a Java program development kit, a small program or utilitycalled "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 javaprogram: You canexecute a java program using a batch file also. It runs a program because, whenit is executed, the shell program (usually COMMAND.COM or cmd.exe) reads thefile and executes its commands. The sequence of commands contained in it areexecuted sequentially in order and can be displayed on the screen to obtain thedesired output.
How to create and execute a program using a batch file.
Leave a Comment
2 Comments