Asked  6 Months ago    Answers:  5   Viewed   34 times

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?



The Java keyword list specifies the goto keyword, but it is marked as "not used".

It was in the original JVM (see answer by @VitaliiFedorenko), but then removed. It was probably kept as a reserved keyword in case it were to be added to a later version of Java.

If goto was not on the list, and it 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.

Tuesday, June 1, 2021
answered 6 Months ago

You could use a labeled BREAK statement:

    for (i = 0; i < arrayOfInts.length; i++) {
        for (j = 0; j < arrayOfInts[i].length; j++) {
            if (arrayOfInts[i][j] == searchfor) {
                foundIt = true;
                break search;

However, in properly designed code, you shouldn't need GOTO functionality.

Tuesday, June 8, 2021
answered 6 Months ago

it looks the onClick should be:

onclick="document.location+='#goToPage';return false;" 
Thursday, August 12, 2021
answered 4 Months ago

The answer to "can I do x to an object" (or an array for that matter) is usually "yes" and it frequently involves some form of reduce.

If you want to filter falsy values you could do something like this:

function filterFalsy(obj) {
  return Object.keys(obj).reduce((acc, key) => {
    if (obj[key]) {
      acc[key] = obj[key]

    return acc
  }, {})

const testObj = {
  a: 'test',
  b: 321,
  c: false


This returns a new object without falsy values and leaves the existing object alone.

Friday, August 20, 2021
answered 4 Months ago

You can use jQuery to get it done using the beautyOfCode plugin. I'm not sure if there's an easy way to hook into the javadoc generation, but after-the-fact you can just do the following in your header:


and all text inside PRE tags will be highlighted as java. Check out the links above for more info.

Tuesday, September 21, 2021
answered 2 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :