Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

OCP Java SE 11 Developer Complete Study Guide

 
Mehmet Tahir Dede
Greenhorn
Posts: 7
  • 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
 
Paweł Baczyński
Bartender
Posts: 2236
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: 7
  • 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.
 
Liutauras Vilda
Marshal
Posts: 8196
583
Mac OS X VI Editor BSD Linux
  • 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: 8196
583
Mac OS X VI Editor BSD Linux
  • 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: 7
  • 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,
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic