Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it netbeans or is it me?

 
Stephen Fairchild
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am both new here and to Java. I took a class last semester but he never taught us the import things

First off I know how to create a class and how to create objects

My problem is.. I don't know how to create objects of classes that are not in the same .java file

I know by looking through my folders that netbeans compiles the .java file for you so im wondering if that has something to do with it

Whenever I make a .java file with multiple classes I have no trouble creating objects, but if i have 2 .java files with different classes I can't call one class from the other .java file..

Is this because it won't work like this in netbeans or am I just not understanding this right?

Maybe I shouldn't use netbeans? and maybe eclipse???
 
Tom Reilly
Rancher
Posts: 618
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not NetBeans. You need to learn the "import things". If you post your code along with the errors you're getting, someone can probably help.
 
Stephen Fairchild
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well thank you!

In my persuit of making an example and getting errors I got it to work.

I found out that netbeans was creating the new .java file in the wrong spot.

I now have both .java files in src>project>
and both .class files are in build>classes>project

 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Next you might want to learn about packaging in Java, and Welcome to Javaranch
 
Greg Brannon
Bartender
Posts: 563
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may find this article useful:

Access to Members of a Class

You'll note the mention of "package-private" in that discussion, which is what Vijitha may be referring to in his/her response (sorry, I'm not certain of the gender of that name). Said another way, you can specify that multiple classes are members of the same package name by adding the statement:



on the first line of code in each class file that you want to be a member of the same package. This 'packaging' increases the visibility of one class to all others in the same package.

You can learn more about the Java package concept, naming conventions, etc., later in the link I included above.
 
Vijitha Kumara
Bartender
Posts: 3913
9
Chrome Fedora Hibernate
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greg Brannon wrote:... (sorry, I'm not certain of the gender of that name)...

You will find so many of those here in the forums
And welcome to JavaRanch, Greg
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic