• Post Reply Bookmark Topic Watch Topic
  • New Topic

ImportExample from Chapter One OCA Java 8 book  RSS feed

 
Niall Kev
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Trying to do the following sample from the book:



I am using notepad ++ and the file compiles using javac ImportExample.java

When I try to run I get

C:\EDGE\OCA>java ImportExample
Error: Could not find or load main class ImportExample

In the book it says it should print out a random number between 0 and 9.

I am wondering is it not finding the import java.util.Random as my code is in a different directory or something. any help much appreciated
 
Niall Kev
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
turned out to be a CLASSPATH issue. needed to add folder I'm working in to classpath. still don't know why as works on different machine but might be helpful to others
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37181
515
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you got it working.

When you have a classpath environment variable set, Java doesn't know to use the current directory unless you tell it.

Note: There are multiple OCA books. If you post more book questions, please mention the author or publisher so people can better help you.
 
Niall Kev
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jeanne. It was your OCA 8 book(OCA: Oracle Certified Associate Java SE 8 Programmer I Study Guide: Exam 1Z0-808)

Wasn't expecting a reply from the author

I had one other question. Why is there an assessment test before chapter one? I tried to answer the questions and got the first 5 wrong. Are we suppossed to do this test before reading the book. Didn't make sense for me.

Thanks for replying
 
Liutauras Vilda
Marshal
Posts: 4511
306
BSD
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Niall Kev wrote:Wasn't expecting a reply from the author

Exciting, isn't it?

Niall Kev wrote:Why is there an assessment test before chapter one?

I guess in order to give you a clear feeling what is all about, I mean, so you wouldn't underestimate exam, would take further advises seriously and would read chapters carefully.

Some people who taking an exam are complete beginners, so maybe yes, not much you could expect from them at that moment. But there are also many who have extensive experience in industry, so I think for them it is a good indication what basic exam looks like, so they would understand the meaning of word "basic" in that context.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!