How to run a Java program on a Commandline


      A command-line interface is a concept of interacting with a computer program whereby the user key in or issues commands to the program in form of lines of codes or command lines. These commands are handled by a program called a Command language interpreter or shell.
      Command-line interface can also be referred to as command language interpreter (CLI), Command-line user interface, console user interface or character user interface (CUI).

Today Am going to show you how to write simple program in Java and run it on your computer command-line interface using Ubuntu. But before that, Let me give some of the importances of using Command-line interface instead of just the Graphical User Interface.
  •  Requires few system resources to implement
  • Automation of repetitive tasks is simplified
  • command-line history can be kept
  • its faster when running programs as long as you've mastered the commands.
   There are few requirements one needs to have so as  to be able to run Java program on command-line. First you need a text editor such as brackets, atom, notepad++, sublime text, vim etc. Second, you need Java JDK for compiling the program.
 I won't be taking you to how to install text editors, but if you go to the official websites of these text editors, you will be able to download them. Most of them are usually free from open source.
Now lets go to how to install Java jdk in you ubuntu or any linux os and how to run your first program on command- line interface.
  1. From Terminal install openjdk 
         
               sudo apt-get install openjdk-8-jdk
 
                
2. Write your program and save the file name as anything. for example mine have saved as Number.java
3. The next step is to compile your program from terminal
   
                     javac Number.java
After compilation another file will be created with extension .class i.e Number.class

4. Lastly we run the program

                   java Number


 thank you!!!!!

Comments

Popular posts from this blog

Is Your Laptop or Desktop Safe from Hacking?

Nano Robots developed to fight and destroy Tumors