This week's book giveaway is in the Cloud/Virtualization forum.
We're giving away four copies of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds and have James Denton on-line!
See this thread for details.
Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

I have a doubt  RSS feed

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the java statement
final JLabel label = new JLabel("Hello world");
what does "final" mean? Why is it put before JLabel?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Priya,
When in the Java language a variable is declared 'final', it cannot be changed after initialisation. When a final variable is initialised and you attempt to assign it a new value, this will generate a compile error. Final variables are similar to constants in other programming languages.
In your example it means that the JLabel label can not be changed. It can not be assigned another JLabel object, nor can it's caption be changed.
Hope this helped,
Tim
[ May 05, 2003: Message edited by: Tim B. ]
 
Ranch Hand
Posts: 867
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Priya
final JLabel label = new JLabel("Hello world");
It means that the reference of the label as a final reference,the reference of label points to something once when it declares.It can not make any changing of pointer which point to the other thing.If you do it,the compiler error occurs
Lets consider the case
case 1 give you compiler error
case 1:
final JLabel jlabel=new JLabel();
jlabel=new JLabel("Hello");
case 2 compile fine
case 2
JLabel tlabel=new JLabel("Hello");
tlabel= new JLabel("");
If it is not clear,please post again

[ May 05, 2003: Message edited by: siu chung man ]
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Tim B, welcome to JavaRanch, and thanks for helping out by responding to the questions placed in the forums.
However, there is a problem with your displayed name. Please change it to conform with JavaRanch's Naming Policy. An initial letter with a last name are OK, but not a first name with a letter for the last name.
Thanks in advance.
-Barry
[ May 05, 2003: Message edited by: Barry Gaunt ]
 
Priya Pichamuthu
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys. I have another doubt. How do I put a text area under a text field in a swing GUI. Will the code be different from the one where I put a text area to the side of a text field? How do we determine the position of the text field and text area relative to each other?
 
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the various layouts available in AWT in the API.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!