Is there a goto statement in Java?

Venkat picture Venkat · Mar 30, 2010 · Viewed 396.5k times · Source

I'm confused about this. Most of us have been told that there isn't any goto statement in Java.

But I found that it is one of the keywords in Java. Where can it be used? If it can not be used, then why was it included in Java as a keyword?

Answer

Vitalii Fedorenko picture Vitalii Fedorenko · Dec 28, 2010

James Gosling created the original JVM with support of goto statements, but then he removed this feature as needless. The main reason goto is unnecessary is that usually it can be replaced with more readable statements (like break/continue) or by extracting a piece of code into a method.

Source: James Gosling, Q&A session