Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Package help  RSS feed

 
Asiuol Star
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi -- I am completely new to Java.

I am trying to create a class that calls another class. Some googling told me that I should be using packages, but I'm having a bit of trouble getting it to work.

So far, I have a class that defines a Die object. I wrote "package dice;" as the first line of code in that program. I am now trying to make a second program that uses Die objects. I wrote "package dice;" as the first line in that code, but when I try to compile the file it gives me "cannot find symbol" errors when I try to call new Die(). Any help with this would be appreciated. Thanks!!
 
Paweł Baczyński
Bartender
Posts: 2054
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post your code?

You don't need to use packages to be able to use multiple classes.

And welcome to the Ranch!
 
Campbell Ritchie
Marshal
Posts: 55678
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome again

If you go through the Java™ Tutorials, you can read all aboiut packages. At the bottom of the 3rd page, it says this:-
If you do not use a package statement, your type ends up in an unnamed package. Generally speaking, an unnamed package is only for small or temporary applications or when you are just beginning the development process. Otherwise, classes and interfaces belong in named packages.
At your stage you are probably writing only small applications so you can “Generally speaking” use the unnamed package. Also, if you add package names, the compilation process becomes more difficult and you are liable to get all confused at a stage when you want everything as easy as possible.
 
Asiuol Star
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you both very much for your help!! I solved my problem.
 
Campbell Ritchie
Marshal
Posts: 55678
161
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!