• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error in Mala Gupta's OCA Java SE7 (page 28)

 
rashee thirtha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

OS: Mac
Java:1.7

(optional) Eclipse: Luna


In page 27, there is a piece of code (before Fig 1.8)




When I ran this on the terminal, I am getting the following error



When I ran the same on Eclipse, I got




Am I missing something here or is this an actual error from the author?
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35269
383
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The book is correct.

When running from the command line, what command are you running? Also, check for typos in the class name and within the file. Such as forgetting to make the main method static.

In Eclipse, you forgot to add the arguments. Go to run > run configurations and find the one for this class. (You can filter by text and type "Hello".) Then on the arguments tab, enter 1 2 for the program arguments text area.
 
rashee thirtha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you! I was able to run it on Eclipse after I set the Arguments in Run configuration.

However, no luck on the command line. Also, which folder location should I run it under? I tried going inside /workspace/pkg/src. I also tried it under /workspace, same error.

I used the following command.



However, I tried a few others and got the same error for all.

 
Swastik Dey
Rancher
Posts: 1637
6
Android Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like a classpath issue.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi rashee thirtha,

First of all, a warm welcome to CodeRanch!

rashee thirtha wrote:I used the following command.


That's one of the reasons why people should not use an IDE while preparing for the OCA exam. An IDE does stuff behind your back and for the exam you need to know these things. So get rid of the IDE and use nothing but your favourite text editor, javac (to compile your programs) and java (to run your programs).

So before you can run your application, you need to compile it first using javacAnd when you successfully compiled your source code file, you'll get a .class file. This file you can run with java

Hope it helps!
Kind regards,
Roel

(Note: in order to compile and run your application flawlessly, you should be in the appropriate directory or use -cp option to add directories to your classpath)
 
rashee thirtha
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much Roel! Sorry for the late reply. I have been a bit busy at work.

It did work now! I realized the mistake I was doing before. I was not running it immediately after compiling. Your explanation was very clear.

As far as IDE is concerned, yeah, I do get tempted to run it in there since I am so used to using it. Frankly, the command line is slightly intimidating to me. But i guess I will take your advice and go that route to better prepare.



I had another question Roel. I have booked my exam for May 16th, which gives me 15 days to prepare. Do you think I might be able to prepare well in 2 weeks? I have a basic understanding of Java and have been working on Selenium automation with Java for a few years. However, after having read the first chapter itself, I realized there were things I did not know..well, maybe because it was not relevant to what I was working on. I have bought Mala Gupta's book and Enthuware set of tests. I have a full time job and am planning to do an all day study this weekend and the next and maybe 4 hours during weekdays. Your input will be much appreciated!


Thank you.
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
rashee thirtha wrote:It did work now! I realized the mistake I was doing before. I was not running it immediately after compiling. Your explanation was very clear.

Glad to hear it's working for you now!

rashee thirtha wrote:Frankly, the command line is slightly intimidating to me. But i guess I will take your advice and go that route to better prepare.

At first it will probably be a little bit harder than using an IDE, but you'll definitely benefit from it. It's also mentioned by other ranchers following this advice (e.g. here). And here you'll find different opinions about this topic.

rashee thirtha wrote:I have booked my exam for May 16th, which gives me 15 days to prepare. Do you think I might be able to prepare well in 2 weeks? I have a basic understanding of Java and have been working on Selenium automation with Java for a few years. However, after having read the first chapter itself, I realized there were things I did not know..well, maybe because it was not relevant to what I was working on. I have bought Mala Gupta's book and Enthuware set of tests. I have a full time job and am planning to do an all day study this weekend and the next and maybe 4 hours during weekdays. Your input will be much appreciated!

I think that might be tight, very tight. But maybe you could pull it off. So maybe you can assess your progress/knowledge after 1 week or so. And if it's needed you can postpone your exam. You can reschedule your exam for free. According to the Reschedule Policy of the Oracle Certification Program Policies there's just 1 restriction: you must reschedule at least 1 business day prior to your exam appointment.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic