aspose file tools*
The moose likes Beginning Java and the fly likes Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Classes" Watch "Classes" New topic
Author

Classes

Sebastien Zerbato
Greenhorn

Joined: Nov 14, 2011
Posts: 24
Hello, I am new to java and I have to code a class. The demonstrator from my course told me to use another class to create a type that is needed in my class, however, I cannot compile due to errors with the declaration of that class. I have checked the chapter in my java book that relates to class declaring and still don't see the issue.
This is the code:



Thanks in advance.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18896
    
  40




A couple of obvious issues....

* The "class" keyword is used to declare a class.

* Code are part of initializers, constructors, or methods. Java doesn't just allow code anywhere.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Sebastien Zerbato
Greenhorn

Joined: Nov 14, 2011
Posts: 24
"A couple of obvious issues....

* The "class" keyword is used to declare a class.

* Code are part of initializers, constructors, or methods. Java doesn't just allow code anywhere.

Henry"
So what you're sating I should do is put that "public tab" in a different file and call it from this file ?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18648
    
    8

Sebastien Zerbato wrote:So what you're sating I should do is put that "public tab" in a different file and call it from this file ?


You will find that whenever somebody on a forum says "So what you're saying is..." the answer is inevitably "No, I didn't say any such thing."

And so it is in this case.
Sebastien Zerbato
Greenhorn

Joined: Nov 14, 2011
Posts: 24
Ok, let me rephrase this then, what do you think would solve my problem ? Or do you think that creating a different file for "tab" would work ? (in the end, i am just asking for your opinion, not saying that you said or implied that. But whatever.)
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18648
    
    8

It's hard to say. That code which Henry posted... did you mean it to be a class? (Henry pointed out several problems with it, if it was supposed to be a class.) If you did, then yes you should put it in its own file. But that's only one thing you should do. The other things... well, they were what Henry actually said.
Sebastien Zerbato
Greenhorn

Joined: Nov 14, 2011
Posts: 24
Ok thank you (I meant it to be a class)
But I don't see any problem with the actual encoding in the public tab ? Could you point it out to me ?
Thanks in advance.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

How is Java supposed to know you meant for it to be a class?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sebastien Zerbato
Greenhorn

Joined: Nov 14, 2011
Posts: 24
I know, now that I look at it, I can see that there was no evidence of it being a class.
Thank you for question though.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39390
    
  28
You are writing too much code before finding mistakes. You should not write more than about 5 lines without compiling it. Then you would have known because you would have got an error saying “class interface or enum expected”.
You have got some spelling errors in what you quoted, so the code won’t compile. You should always use ctrl-C ctrl-V to copy code. You have also some code //commented out. We do not need to see that.
You have some incorrect naming conventions, eg use of underscores_ in_ identifiers_.
You should not use StringTokenizer; click on that link to find out why.
Sebastien Zerbato
Greenhorn

Joined: Nov 14, 2011
Posts: 24
Thank you everybody, I managed to find my mistakes. for now ;)
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39390
    
  28
And what was your mistake?
Sebastien Zerbato
Greenhorn

Joined: Nov 14, 2011
Posts: 24
I don't remember, I got blocked after that, and I realized the way I had approached the problem with was just way too complicated so I started from scratch again. My file now compiles and executes when tested with another program. Thank you for sparing me with your time.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39390
    
  28
Sebastien Zerbato wrote:I don't remember . . .
What a nuisance. If you don’t remember, you will repeat that mistake.
Thank you for sparing me with your time.
You’re welcome
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Classes