Win a copy of Functional Design and Architecture this week in the Functional programming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Classes

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23907
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



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
 
Sebastien Zerbato
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"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 ?
 
Sheriff
Posts: 26764
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 26764
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67590
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is Java supposed to know you meant for it to be a class?
 
Sebastien Zerbato
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Marshal
Posts: 73951
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you everybody, I managed to find my mistakes. for now ;)
 
Campbell Ritchie
Marshal
Posts: 73951
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what was your mistake?
 
Sebastien Zerbato
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 73951
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
We're all out of roofs. But we still have tiny ads:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic