1

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).

14
  • 1
    A CLI is any program run from the command line, taking in arguments that affect the operation. I don't know, think cp (or copy). It has no GUI and it's operations are all carried out at the command line Commented Dec 20, 2019 at 7:53
  • 2
    as answered on your (identical) question on wwweagle's answer: if you want to have a GUI, you'll have to create it. There is no default. It depends on your needs. Commented Dec 20, 2019 at 7:59
  • 1
    @don there's no default. If you use classes and method that show a GUI you get a GUI application, if you use classes and methods that interact with a command line you get a CLI application Commented Dec 20, 2019 at 7:59
  • 1
    @don that's too vague a question. What does your application need to do? Commented Dec 20, 2019 at 8:00
  • 1
    @don I already answered that. Scanner and print statements Commented Dec 20, 2019 at 8:00

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

3

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.

5 Comments

Ok thanks - my question as a follow up would be: If you write source code in Eclipse or whatever IDE, do you have to do anything special to incorporate CLI or GUI? What is the default?
@don you have to create a GUI.
Ok thanks - what do I need to do to write a Java Command Line program? Just a guideline or generally idea would be helpful - I can browse around to figure out the implementation details
@don just follow any Eclipse "new project" tutorial. They almost always start with a command line app.
One thing to remember is that very few CLI Programs have any sort of interactive interface. Most get all their data through the initial command line and arguments. Ex: mv file1 ../

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.