File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes What does this line do? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "What does this line do?" Watch "What does this line do?" New topic

What does this line do?

Mat Cauthon

Joined: Mar 29, 2006
Posts: 10
I got this out of my text book for my programming principles class. This code shows name overloading in Java. The line in question is in bold.

[ October 01, 2006: Message edited by: Marilyn de Queiroz ]
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
That is a label. You can find the specification for it in Section 14.7 of the Java Language Specification, Third Edition.
[ October 01, 2006: Message edited by: Keith Lynn ]
Pratibha Malhotra
Ranch Hand

Joined: Dec 21, 2003
Posts: 199
Yes, it is a way to label a statement. Main purpose behind same is to to provide a mark to a particular line of code.

It is primarily used in Loops for decision making for flow of control and is useful with break and continue operations

for( i=0; i<10; i++ ){
for( j=10; j>0; j--){
if( j == 5 ) {
break outer; // exit entire loop-labeled as outer


~ Pratibha Malhotra<br /> <br />Sun Certified Java Programmer<br />SCEA 1.4 (In Progress)<br />~~~~~~~~~~~~~~~~~~~~~~~~~~~<br />"Many of life's failures are people who did not realize how close they were to success when they gave up!!"
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15038

Ok, so now that you've learned what a label is, please forget about it and don't use it in your own code ever again...

You don't need this construction, it makes code hard to read and follow. A label and a break statement to jump to the label are more or less like a "goto" statement, the statement that quickly makes programs a messy jumble (spaghetti code).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: What does this line do?
It's not a secret anymore!