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.
Campbell Ritchie wrote:This version has no input validation, and does everything in the main method, which is usually not a good idea. It might be better to pass args to the constructor of a class which extracts the values from the array.
Roel De Nijs wrote:It's a long time ago since I used the command line myself for compiling and running java files. So, it's all a bit rusty
This should do the trick: javac E:\Development\workspace\BackToJava\src\com\ocaexam\tutorial\GreetingsUniverse.java
An alternative could be:
javac com\ocaexam\tutorial\GreetingsUniverse.java (and if you want to compile all java files in a given package then you can do: javac com\ocaexam\tutorial\*.java)
Roel De Nijs wrote:When your class is not in a package, you can compile it with javac -cp Development\workspace\BackToJava\src GreetingsUniverse.java
When your class is in package com.ocaexam.tutorial, you can compile it with javac -cp Development\workspace\BackToJava\src com/ocaexam/tutorial/GreetingsUniverse.java
In both cases it's not needed to change the current directory to the source directory as you can provide it with the -cp option.
Roel De Nijs wrote:You forget about the package of your java file. The directories which are part of the package should not be part of the classpath, only the source-directory (and eventually directories with already compiled classes) should be.
So make the src directory the current directory (cd E:\Development\workspace\BackToJava\). Then you can compile your file with javac com/ocaexam/tutorial/GreetingsUniverse.java. The IDE is doing that all for you, so now you can see what a lot of work it's doing for you
Roel De Nijs wrote:
Omar Jouda wrote:I just keep getting source file not found when trying to compile source code in a package on a different drive.
Could it be a network security issue? Or maybe you saved the file with a text editor and the text editor added ".txt" extension for you, so now the file is called MyClass.java.txt instead of MyClass.java?
Roel De Nijs wrote:That's true! But when I studied Java (10 years ago) I had to use Notepad, simply because our family pc was not capable of running an IDE. And you are right: it's frustrating to have compiler errors one after another when trying to make an application. An IDE is a lot easier, because it spots for you the compiler errors. But with a simple text editor you'll become more careful, just because a little mistake results in compilation error (and having to change source code, compiling again,...). So you'll be more aware of the mistakes you have made already and prevent you to make these mistakes again. And because you also don't have code completion in your text editor, you'll learn the Java API more quickly.
On the certification exam you don't have a compiler and you'll get a lot of code snippets which you have to study and decide if they compile, and if they do what will be the output. So there is no IDE to do that job for you. That's why you should consider preparing for the certification exam without an IDE.
And you are right: it's frustrating to have compiler errors one after another
Roel De Nijs wrote:
Omar Jouda wrote:I am just studying them now, as I have been used to the IDEs all the time.
If you are studying for the exam, you should do this definitely without an IDE. Just use NotePad or NotePad++ or the text editor of your choice and just use javac/java to compile/run your little programs.
Roel De Nijs wrote:It all depends on what you are planning to do in the future. If you want to become a java developer this exam is really a must-have (just like the OCPJP 7). If you prepare yourself seriously (and not just to pass the exam), you will (as you already described in your 1st post) learn a whole bunch about the java programming language. And that will definitely benefit the quality of the code you write.
Lalit Mehra wrote:Hi Omar,
It does worth it to be certified ... It feels great.
But above all you need to ask yourself that at what extent do you wish to pursue it, i mean will you build up on it or just leave the coarse after the certification.
Certifications are a good way to attain knowledge, and be somewhat more noticeable to the employers also.
Roel De Nijs wrote:But you are talking about command line. How are the commands to invoke java/javac different. As far as I know they are exactly the same. The only thing that is different, is the classpath separator: on windows it's a semicolon (;) and on Unix/Linux/Solaris it's a colon (.
java -cp . com.example.MyAmazingClass will work on every operating system where java is installed.
Roel De Nijs wrote:Because your constructor has invalid syntax. Take a close look to your constructor and see if you can spot the problem.