wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes Command line to console ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Command line to console ?" Watch "Command line to console ?" New topic
Author

Command line to console ?

Charles Angemeyer
Greenhorn

Joined: Dec 18, 2012
Posts: 22
Below is some code on bit sets from the "Teach Yourself Java2" book but it is started via the command line.
Is there anyway that I can change it to a console application?
I inserted some Scanner code hoping that would do the trick but it just prompted me for the information then nothing.
Thank you.



Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41085
    
  43
What is the difference between a "command line app" and a "console app"?


Ping & DNS - my free Android networking tools app
Charles Angemeyer
Greenhorn

Joined: Dec 18, 2012
Posts: 22
console app = when I'm working in Eclipse and I click the run button. The app runs or doesn't run in the bottom of the screen in the console area.
Command line app = not sure, you run it from the command prompt, like a DOS window.
Thanks.
Jayesh A Lalwani
Bartender

Joined: Jan 17, 2008
Posts: 2272
    
  28

COnsole app is the same thing as a command line app. Eclipse just shows the command line output in the "console". You can type your input right in the console window
Charles Angemeyer
Greenhorn

Joined: Dec 18, 2012
Posts: 22
Really sorry, I still don't know what to type and where.
Here's what it says in the book.

"This class can be run as an application because of the main() method. The application takes a single command-line argument: A number from 1 to 365 that
represents one of the days of the year. The application displays whether that day is a holiday according to the schedule of the HolidaySked class. Test the program with
values such as 20 (Martin Luther King Day) or 104 (my 37th birthday). The application should respond that day 20 is a holiday but day 104, sadly is not."

I just want to test the app in eclipse.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37950
    
  22
Confusion: command line: a place where you write instructions to the operating system. Terminal: a place where you write instructions to the operating system. You usually call it command line on Windows and terminal on *nix. The *nix terminals are much more powerful than the command line. A console (small c) is a place where you write instructions to the operating system. A Console (large C) is a class in the java.io package, which can take instructions from the console. Beware: if you start your app in certain fashions (I think, including by running it from an IDE), you get null instead of a Console object, and you cannot use the Console class’ methods.

What the Deitel book means is that you are supposed to start the app like this at a console
java HolidaySked 359
There is a window in Eclipse called console, which shows the input and output, but it behaves rather like a combination of System.in System.out and System.err, not as a proper console. You can enter input to the running program, but not to the OS. This shows the hazards of using IDEs when you are first learning. You get confused because things like command‑line arguments are hidden. Stop using Eclipse.
If you insist on using Eclipse, I think what you need to do is:-
  • 1: R-click the name of your class and get a dropdown list.
  • 2: Click run configurations.
  • 3: Open the arguments tab.
  • 4: put 359 in the command line arguments box (not the JVM options box).
  • Not certain; I would have to run Eclipse to check that.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 37950
        
      22
    Charles Angemeyer wrote: . . . 104 (my 37th birthday). . . .
    And how does that differ from his 38th birthday?
    Charles Angemeyer
    Greenhorn

    Joined: Dec 18, 2012
    Posts: 22
    If I don't use Eclipse or another IDE then what program should I use so I can experience command line arguments the way they are meant to be used/seen?
    Or can you point me in the direction of something that I can "read up" on?
    Also, thanks, your suggestion worked.
    Winston Gutkowski
    Bartender

    Joined: Mar 17, 2011
    Posts: 7523
        
      18

    Charles Angemeyer wrote:If I don't use Eclipse or another IDE then what program should I use so I can experience command line arguments the way they are meant to be used/seen?

    Erm ... cmd.exe?

    At least, that's what you use on Windows; on Unix/Linux, there are a bunch of programs, all of which come under the general heading of 'terminal's.

    Winston

    Isn't it funny how there's always time and money enough to do it WRONG?
    Articles by Winston can be found here
    Stevens Miller
    Ranch Hand

    Joined: Jul 26, 2012
    Posts: 523
        
        3

    Under Windows, click on the "Start" menu (almost always lower left on your desktop), then select All Programs / Accessories / Command Prompt. You'll get a DOS window.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 37950
        
      22
    Whenever you have found your console program, add it to your desktop as a shortcut/launcher.
    Omar Jouda
    Greenhorn

    Joined: Jul 11, 2012
    Posts: 19
    Campbell Ritchie wrote:Confusion: command line: a place where you write instructions to the operating system. Terminal: a place where you write instructions to the operating system. You usually call it command line on Windows and terminal on *nix. The *nix terminals are much more powerful than the command line. A console (small c) is a place where you write instructions to the operating system. A Console (large C) is a class in the java.io package, which can take instructions from the console. Beware: if you start your app in certain fashions (I think, including by running it from an IDE), you get null instead of a Console object, and you cannot use the Console class’ methods.

    What the Deitel book means is that you are supposed to start the app like this at a console
    java HolidaySked 359
    There is a window in Eclipse called console, which shows the input and output, but it behaves rather like a combination of System.in System.out and System.err, not as a proper console. You can enter input to the running program, but not to the OS. This shows the hazards of using IDEs when you are first learning. You get confused because things like command‑line arguments are hidden. Stop using Eclipse.
    If you insist on using Eclipse, I think what you need to do is:-
  • 1: R-click the name of your class and get a dropdown list.
  • 2: Click run configurations.
  • 3: Open the arguments tab.
  • 4: put 359 in the command line arguments box (not the JVM options box).
  • Not certain; I would have to run Eclipse to check that.


    Wow, I never knew we can pass arguments in Eclipse. This made it much more easier to test cmd line arguments while studying.
    I value all your experienced advice greatly, but just focusing on CMD makes it very tedious, hard, and time consuming. I mean I try to practice something, but I get errors which I don't understand why they come up and why they come up. It gets very frustrating, I can't practice any theory I am focusing on. I try something , another completely different weird error comes up.
    Like now, I tried opening CMD to practice Command Line arguments , I compiled the .java file. I then try to run it using java ,but it gives me an error that the class was not found. I mean it is right there but the CMD doesn't want to execute it.
    I created a post before in the OCAJP7 forum about this. I struggled for hours with it despite Mr. Roel's kind efforts with me. I still did not successfully execute programs or packaged programs using command lines. I am just relying on my theoretical knowledge from books but I can't practice CMD without getting frustrated. Very Hard times.
     
    jQuery in Action, 2nd edition
     
    subject: Command line to console ?
     
    Similar Threads
    Java Project Beginner OOP
    Unable to Return Variable
    Bad operand types for binary operator?
    creating user defined threads
    Help needed gathering and sorting info in arrays to make a histogram