This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Command Line Confusion

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to follow my book (Jeanne Boyarsky and Scott Selikoff, OCA Java SE 8 Programmer I Study Guide, page 6), but I'm stuck here:

[If place inline fails, the attached image that's supposed to be here is Javac_bookPage6.jpg]

Here's the class code that I want to test (note that my class name is "Main" instead of "Zoo"):

I was only able to assume that "javac Main.java" and "java Zoo" were supposed to be executed from a command line, so I tried this:

[if place inline fails, the attached image that's supposed to be here is Javac_CMD.png]

But as you can see, nothing happened. Any idea what they're trying to tell us to do based on the Javac_bookPage6.jpg screenshot?
Javac_bookPage6.jpg
[Thumbnail for Javac_bookPage6.jpg]
Javac_CMD.PNG
[Thumbnail for Javac_CMD.PNG]
 
Marshal
Posts: 65782
250
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please avoid Screenshots, which can be difficult to read. There is no such instruction as $; any dollar signs in the book represent the start of the command line.
Why are you only writing javac? Why are you not using the java command, too? Why have you added a package name to your class? Why didn't you copy what the book wrote? It tells you exactly which instructions to use? It also tells you that the Zoo program doesn't do anything useful, so you won't see anything happen at the terminal.
How much programming experience do you have? The book you have got is intended for experienced programmers planning to sit a certification exam. It isn't supposed to be a tutorial for beginners. It does however say that after javac you should expect to see nothing, which is exactly what your screenshot shows. That means what you are saying in line 6 isn't quite correct. If that text appears, it means the java instruction worked correctly.
 
Marshal
Posts: 14039
234
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
javac is the Java compiler. If you get no message, that's a good thing. It means the compiler ran successfully and your program has been compiled to a .class file. To run the program, use the java command.
 
Saloon Keeper
Posts: 6227
58
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm guessing that you mistakenly typed the '$' on the command line. This is a typical *nix command line prompt and not something you actually type.

So, you should have entered
 
Saloon Keeper
Posts: 21128
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually, it's messier than that. There's a package structure. So the actual class to execute via the "java" command is sam.main.Main.

 
Sam Peterson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:How much programming experience do you have? The book you have got is intended for experienced programmers planning to sit a certification exam. It isn't supposed to be a tutorial for beginners.


I took several courses involving Java during my associate-degree-earning-days from 2011 - 2013. I then transferred to a university to earn a bachelor's degree in network engineer courses. Since I've graduated with my bachelor's degree in May 2019, I've walked away from what I studied at the university because I enjoyed programming with Java far more. I'm hell-bent on starting a career with Java development, but because I don't have any job experience, I'm having a hard time finding an entry level job. That's why I need to get the certification.

Junilu Lacar wrote:javac is the Java compiler. If you get no message, that's a good thing. It means the compiler ran successfully and your program has been compiled to a .class file. To run the program, use the java command.


Regarding output from commands in a Linux terminal, a lot of the time the safe assumption is that no news is good news (because it means the command you typed in didn't cause any errors). But this? What is the point? What if I'm supposed to explain what happened with the javac and java commands on the exam?

Tim Holloway wrote:Actually, it's messier than that. There's a package structure. So the actual class to execute via the "java" command is sam.main.Main.


It still didn't work:
CMD_failed01.PNG
[Thumbnail for CMD_failed01.PNG]
 
Tim Holloway
Saloon Keeper
Posts: 21128
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It won't help your attempts to enter the field if you can't even copy-and-paste command line text instead of doing screenshots.

I'll give you a hint. Java package structure on Windows is expected to map filesystem structure. It's very important, however, to understand what packages are, what the difference between a filesystem path and a package path are and what a classpath is.

Your example was not well suited for the basic "hello, world!" type of introduction to Java because it does expect you to know all of those things.
 
Sam Peterson
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a simple java file called CMDtest.java:

When I executed it in the command prompt for a non-package (file system path) folder, it successfully created the CMDtest.class file in the same C:\JavaFileSystemPath folder that the CMDtest.java file is in, but it failed to output the second print statement.
Here's what happened in the command prompt for that:

C:\Users\User>cd C:\JavaFileSystemPath

C:\JavaFileSystemPath>javac CMDtest.java

C:\JavaFileSystemPath>java CMDtest
I'm the main method.

C:\JavaFileSystemPath>

Why do I not also see "sum = 5" after "I'm the main method."?

When I executed an exact replica of the CMDtest.java file in the command prompt for the package folder, not even the javac compiler command worked.
Here's what happened in the command prompt for that:

C:\Users\User>cd C:\murach\java_eclipse_ee\SamsProjects\JavaPackageSystemPath\sr
c\cmdtest

C:\murach\java_eclipse_ee\SamsProjects\JavaPackageSystemPath\src\cmdtest>javac C
MDtest.java

C:\murach\java_eclipse_ee\SamsProjects\JavaPackageSystemPath\src\cmdtest>java CM
Dtest
Error: Could not find or load main class CMDtest

C:\murach\java_eclipse_ee\SamsProjects\JavaPackageSystemPath\src\cmdtest>

If you have any doubts, here is the file's path properties from the Eclipse IDE:


PackageSystemPath.PNG
[Thumbnail for PackageSystemPath.PNG]
 
Tim Holloway
Saloon Keeper
Posts: 21128
131
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because the actual classname is cmdtest.CMDtest.

And, incidentally, if you're using the Eclipse IDE, it's normally going to automatically compile source classes.

Although if you don't define the project structure properly, it may not compile the class where you think it will.

You can use code tags to bracket pasted command-line samples, by the way. Code tags can actually be used for all sorts of pre-formatted text, including SQL and XML.

They keep our message editor from mangling the spacing.
 
Something must be done about this. Let's start by reading this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!