Is there any goto statement in java

0 votes

 I found that it is one of the keywords in Java. But I don't know about goto statement.

Jun 12, 2018 in Java by Akrati
• 960 points
1,299 views

3 answers to this question.

0 votes
The Java keyword list specifies the goto keyword.

It was in the original JVM, but then removed. It was probably kept as a reserved keyword in case it was to be added to a later version of Java.

If goto gets added to the language, later on, existing code that used the word goto as an identifier (variable name, method name, etc...) would break. But because goto is a keyword, such code will not even compile in the present, and it remains possible to make it actually do something later on, without breaking existing code.
answered Jun 12, 2018 by scarlett
• 1,290 points
0 votes

James Gosling created the original JVM with the 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

answered Aug 10, 2018 by samarth295
• 2,220 points
0 votes
So they could be used one day if the language designers felt the need.

Also, if programmers from languages that do have these keywords (eg. C, C++) use them by mistake, then the Java compiler can give a useful error message.

Or maybe it was just to stop programmers using goto :)
answered Oct 15, 2018 by Daisy
• 8,140 points

Related Questions In Java

0 votes
2 answers

Is there a destructor in Java?

try (BufferedReader br = new BufferedReader(new FileReader(path))) ...READ MORE

answered Sep 4, 2018 in Java by Sushmita
• 6,920 points
938 views
0 votes
2 answers

Is there a SortedList in Java?

Since all lists are already "sorted" by ...READ MORE

answered Nov 2, 2018 in Java by Sushmita
• 6,920 points
4,502 views
0 votes
1 answer

Is there any way to write content of Java InputStream to an OutputStream?

org.apache.commons.io.IOUtils from Apache has a method called copy(InputStream,OutputStream).which does ...READ MORE

answered Jul 6, 2018 in Java by sharth
• 3,370 points
758 views
0 votes
2 answers

Is there any way to declare an array in-line?

Another way to do that, if you ...READ MORE

answered Aug 30, 2019 in Java by Sirajul
• 59,230 points
588 views
+5 votes
4 answers

How to execute a python file with few arguments in java?

You can use Java Runtime.exec() to run python script, ...READ MORE

answered Mar 27, 2018 in Java by DragonLord999
• 8,450 points

edited Nov 7, 2018 by Omkar 81,245 views
+1 vote
1 answer

How to handle drop downs using Selenium WebDriver in Java

First, find an XPath which will return ...READ MORE

answered Mar 27, 2018 in Selenium by nsv999
• 5,500 points
8,366 views
0 votes
1 answer

What are the differences between getText() and getAttribute() functions in Selenium WebDriver?

See, both are used to retrieve something ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points
17,444 views
0 votes
1 answer

Selenium JARS(Java) missing from downloadable link

Nothing to worry about here. In the ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,500 points

edited Aug 4, 2023 by Khan Sarfaraz 4,882 views
0 votes
1 answer

Why there is the need of getters and setters in java

In Java getters and setters are completely ...READ MORE

answered Jun 26, 2018 in Java by scarlett
• 1,290 points
1,974 views
0 votes
3 answers

What is ^ operator in java?

It's bitwise XOR, Java does not have ...READ MORE

answered Oct 31, 2018 in Java by Sushmita
• 6,920 points
1,106 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP