File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Vector cannot be private? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Vector cannot be private?" Watch "Vector cannot be private?" New topic
Author

Vector cannot be private?

Robert Ploch
Greenhorn

Joined: Jun 05, 2002
Posts: 19
Hi
I`m developing at the moment this class ( a graph containg nodes and edges etc.)

Why is it not possible to declare the global variables as private?
Graph.java:3: modifier private not allowed here

thx for answers
Robert Ploch
[ May 19, 2003: Message edited by: Robert Ploch ]
[ May 19, 2003: Message edited by: Robert Ploch ]
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

I don't know why you see that error, but you have to fully qualify Vector or import it. Otherwise, you will see an error complaining about not understanding vector. Use:
import java.util.Vector;
on the top line and see if that helps.
Other points, they're member variables, not globals. Java does not permit global variables. Member variables can, of course, be private. There's nothing illegal in how you've declared them. However, member variables should start with a lower-case letter. Code is communication. By following conventions you communicate effectively!
Robert Ploch
Greenhorn

Joined: Jun 05, 2002
Posts: 19
Thanks for the explanation of global variables. I screwed some definitions
I tested your hint, but the compiler (newest version) still posts this error. It doesn`t depend only on the Vector-Class, the compiler is already complaining about the int with the same error.
It also confuses me, because i didn`t do it different than all the times before.
But see yourself
You`ll find the files on:
www.robertploch.de/files/Node.java
www.robertploch.de/files/Edge.java
www.robertploch.de/files/Graph.java
[ May 19, 2003: Message edited by: Robert Ploch ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61449
    
  67

If Nodes and Edges are class names then you cannot also use them as variable names.
To avoid this be sure to follow the Java naming conventions of using lowercase for the initial letter of variable names, and uppercase for classes.
hth,
bear


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Robert Ploch
Greenhorn

Joined: Jun 05, 2002
Posts: 19
thanks, but the variables do have the name`s: Edges & Nodes;
the class`s names are Edge & Node, without 's', so it should`nt come to an error ( i hope )
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
There is absolutley nothing wrong with using private where you are using it. What version of Java? Using an IDE? Can you compile a program that has nothing except a single private variable?


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Robert Ploch
Greenhorn

Joined: Jun 05, 2002
Posts: 19
i think i`ve got the error
i programmed another, still unready file in the same directory as Graph.java
javac compiled everything and only showed some errors in the unready file.
now i`ve deleted the file and some errors in graph.java were born
ok, now bugfixing
thx for helping
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
thanks, but the variables do have the name`s: Edges & Nodes; the class`s names are Edge & Node, without 's', so it should`nt come to an error
I strongly recommend that you follow Java Coding Conventions, -- it will make it easier for everyone (including you) to understand your code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Vector cannot be private?