• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

OCP Java SE 11 Developer Complete Study Guide

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear All,

I would like to ask for the error "Random can not be resolved to a type" on the page 16, Chapter 1.

It says the code below generates an error as Random can not be resolved to a type but when I test it it gives an error like  "error: cannot find symbol".

Code is :


Could you please inform me if you get the same error that I get while compiling with Java SE 11.2
 
Bartender
Posts: 2237
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What version of javac are you using?

javac ImportExample.java
ImportExample.java:3: error: cannot find symbol
       Random r = new Random();   // DOES NOT COMPILE
       ^
 symbol:   class Random
 location: class ImportExample
ImportExample.java:3: error: cannot find symbol
       Random r = new Random();   // DOES NOT COMPILE
                      ^
 symbol:   class Random
 location: class ImportExample
2 errors


javac -version
javac 17.0.1
 
Mehmet Tahir Dede
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use java se 11, as suggested in the book.
 
Marshal
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And.. did you import:

?
 
Liutauras Vilda
Marshal
Posts: 8988
652
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Mehmet Tahir Dede wrote:It says the code below generates an error as Random can not be resolved to a type but when I test it it gives an error like  "error: cannot find symbol".


To me not quite clear what are you trying to address here, whether the wording in error message is different comparing spoken language explanation what will happen vs actual compilation error given by the compiler. Or you expected something totally different in general?
 
Mehmet Tahir Dede
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Liutauras
Thank you so much for your reply.

I am aware that when we add the library code will not give any error. Problem here is the error that I get is different than the error mentioned in the book OCP Java Developer 11, page 16, chapter 1.

Dear Pawel,
Thank you so much for your reply too.

I see that you are getting the same error as I get. This means problem is about the book' s error message. Most probably book writes the error which belongs to an older JDK than JDK11.

Kind Regards,
 
author & internet detective
Posts: 42056
926
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"DOES NOT COMPILE" is never the error you should expect to see. It's what we put in comments when code does not compile. You aren't expected to know the exact text of compiler errors for the exam. Just whether it does or not.
 
Mehmet Tahir Dede
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you so much Jeanne,...
 
You guys wanna see my fabulous new place? Or do you wanna look at this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic