Reputation: 1317
I'm a newbie to Java and software engineering and had the following question. What exactly does it mean to build a Java Command Line application? In particular, should the application be such that it can run by an individual using Command Line (with the program in some file on the user's desktop and the application be a java file) and all the source code should be written in Java? I understand what Command Line is and my JDK is Eclipse. Thanks for the clarification (couldn't find sufficient explanation online).
Upvotes: 1
Views: 14110
Reputation: 448
A CLI program is a program that uses the command line as its interface.
For example,
cp file1 ../
If such a program requires some continuing interaction with the user, then Java programs typically use System.out to print output, and a Scanner object for input.
Scanner ins = new Scanner(Sytem.in);
The user types on the keyboard. The Scanner doesn't get the input until the user presses the return key.
For example, to request a name from a user
Scanner ins = new Scanner(System.in);
String name = "";
while (name.equals("")) {
System.out.print("Your name? ");
name = ins.next();
}
There should be more error checking and so forth, but the basupics are there. I hope this helps.
Upvotes: 3
Reputation: 1325
It generally means there is no graphic user interface (aka, GUI) in you program, so people could use it in text terminals without a graphic display (embeded, remote server, etc). I believe the default setting in Eclipse new projects are command line applications, so no additional efforts needed.
Upvotes: 2