This may not cover every piece of Java you can use in code.org but this the main stuff I've seen in others' programs.

  1. Short Hand if else statements. These are used to shorten if else statements in your code.
    A shorthand if else looks like this: variable = (operator/condition) ? ifTrue : ifFalse;

For example, if I wanted to write this:

if (skibidi == 20){
console.log("Get Fanum Taxed");
} else {
console.log("The Fanum Taxer Thinks Ur Not Skibidi");
}

I could simplify that and write:

var skibidi = 20;
var output = (skibidi == 20) ? "Get Fanum Taxed" : "The Fanum Taxer Thinks Ur Not Skibidi";
console.log(output);
  1. The Java Switch. This is basically another way to write multiple else statements within the same "block" of code. The Java switch evaluates multiple cases that are all associated with the same expression. This is how you write a Java switch statement:
switch(skibidi){
case 1: 
//Code stuff
break;
case 2:
//Code stuff
break;
default:
//Code stuff
break;
}

Both default and break; are optional but here is what they do:

default is the code executed if each case does not match.
break; is to stop the evaluation of each case. This is usually used after a case matches the expression given.

  1. Java continue;. continue; is used in loops to break; a certain outcome while still continuing the loop.

For example, using this code:

for (var i = 0; i < 10; i++) {
  if (i == 4) {
    break;
  } else {
    console.log(i);
  }`
}

Will make the loop stop at 3 while this code:

for (var i = 0; i < 10; i++) {
  if (i == 4) {
    continue;
  } else {
    console.log(i);
  }
}

will skip 4 and continue up to 10.

  1. Java Assignment Operators. Java assignment operators can shorten even the smallest parts of your code.
    Java assignment operators output the original value of a variable by whatever operator you used.

For example, If I wanted to write:

var x = 10;
x = x + 5;

I could simplify and rewrite it as:

var x = 10;
x += 5;

Note: I didn't feel like writing every assignment operator out so I ss'd this from w3Schools

Feel free to add any additional Java that could be used in code.org below.

Java and JavaScript are completely different languages though they have some similar syntax. You are not “using Java” in code.org, merely the language that code.org uses, JavaScript, syntactically resembles Java in some ways. However, both are very different.

Awards

    conditional operators are also in normal javascript? its not java in code.org its just javascript..

    class MyClass {
    int num = 12;
    public static void main(String[] args) {
    System.out.println(num);
      }
    }

      Chat