banner



How To Compile Java Template In Command Line Prompt

Although Merit Campus provides the online compiler Try Java Online Compiler, information technology is more of import to sympathize how to compile and run your programs on the local automobile Using Command Prompt. Because in real time you will need to run your programs locally and to add to that the online compiler does non support circuitous programs.

For you to compile and run any Java program on your machine/computer/pc, you should accept installed Java on it. Please find the instructions for installation of Coffee at Installation Of Java on your PC.

Steps for compiling and running a Java program

  • 1. Create a directory: Open the windows explorer(file explorer) and go to the D drive (or any other drive of your choice). Inside that create a directory called programs. This volition be the directory you will employ for storing all your java programs. This step you have to do only once per reckoner, it is non necessary to create a new directory for every Coffee programme.

compilation create programs directory

  • 2. Create a new text document: Go to the programs directory in windows explorer and create a new text file by correct clicking in the empty area and employ the pick 'New' -> 'Text Document'.

compilation right click menu for new text document

  • three. Modify the binder options (if required): If the newly created file is 'New Text Document' instead of 'New Text Document.txt', so you demand to this additional step of irresolute the folder options to prove the file extension. Please go to the bill of fare option 'Organize' -> 'Folder And Search Options', it launches a dialog with name 'Folder Options'. Go to the tab 'View' and un-select the option 'Hide extensions for known file types'. Click 'OK' on the dialog. Then information technology should testify the file name as 'New Text Document.txt'.

compilation new text document with out extension

compilation choose folder and search options

compilation folder options dialog

compilation choose hide extensions for known file types

compilation new text document with extension

  • 4. Rename the text certificate to programme name: Right click on 'New Text Document.txt' and rename it to 'PrintHelloWorld.java'. You lot should see the .java extension after y'all rename it. The type should be 'JAVA file' instead 'Text Certificate'.

compilation after renaming the text document

  • 5. Why we chosen information technology 'PrintHelloWorld.java': Since in this example we volition be copying the code from Java Sample Program - Simple Hello World Program In Java and the plan name their is PrintHelloWorld. Please notation that the file name PrintHelloWorld.java and the plan name PrintHelloWorld should be exactly same and they are case sensitive. Having the file names like 'printhelloworld.java' or 'Printhelloworld.java' or 'printworld.coffee' is not allowed. The spelling should be exactly same and the case of letters (Uppercase or small) should as well be same.
  • 6. Copy the Java plan into the file 'PrintHelloWorld.java': Open the file 'PrintHelloWorld.java' using 'Notepad' and re-create the program code from Java Sample Plan - Simple How-do-you-do Earth Plan In Coffee and save it using 'File'->'Save'.

compilation open file with notepad

compilation copy content into file

  • vii. Launch the command prompt: Go to the 'First' menu and launch the 'Control Prompt' program. Or run the 'cmd' program to launch the control prompt.

compilation launching command prompt

or

compilation launch using cmd

compilation command prompt

  • 8. Go to the required directory: Use the command 'd:' to get the required drive, 'cd programs' to go to the programs directory, 'dir' to see the listing of files. The directory listing should prove the file 'PrintHelloWorld.java'

compilation change and list directory

  • 9. Compiling the Coffee program: On the control prompt use the command 'javac PrintHelloWorld.java' to compile the program. It should compile with out any errors. If it says 'not a recognized program', then it means the java is not installed or it is not proper. Go to Installation Of Coffee on your PC for installing the aforementioned. If at that place are no errors, then run the control 'dir' and encounter that a new file 'PrintHelloWorld.class' is created. This .course file is created when we compiled the program and information technology contains the bytecode. Yous should too see this file in the file explorer.

compilation compilation and list directory

compilation dot class file in explorer

  • 10. Run the Java program: On the command prompt use the control 'coffee PrintHelloWorld' to run the program. Information technology should impress the output 'Hello World' on the screen. This ways we are able to successfully compile and run a simple java program.

compilation run java program

Making further changes to the PrintHelloWorld program:

To brand further changes to the program:

  • Open 'PrintHelloWorld.java' in notepad, brand the necessary changes, save it using 'File'->'Save'
  • Compile in command prompt using 'javac PrintHelloWorld.java'
  • Run using the command 'java PrintHelloWorld'

Creating a new programme called SayHelloHi:

  • Create a new text document using 'New' -> 'Text Document' in file explorer, rename it to 'SayHelloHi.java'
  • Write lawmaking in the file 'SayHelloHi.coffee'. The class name given in the file should exist 'SayHelloHi' which is same as the program name.
  • Salvage the file using 'File'->'Save'.
  • Compile in command prompt using 'javac SayHelloHi.coffee'
  • Run using 'java SayHelloHi'.

Setting up the surroundings for time to come programming sessions:

  • Open up the directory D:\programs in windows(or file) explorer. This is where all your programs are present.
  • Open the command prompt using 'Showtime'->'Command Prompt' or by running 'cmd'. Go to your programs directory using the commands 'd:', 'cd programs'. Use 'dir' to see the listing of all programs and the .class files created.
  • Run the command 'javac PrintHelloWorld.java' and 'coffee PrintHelloWorld' to confirm that your java installation is still proper.

How To Compile Java Template In Command Line Prompt,

Source: http://java.meritcampus.com/core-java-topics/how-to-compile-and-run-java-program-in-cmd-prompt

Posted by: swanmencir.blogspot.com

0 Response to "How To Compile Java Template In Command Line Prompt"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel