java class hierarchy

T

Thomas

1)Hello I noticed that java needs a separated file for each file. Isn't it
too much ? I writing a simple project and have to use too many of them I
suppose. Is there any way to reduce it, for example putting the code of
several classes into one file ?

2) I have two interfaces :
==============================================================
public interface Value {
double evaluate () throws IllegalStateException;

}
=============================================================
public interface Arguments extends Value
{
int arity ();
int missingArguments ();
void addArguments (double) throws IllegalStateException;
}
=================================================================

I get identifier expected at the last line it the second class, Whats wrong
?
 
C

Chris Dollin

Thomas said:
1)Hello I noticed that java needs a separated file for each file.

You mean for each /class/, and it doesn't -- it requires a separate
file for each /public/ class.
Isn't it too much ?
No.

I writing a simple project and have to use too many of them I
suppose. Is there any way to reduce it, for example putting the code of
several classes into one file ?

(a) nested classes.

(b) non-public classes.

(c) why does it worry you?

(d) using an IDE may help.
2) I have two interfaces :
==============================================================
public interface Value {
double evaluate () throws IllegalStateException;

}
=============================================================
public interface Arguments extends Value
{
int arity ();
int missingArguments ();
void addArguments (double) throws IllegalStateException;
}
=================================================================

I get identifier expected at the last line it the second class, Whats wrong
?

The expected identifier following the type `double` for the method
`addArguments` isn't there.
 
D

Daniel Pitts

1)Hello I noticed that java needs a separated file for each file. Isn't it
too much ? I writing a simple project and have to use too many of them I
suppose. Is there any way to reduce it, for example putting the code of
several classes into one file ?

2) I have two interfaces :
==============================================================
public interface Value {
double evaluate () throws IllegalStateException;

}

=============================================================
public interface Arguments extends Value
{
int arity ();
int missingArguments ();
void addArguments (double) throws IllegalStateException;}

=================================================================

I get identifier expected at the last line it the second class, Whats wrong
?


Every argument in Java requires a name, unicek c++

void addArguments(double arg) throws IllegalStateException;
 
R

Roedy Green

1)Hello I noticed that java needs a separated file for each file. Isn't it
too much ? I writing a simple project and have to use too many of them I
suppose. Is there any way to reduce it, for example putting the code of
several classes into one file ?

Each public class must go in a different *.java file named the same as
the class including case. You can put bundle up other classes more
than one to a file, but it is not a good idea. You will have trouble
finding the code later.
 
N

nebulous99

You mean for each /class/, and it doesn't -- it requires a separate
file for each /public/ class.


(a) nested classes.

(b) non-public classes.

(c) why does it worry you?

(d) using an IDE may help.

Eclipse is highly recommended. Some people also like netbeans. A few
people here will now try to sell you something; I suggest you ignore
them unless you are wealthy enough that you routinely lose fifties and
C-notes between the sofa cushions and don't miss them for months
before eventually finding them again. Preferably, rich enough that a
whole roll of these can go missing and this fact go unnoticed for
months.

Not using an IDE is less of an option with Java than with many
languages, because of this many-files requirement. Any nontrivial
project is going to blow out the maximum of four recently-opened files
lots of text editors have on their file menu MRU, which means manually
navigating and typing stuff for a minute or two fairly often when
changing files. Tabbed editors with ten-item MRUs are out there but
many are crippled or timebombed instead of free, and none will cope
with anything truly substantial without running out of room for tabs
you can still use easily and conveniently, running out of MRU items,
or both.

Eclipse, and probably all other IDEs, provides handy built-in project-
file navigation and Eclipse at least definitely also provides tabbed
editing of code. The left window pane in Eclipse by default will have
a tree of your project's source files and ancillary stuff like
resources and package-html files and the like; one double-click and
you're in any file you please, with maybe some scrolling if you have a
big project and a low resolution monitor (<1024 pixels high, say).

Someone here will probably be perverse now and remark that something
called "emacs" has some obscure "mode" that does the same thing with a
file tree at left, but I doubt this is the route you want to go. Not
if you don't fancy spending many hours memorizing obscure hotkeys from
cheatsheets before you can even contemplate being productive, and
having to use wacky keyboard commands to get to, select in, and get
back from the tree pane. Not to mention the tree pane even if
identical to Eclipse kind of loses its luster when cramped down to
being only 24 items high max, and you would probably have to find,
download, and install a plugin to get it to boot.

Eclipse is easy enough to use that you can just install it, run it,
look at a few things quickly, and then start working in it without
prior experience of anything except some Java knowledge and basic GUI
manipulation knowledge of the sort taught in grade school nowadays.
You can go from Eclipse-n00b to a working Hello, World in less than
half an hour very easily, and probably in about 10 minutes.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top