• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Syntax error, insert ";" to complete FieldDeclaration

 
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have this method in my Subject class which make use of a Enum class and I am not sure where to put the ;

Hope someone can let me know how cos when I close the clsss with }  it still appear this message.

Here's the code;

 
Saloon Keeper
Posts: 7582
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No need to add anything. To the contrary, you need to remove something. Take a very close look at the entire line 11.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could also format your code, carefully checking each indentation.  This is really how you should always code.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Moores wrote:No need to add anything. To the contrary, you need to remove something. Take a very close look at the entire line 11.



Hi Tim,

Not sure if you are referring to {

Cos by right it should be { but my Eclipse IDE Oxygen keeps making me putting {{ and only when I put {{ then there's no error...

 
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:I have this method in my Subject class which make use of a Enum class and I am not sure where to put the ;


Maybe I'm missing something?  Which method are you referring to, and where is the Enum?
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:Hope someone can let me know how cos when I close the clsss with }  it still appear this message.


What is the message, and where does it appear from?
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

tangara goh wrote:I have this method in my Subject class which make use of a Enum class and I am not sure where to put the ;


Maybe I'm missing something?  Which method are you referring to, and where is the Enum?



The enum class is :

 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:

tangara goh wrote:Hope someone can let me know how cos when I close the clsss with }  it still appear this message.


What is the message, and where does it appear from?



Hi Ron,


Please find attached the error message.
error-from-eclipse.jpg
[Thumbnail for error-from-eclipse.jpg]
 
Ron McLeod
Marshal
Posts: 4491
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is the for loop inside a method?
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ron McLeod wrote:Is the for loop inside a method?



Hi Ron,  

Thanks for pointing out my mistake.

I have changed my method to as follows but I feel there is something wrong with it.

My purpose is that once I have the Enum class which  contains a HashMap which stores the key value pair.  Subject and the corresponding String ID, I would like this to be map to the List<Object>



I am stuck as to how to map it to List<Subject> in my controller where I have a getParameterValues.

Please advise me or give me some hints how to do it.

Tks.
 
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a few things wrong with your code but it is hard to know what to suggest because the intent of this method is unclear.

Forget this getValue() method for a second and please explain in English what it is that you are trying to achieve.

Note: Enums have an implicit "name" field and getName() method. This is unfortunate because so often "name" has significance to the project but is in conflict with enum's usage. My advice is to change "name" to something else so that you are not accidentally overriding the enum "name". Also, enums are typically in all upper case characters, e.g. L_PRI_CHINESE("L1").
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:
Cos by right it should be { but my Eclipse IDE Oxygen keeps making me putting {{ and only when I put {{ then there's no error...


Something to remember is tha when there is an issue with brackets or code outside of a method, that IDEs tend to attempt a guess at how to fix the problem, and they are often wrong.
Don't rely on them for that sort of thing.
 
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Dave Tolls wrote:. . . IDEs tend to attempt a guess at how to fix the problem, and they are often wrong. . . .

The standard Oracle compiler is even more likely to get it wrong. IDEs often suggest several corrections, which sometimes makes it even more difficult to understand the problem.
 
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Dave and @Campbell, I know what you guys mean by "the compiler is wrong" but to be fair—and for the sake of argument, because I'm in that kind of a mood at 4am — the compiler actually makes the suggestion based on a syntax rule that was violated. So, based on language syntax rules, its suggestion is probably technically correct. The problem is when the suggested "fix" doesn't logically align with the code author's actual intent. To your points though, many of the suggestions given are often based on a best "guess" which doesn't take into account other errors that could result if the suggested fix is applied.

The point I really wanted to make is that it helps to understand the syntax rules of the language you're trying to learn. Back when I was taking my first programming class in Pascal, out teacher always referred us to BNF and syntax diagrams and would walk us through one for each statement type we studied. We didn't realize it at the time but now in retrospect, that really taught us how to "think like the compiler" which made it easier to figure out what was actually going on when we got compiler errors.
 
Campbell Ritchie
Marshal
Posts: 79153
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good point: learnnin gthe BF would make it easier to understand the error messages.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:There are a few things wrong with your code but it is hard to know what to suggest because the intent of this method is unclear.

Forget this getValue() method for a second and please explain in English what it is that you are trying to achieve.

Note: Enums have an implicit "name" field and getName() method. This is unfortunate because so often "name" has significance to the project but is in conflict with enum's usage. My advice is to change "name" to something else so that you are not accidentally overriding the enum "name". Also, enums are typically in all upper case characters, e.g. L_PRI_CHINESE("L1").



Hi Carey,

Here's what I want to achieve.

I want to insert SubjectName and SubjectIDs together with Tutor ID into a table.
The SubjectName and SubjectIDs are 'constant' so I decided to use Enum which has a key value pair.
So now, I have a List<Subject>subjectlist which I am able to insert the ParameterValues into the database.
I'd like to know how to use HashMap to mapped this ParameterValues to the Enum so that it will give me the IDs.

and then I can insert it to the column SubjectIDs,  SubjectNames insides column SubjectNames and tutorId into column tutor.
so that the table will look like this

SubjectName    SubjectID    tutor_id
---------------    ------------   ---------
UPEnglish          2               1
UPMaths            3               1
UPEnglish          2               2

I hope I am clear.

Please guide me how to do the HashMap and the ParameterValues part.

Thanks.
 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't think enums are an appropriate mechanism for representing the concept you're trying to represent here. Subjects and their IDs are temporal, that is, they will probably change over a relatively short period of time. Changing an enum by adding or removing values can break a lot of code and that's a bad thing. Thus, enums are used for value sets like Boolean (false, true) or Suits of a standard deck of cards (Clubs, Spades, Hearts, Diamonds). These things have a limited number of distinct values that don't get added to or taken away from.  Subjects and their IDs are not like this. I suggest you use a class that can represent name/value pairs or a custom class that encapsulates the attributes of name and Id instead. With a class, you can create as many instances to represent however many different subjects as you need.
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:So now, I have a List<Subject>subjectlist which I am able to insert the ParameterValues into the database.

Why not insert the values directly into the database? Once inserted they should be persistent and not need to be inserted again, though they may need updating from time to time. As Junilu said, enum seems like the wrong vehicle for this. I even doubt you need a Map, it seems like just a list of Subject's would suffice for inserting into a database or read the list from a flat file. On the other hand, when reading the Subjects back in from the database, a Map might be a useful construct.
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:...and then I can insert it to the column SubjectIDs,  SubjectNames insides column SubjectNames and tutorId into column tutor.
so that the table will look like this

SubjectName    SubjectID    tutor_id
---------------    ------------   ---------
UPEnglish          2               1
UPMaths            3               1
UPEnglish          2               2


Right here you have the plan for a Subject class, having subjectName, subjectId, and tutorId as the fields. (Please don't skimp on typing when creating variable names, more descriptive names help with maintenance down the road. Also, don't use underscores (_) in Java variable names.)

You might have some or all of these constructors:
 
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just as a matter of exercise, you can have your Subject class implemented as an enum, including a look-up table. For instance:

Given the objections against an enum, I leave it up to you to see if this is useful.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:Just as a matter of exercise, you can have your Subject class implemented as an enum, including a look-up table. For instance:

Given the objections against an enum, I leave it up to you to see if this is useful.



Hi,

I'd like to clarify on your code :

private static void createMap() {
       if (map.isEmpty()) {
           Arrays.stream(MyEnum.values()).forEach(flup -> map.put(flup.id, flup));
       }
   }

Could you let me know this flup is referring to  ?

 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Tangara,

the 'map' is referring to the map in your opening post:

but here I used a lookup Map<Integer, MyEnum>. The idea is that I turn your Subject itself into an enum, but instead of using your Subject, I created my own enum, just as an example how it could be done. But that is not to say I find it very useful, though.

The reason that I check for the emptyness of my map, is that I could not manage to create that map in the constructors of MyEnum (I kept getting an error here), so now I used a form of 'lazy initialization': I only filled the map first time I use it. Java does not support lazy variables explicitly (only in streams), so I did it this way.

But useful or not, I hope it is illustrative.

Edit: 'flup' is just a name I give to the MyEnum values.

What happens here is equivalent to this code:

For such simple oneliners I often use some phantasy names for variables, but I admit that it may not be clear to others. Maybe the current book (about bad programming habits) is more for me than I thought!
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of lazy loading the map you could have done it in a static block.

 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That was one of the things I tried, but first all the values must have been initialized. Maybe I did something wrong, can you give it a try and see if that works?
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I did try it and it does work. Perhaps the static block needs to be specified after the constructor (?).
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Carey!
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Junilu Lacar wrote:I don't think enums are an appropriate mechanism for representing the concept you're trying to represent here. Subjects and their IDs are temporal, that is, they will probably change over a relatively short period of time. Changing an enum by adding or removing values can break a lot of code and that's a bad thing. Thus, enums are used for value sets like Boolean (false, true) or Suits of a standard deck of cards (Clubs, Spades, Hearts, Diamonds). These things have a limited number of distinct values that don't get added to or taken away from.  Subjects and their IDs are not like this. I suggest you use a class that can represent name/value pairs or a custom class that encapsulates the attributes of name and Id instead. With a class, you can create as many instances to represent however many different subjects as you need.



Hi Junilu,

The subjects and Ids will never change.  In this case, is Enum suitable or there is a better way to handle things ?

Actually, I find the class Subject seems to be redundant now there is Enum and everything seems to be there for the insertion to be done.

 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:



Thanks for the clarification.

However, I need the return to be in a List cos I am using List<Subject> as an insertion into the database,

So the List<Subject> must have a list of SubjectNames and a list of matching SubjectIDs.

But, I am not sure how to do it.  

 
Junilu Lacar
Sheriff
Posts: 17644
300
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:The subjects and Ids will never change.


I'm not convinced that's entirely true. Subjects being taught in schools come and go all the time. There are new subjects that are offered, some become obsolete and are eliminated from the curriculum, others are renamed, etc. While those kind of changes may not happen every day, they do occur or have the potential to occur at the start of every term. The question really is whether or not you have to change your code at all if one or more subjects get added, modified, or removed. I would still argue that Enums are not the appropriate way to represent this idea.
 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

tangara goh wrote:(...)
So the List<Subject> must have a list of SubjectNames and a list of matching SubjectIDs.

But, I am not sure how to do it.  


Well, you could have this Subject enum:

with this use:

but I agree with Junilu: a Subject class like in your opening post, and oerhaps with a field: MOESubjectIDs moes, wasn't bad at all, and much more flexible.
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Piet Souris wrote:

tangara goh wrote:(...)
So the List<Subject> must have a list of SubjectNames and a list of matching SubjectIDs.

But, I am not sure how to do it.  


Well, you could have this Subject enum:

with this use:

but I agree with Junilu: a Subject class like in your opening post, and oerhaps with a field: MOESubjectIDs moes, wasn't bad at all, and much more flexible.



Hi Piet,

Thanks for showing me the above.

I need to highlight that I am using DAO pattern where I have a SubjectDAOImpl class that use Subject class to insert the subject which make us of a SQL insert query.  The Manager class is one which hide the logic and Controller calling the Managerial and insert the method insdie.

Actually, at this point, I am abit confused as in should I use TutorDAOImpl to insert the Subject class List<Subject> or still use SubjectDAOImpl and with the Subject now change to Enum altogether, how should I piece everything together ?

Hope to hear some advice how best to move things forward.

Tks again.
 
Carey Brown
Saloon Keeper
Posts: 10687
85
Eclipse IDE Firefox Browser MySQL Database VI Editor Java Windows ChatGPT
 
tangara goh
Ranch Hand
Posts: 1021
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Carey Brown wrote:perhaps this TUTORIAL will help



But this is just one entity.
I am using 2 entities now - tutor and subject.

cos if I use JPA, they will normally use dependencies and used tutor to insert the subject and not using subject to insert by itself.

That's the area I am stumped.  I wonder should I use DAO pattern for my case.

Any advice is appreciated.

 
Piet Souris
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My knowledge and experience of DAO's are limited to what I just read in the tutorial that Carey pointed to, so my idea might be absolute nonsense, in which case many here will let us know.

I would have a third entity as well, a class SubjectTutor that has a Subject and a Tutor as fields, and also a Period that indicates in what period this subject is taught by this tutor (if there is any need for such information). From this there might be a class 'SubjectsAndTotors' that has a subject, a period and a list of tutors. You can deduce the relevant DAO's for these classes, although the classes and DAO's are so almost 1-1 that you might skip the DAO part.

So in a demo you might have a class Subject, a class Tutor and a class SubjectByTutor. From this a class or Map<Period, SubjectTutor> can be derived to see what subjects are given by what tutors in what period. I think the required DB tables are obvious. Anyway, this would probably my first attempt.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic