9 Replies - 1160 Views - Last Post: 27 September 2010 - 10:08 AM Rate Topic: -----

#1 taylorc8   User is offline

  • B&

Reputation: 150
  • View blog
  • Posts: 1,572
  • Joined: 21-July 09

.java files

Posted 26 September 2010 - 10:31 AM

I'm using Java with Netbeans 6.9.1, is there a simple way to avoid having to put classes in separate files?

What am I doing wrong here? This is really annoying.
Is This A Good Question/Topic? 0
  • +

Replies To: .java files

#2 anonymouscodder   User is offline

  • member icon

Reputation: 126
  • View blog
  • Posts: 710
  • Joined: 01-January 10

Re: .java files

Posted 26 September 2010 - 10:36 AM

I don't know if I get it, but you can do nested classes.

http://download.orac...aOO/nested.html
Was This Post Helpful? 1
  • +
  • -

#3 taylorc8   User is offline

  • B&

Reputation: 150
  • View blog
  • Posts: 1,572
  • Joined: 21-July 09

Re: .java files

Posted 26 September 2010 - 10:40 AM

That works, thanks.


Other than not being able to access non-static classes....

This post has been edited by taylorc8: 26 September 2010 - 10:46 AM

Was This Post Helpful? 0
  • +
  • -

#4 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: .java files

Posted 26 September 2010 - 11:31 AM

All public classes must be declared in their own .java file. This is really better practice to help better organize code. Yes, there are nested classes, but you shouldn't be using those unless you have a need for added encapsulation. For example, encapsulating an Entry class within the HashMap class. You *can* have a multiple non-public classes in the same file, even if there is already a public class in that file. But there cannot be two outer public classes in the same file.
Was This Post Helpful? 0
  • +
  • -

#5 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2972
  • View blog
  • Posts: 11,223
  • Joined: 15-July 08

Re: .java files

Posted 26 September 2010 - 12:42 PM

View Posttaylorc8, on 26 September 2010 - 12:31 PM, said:

I'm using Java with Netbeans 6.9.1, is there a simple way to avoid having to put classes in separate files?

What am I doing wrong here? This is really annoying.


Why would you want to? Code organization is crucial in most applications and the less code you have per class and the fewer classes per file, while still making your code readable, is better than shoving it all into one file.

However, as has been said, I would put non-public classes and stay away from nested classes unless nested classes are what you're going for.
Was This Post Helpful? 0
  • +
  • -

#6 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: .java files

Posted 26 September 2010 - 06:01 PM

Use C++ :)
I think Java make it quite clear: class ABCD is in ABCD.java
A class cannot, as in C++, being hidden somewhere
Was This Post Helpful? 0
  • +
  • -

#7 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2972
  • View blog
  • Posts: 11,223
  • Joined: 15-July 08

Re: .java files

Posted 26 September 2010 - 07:02 PM

View Postpbl, on 26 September 2010 - 08:01 PM, said:

Use C++ :)
I think Java make it quite clear: class ABCD is in ABCD.java
A class cannot, as in C++, being hidden somewhere


You make C++ sound so evil! :P
Was This Post Helpful? 0
  • +
  • -

#8 pbl   User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8381
  • View blog
  • Posts: 31,956
  • Joined: 06-March 08

Re: .java files

Posted 26 September 2010 - 07:06 PM

View PostDogstopper, on 26 September 2010 - 08:02 PM, said:

View Postpbl, on 26 September 2010 - 08:01 PM, said:

Use C++ :)
I think Java make it quite clear: class ABCD is in ABCD.java
A class cannot, as in C++, being hidden somewhere


You make C++ sound so evil! :P

Please be respectful, do not bitch on other languages in this forum :)
Was This Post Helpful? 0
  • +
  • -

#9 Dogstopper   User is offline

  • The Ninjaducky
  • member icon

Reputation: 2972
  • View blog
  • Posts: 11,223
  • Joined: 15-July 08

Re: .java files

Posted 26 September 2010 - 07:10 PM

...yessir... :)
Was This Post Helpful? 1
  • +
  • -

#10 macosxnerd101   User is offline

  • Games, Graphs, and Auctions
  • member icon




Reputation: 12742
  • View blog
  • Posts: 45,926
  • Joined: 27-December 08

Re: .java files

Posted 27 September 2010 - 10:08 AM

View Postpbl, on 26 September 2010 - 10:06 PM, said:

View PostDogstopper, on 26 September 2010 - 08:02 PM, said:

View Postpbl, on 26 September 2010 - 08:01 PM, said:

Use C++ :)
I think Java make it quite clear: class ABCD is in ABCD.java
A class cannot, as in C++, being hidden somewhere


You make C++ sound so evil! :P

Please be respectful, do not bitch on other languages in this forum :)

Because no language can prevent programmers from writing bad code. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1