Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Teacher said This is not a correct code

 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the assignment was to make a JFrame then three sliders one textarea the move slider and change the color of textfield accordingly.
my code is..
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I wouldn’t call it correct either.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Listeners not connected to the component they are listening.
Three static fields.
Three declarations on the same line.
Dreadful use of = inside ().
Having those components as fields rather than local variables.
[] after the identifier name. Any why do you want an array in the first place?
Using null layout.

And there is bound to be more.
 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:Listeners not connected to the component they are listening.
Three static fields.
Three declarations on the same line.
Dreadful use of = inside ().
Having those components as fields rather than local variables.
[] after the identifier name. Any why do you want an array in the first place?
Using null layout.

And there is bound to be more.


Thanks sherrif, but the program running absolutely fine.
Then why ??
write more about why not static variables here, i am using only one object here then that should be correct ??
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"running fine" is an extremely poor metric to measure the quality of code. Crappy code can "run fine". Are you satisfied with crappy code?
 
Campbell Ritchie
Sheriff
Pie
Posts: 49733
69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Static members do not belong to objects, but to the class. And those fields have poor names. Bear was being kind calling your code crappy.
 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Sherrif.
Thanks Marshal.
Actually this code is written by one of my Class-met. i told him that it is not a correct way to write a program, BUT i don't know why he always reply that the output is fine, so my program is correct.
i told him that your program is dependent only on one object , and when dependent word comes into programming unnecessarily then either you are not writing that code in java or you are not a java programmer.
But again his reply is same as before.
at last i had to post his code here on the same way he posted his code on our class' google group.
But No his reply is same as before.
At last i told him that he is a IMMUTABLE OBJECT and no method one can change the values in you.
if you like to say somthing to him then please open this link....
Google Group
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> if you like to say somthing to him then
> please open this link....

why? ...

so he can write better code for you to
submit as you own?
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you indeed tried to submit your classmate's code as your own, then you're following the wrong path. You won't learn anything that way, and if you want to be a developer it will only hurt you in the long run.
 
Nikhil Sagar
Ranch Hand
Posts: 216
Java Linux Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:If you indeed tried to submit your classmate's code as your own, then you're following the wrong path. You won't learn anything that way, and if you want to be a developer it will only hurt you in the long run.


Rob Sir, I am totally agree with you. But i have submitted my own assignment 2 days before him.And these was no such mistake as in my class-met's assignment.
He submitted assignment after me .it is open for all means if someone submits his/her assignment so all other can see his/her assignment and if there is any mistake then anyone can tell him that there is a mistake in his/her assignment.So, i examined the code and caught the same mistake caught by sherrif.i told him but he denied. thats why i posted his code here for cnfirmation that if i am correct or not. and i am correct.
i requested here to the genius' that if they like then they can post the on my class' group too.
this was the whole story.
Am i wrong Sir ??
 
Rob Spoor
Sheriff
Pie
Posts: 20605
60
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wait, I think I'm missing something.

You first said that it was your code ("my code is.."). Then you said that a classmate wrote it. That made Michael and me think that you let your classmate write the code for you. Are you now saying that you wrote and submitted your own code that you have not posted here? Then why did you say "my code" in the first place?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic