Online Java Compiler

Our best online Java compiler is free to use where you can write, run, share and download Java code online. This is user-friendly and allows you to write and run Java online without any hassle in installing any java ide and interpreter on your mobile and desktop computer. It also supports standard libraries and takes inputs from users.

Enjoy the benefits of using our online java compiler in a fast and efficient way of coding your java projects. As you observe, the sample boilerplate code shows on our online Java text Editor based on the set programming language like Java and you’ll be able to additionally choose many reference programs to start coding.

Best Online Java Compiler - Online Java Compiler
Best Online Java Compiler – Online Java Compiler

User Inputs (STDIN)

Our Java online editor is capable of handling user inputs. This online Java editor supports Standard input(STDIN) that allows users to input any parameter using the standard input (STDIN) textbox under the I/O tab. With the Scanner class in Java, the user is able to read the inputs.

See the sample program below on how to read standard input (STDIN) (In our case we are using integer).

What is Java?

Java is the high-level, object-oriented, robust, secure programming language, platform-independent, high-performance, Multi-threaded, and portable programming language. It was developed by James Gosling in June 1991. It can also be known as the platform as it provides its own JRE and API.

Java programming popularity

Jonathan Sandals in his post about Top 7 Programming Languages Of 2020 last February 7, 2020, listed that Java is being in the Top 2 Most programming language in the year 2020. The philosophy “Write once, work anywhere,” it’s very popular with businesses looking to make sure their applications have a consistent user experience. Java programs should be able to run over a network, without it mattering what operating system the user is running. based on the article published by Northeastern University Graduate programs about THE 10 MOST POPULAR PROGRAMMING LANGUAGES TO LEARN IN 2021 said that there are 29,000 jobs with an annual average salary of $104,000.

Java Systax

Here is the following Java syntax that may help you during your programming journey.

The Java code below called Main.java, and this code will print “Hello World” to the screen:

Single-line Comments

Java Multi-line Comments

Java Variables

Variables are used to store values in computer memory. See the list below of the commonly used java variables

  • String – store values such text, like as “Hello”. String values are surrounded by double quotes
  • int – stores integers values such (whole numbers), without decimals, like as 123 or -123
  • float – stores values such floating point numbers, with decimals, like as 19.99 or -19.99
  • char – stores values such single characters, such as ‘a’ or ‘B’. Char values are surrounded by single quotes
  • boolean – stores values with two states: Yes or No, On or Off, true or false

See the code below to declare java variables.

See the code below on how to assign value to java variables using different data types.

Java Operators

In Java, operators are divided into the following groups.

  • Arithmetic operators
  • Assignment operators
  • Comparison operators
  • Logical operators
  • Bitwise operators

Arithmetic operators

OperatorNameDescriptionExample
+AdditionAdds together two valuesx + y
SubtractionSubtracts one value from anotherx – y
*MultiplicationMultiplies two valuesx * y
/DivisionDivides one value by anotherx / y
%ModulusReturns the division remainderx % y
++IncrementIncreases the value of a variable by 1++x
DecrementDecreases the value of a variable by 1–x
Arithmetic operators

Sample Syntax using Arithmetic Operators

Assignment operators

OperatorExampleSame As
=x = 5x = 5
+=x += 3x = x + 3
-=x -= 3x = x – 3
*=x *= 3x = x * 3
/=x /= 3x = x / 3
%=x %= 3x = x % 3
&=x &= 3x = x & 3
|=x |= 3x = x | 3
^=x ^= 3x = x ^ 3
>>=x >>= 3x = x >> 3
<<=x <<= 3x = x << 3
Assignment operators

The code below shows how to assign a value to a variable.

Comparison operators

OperatorNameExample
==Equal tox == y
!=Not equalx != y
>Greater thanx > y
<Less thanx < y
>=Greater than or equal tox >= y
<=Less than or equal tox <= y
Comparison operators

See the example code below showing the Comparison operators in java.

Code for Java Comparison Operators

Logical operators

OperatorNameDescriptionExample
&& Logical andReturns true if both statements are truex < 5 &&  x < 10
|| Logical orReturns true if one of the statements is truex < 5 || x < 4
!Logical notReverse the result, returns false if the result is true!(x < 5 && x < 10)

See the sample program below that shows logical operators in Java.

Syntax of using Logical Operators in java

Java Conditions and If Statements

In Java, the if statement is used to evaluate the condition. It usually check the boolean condition, either true or false.

Here are the various types of if statement in Java.

The if Statement

Syntax of using If Statement in java

The else Statement

Syntax of using Else Statement in java

The else if Statement

Syntax of using Else-if statement in java

Short Hand If…Else (Ternary Operator)

Java Switch Statements

The switch statement allows us to execute a block of code among many alternatives.

Syntax of using Switch Statements in java

Java Loops

The Loops in Java is used to execute a block of code as long as a specified condition is reached. See the different types of loops in Java below.

Java While Loop

Syntax of using While loop in java

The Do/While Loop

Syntax of using Do While loop in java

Java For Loop

Syntax of using For loop in java

For-Each Loop

Syntax of using For each loop in java

See our suggested articles below