Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Java Arrays
  • Java Strings
  • Java OOPs
  • Java Collection
  • Java 8 Tutorial
  • Java Multithreading
  • Java Exception Handling
  • Java Programs
  • Java Project
  • Java Collections Interview
  • Java Interview Questions
  • Java MCQs
  • Spring
  • Spring MVC
  • Spring Boot
  • Hibernate
Open In App
Next Article:
Java Arithmetic Operators with Examples
Next article icon

Java Operators

Last Updated : 14 Apr, 2025
Comments
Improve
Suggest changes
Like Article
Like
Report
Try it on GfG Practice
redirect icon

Java operators are special symbols that perform operations on variables or values. These operators are essential in programming as they allow you to manipulate data efficiently. They can be classified into different categories based on their functionality. In this article, we will explore different types of operators in Java, including arithmetic, unary, relational, logical, and more, along with practical examples.

Example: This example demonstrates the use of the + (addition) and - (subtraction) operators to perform arithmetic operations on two integer variables.

Java
// Java program to show the use of + and - operators public class Geeks  {       public static void main(String[] args)      {       // Declare and initialize variables         int num1 = 500;         int num2 = 100;                  // Using the + (addition) operator         int sum = num1 + num2;         System.out.println("The Sum is: "+sum);                  // Using the - (subtraction) operator         int diff = num1 - num2;         System.out.println("The Difference is: "+diff);              } } 

Output
The Sum is: 600 The Difference is: 400 

Types of Operators in Java

  1. Arithmetic Operators
  2. Unary Operators
  3. Assignment Operator
  4. Relational Operators
  5. Logical Operators
  6. Ternary Operator
  7. Bitwise Operators
  8. Shift Operators
  9. instance of operator

Let's see all these operators one by one with their proper examples.

1. Arithmetic Operators

Arithmetic Operators are used to perform simple arithmetic operations on primitive and non-primitive data types. 

  • * : Multiplication
  • / : Division
  • % : Modulo
  • + : Addition
  • - : Subtraction

Note:

  • Division (/) truncates decimal points for integers.
  • Modulus (%) is useful for checking even/odd numbers.

Example: This example demonstrates the use of arithmetic operators on integers and string-to-integer conversion for performing mathematical operations.

Java
// Java Program to show the use of // Arithmetic Operators import java.io.*;  class Geeks  {     public static void main (String[] args)      {                    // Arithmetic operators on integers         int a = 10;         int b = 3;                // Arithmetic operators on Strings         String n1 = "15";         String n2 = "25";          // Convert Strings to integers         int a1 = Integer.parseInt(n1);         int b1 = Integer.parseInt(n2);                     System.out.println("a + b = " + (a + b));         System.out.println("a - b = " + (a - b));         System.out.println("a * b = " + (a * b));         System.out.println("a / b = " + (a / b));         System.out.println("a % b = " + (a % b));         System.out.println("a1 + b1 = " + (a1 + b1));                 } } 

Output
a + b = 13 a - b = 7 a * b = 30 a / b = 3 a % b = 1 a1 + b1 = 40 


2. Unary Operators

Unary Operators need only one operand. They are used to increment, decrement, or negate a value. 

  • - , Negates the value.
  • + , Indicates a positive value (automatically converts byte, char, or short to int).
  • ++ , Increments by 1.
    • Post-Increment: Uses value first, then increments.
    • Pre-Increment: Increments first, then uses value.
  • -- , Decrements by 1.
    • Post-Decrement: Uses value first, then decrements.
    • Pre-Decrement: Decrements first, then uses value.
  • ! , Inverts a boolean value.

Example: This example demonstrates the use of unary operators for post-increment, pre-increment, post-decrement, and pre-decrement operations.

Java
// Java Program to show the use of // Unary Operators import java.io.*;  // Driver Class class Geeks {       // main function     public static void main(String[] args)     {         // Interger declared         int a = 10;         int b = 10;          // Using unary operators         System.out.println("Postincrement : " + (a++));         System.out.println("Preincrement : " + (++a));          System.out.println("Postdecrement : " + (b--));         System.out.println("Predecrement : " + (--b));     } } 

Output
Postincrement : 10 Preincrement : 12 Postdecrement : 10 Predecrement : 8 


3. Assignment Operator

 '=' Assignment operator is used to assign a value to any variable. It has right-to-left associativity, i.e. value given on the right-hand side of the operator is assigned to the variable on the left, and therefore right-hand side value must be declared before using it or should be a constant. 

The general format of the assignment operator is:

variable = value;

In many cases, the assignment operator can be combined with others to create shorthand compound statements. For example, a += 5 replaces a = a + 5. Common compound operators include:

  • += , Add and assign.
  • -= , Subtract and assign.
  • *= , Multiply and assign.
  • /= , Divide and assign.
  • %= , Modulo and assign.

Example: This example demonstrates the use of various assignment operators, including compound, bitwise, and shift operators, for modifying a variable.

Java
// Java Program to show the use of // Assignment Operators import java.io.*;  // Driver Class class Geeks {     // Main Function     public static void main(String[] args)     {                  // Assignment operators         int f = 7;         System.out.println("f += 3: " + (f += 3));         System.out.println("f -= 2: " + (f -= 2));         System.out.println("f *= 4: " + (f *= 4));         System.out.println("f /= 3: " + (f /= 3));         System.out.println("f %= 2: " + (f %= 2));         System.out.println("f &= 0b1010: " + (f &= 0b1010));         System.out.println("f |= 0b1100: " + (f |= 0b1100));         System.out.println("f ^= 0b1010: " + (f ^= 0b1010));         System.out.println("f <<= 2: " + (f <<= 2));         System.out.println("f >>= 1: " + (f >>= 1));         System.out.println("f >>>= 1: " + (f >>>= 1));     } } 

Output
f += 3: 10 f -= 2: 8 f *= 4: 32 f /= 3: 10 f %= 2: 0 f &= 0b1010: 0 f |= 0b1100: 12 f ^= 0b1010: 6 f <<= 2: 24 f >>= 1: 12 f >>>= 1: 6 

Note: Use compound assignments (+=, -=) for cleaner code.


4. Relational Operators

Relational Operators are used to check for relations like equality, greater than, and less than. They return boolean results after the comparison and are extensively used in looping statements as well as conditional if-else statements. The general format is , 

variable relation_operator value

Relational operators compare values and return Boolean results:

  • == , Equal to.
  • != , Not equal to.
  • < , Less than.
  • <= , Less than or equal to.
  • > , Greater than.
  • >= , Greater than or equal to.

Example: This example demonstrates the use of relational operators to compare values and return boolean results.

Java
// Java Program to show the use of // Relational Operators import java.io.*;  // Driver Class class Geeks {          // main function     public static void main(String[] args)     {         // Comparison operators         int a = 10;         int b = 3;         int c = 5;          System.out.println("a > b: " + (a > b));         System.out.println("a < b: " + (a < b));         System.out.println("a >= b: " + (a >= b));         System.out.println("a <= b: " + (a <= b));         System.out.println("a == c: " + (a == c));         System.out.println("a != c: " + (a != c));     } } 

Output
a > b: true a < b: false a >= b: true a <= b: false a == c: false a != c: true 


5. Logical Operators

Logical Operators are used to perform "logical AND" and "logical OR" operations, similar to AND gate and OR gate in digital electronics. They have a short-circuiting effect, meaning the second condition is not evaluated if the first is false.

Conditional operators are:

  • &&, Logical AND: returns true when both conditions are true.
  • ||, Logical OR: returns true if at least one condition is true.
  • !, Logical NOT: returns true when a condition is false and vice-versa

Example: This example demonstrates the use of logical operators (&&, ||, !) to perform boolean operations.

Java
// Java Program to show the use of // Logical operators import java.io.*;  class Geeks {          // Main Function     public static void main (String[] args) {                // Logical operators         boolean x = true;         boolean y = false;                System.out.println("x && y: " + (x && y));         System.out.println("x || y: " + (x || y));         System.out.println("!x: " + (!x));     } } 

Output
x && y: false x || y: true !x: false 


6. Ternary operator

The Ternary Operator is a shorthand version of the if-else statement. It has three operands and hence the name Ternary. The general format is,

condition ? if true : if false

The above statement means that if the condition evaluates to true, then execute the statements after the '?' else execute the statements after the ':'.  

Example: This example demonstrates the use of the ternary operator to find the maximum of three numbers.

Java
// Java program to illustrate // max of three numbers using // ternary operator. public class Geeks {        public static void main(String[] args)     {         int a = 20, b = 10, c = 30, result;          // result holds max of three         // numbers         result = ((a > b) ? (a > c) ? a : c : (b > c) ? b : c);         System.out.println("Max of three numbers = "+ result);     } } 

Output
Max of three numbers = 30 


7. Bitwise Operators

Bitwise Operators are used to perform the manipulation of individual bits of a number and with any of the integer types. They are used when performing update and query operations of the Binary indexed trees. 

  • & (Bitwise AND): returns bit-by-bit AND of input values.
  • | (Bitwise OR): returns bit-by-bit OR of input values.
  • ^ (Bitwise XOR): returns bit-by-bit XOR of input values.
  • ~ (Bitwise Complement): inverts all bits (one's complement).

Example: This example demonstrates the use of bitwise operators (&, |, ^, ~, <<, >>, >>>) to perform bit-level operations.

Java
// Java Program to show the use of // bitwise operators import java.io.*;  class Geeks  {     public static void main(String[] args)     {         // Bitwise operators         int d = 0b1010;         int e = 0b1100;                System.out.println("d & e : " + (d & e));         System.out.println("d | e : " + (d | e));         System.out.println("d ^ e : " + (d ^ e));         System.out.println("~d : " + (~d));         System.out.println("d << 2 : " + (d << 2));         System.out.println("e >> 1 : " + (e >> 1));         System.out.println("e >>> 1 : " + (e >>> 1));     } } 

Output
d & e : 8 d | e : 14 d ^ e : 6 ~d : -11 d << 2 : 40 e >> 1 : 6 e >>> 1 : 6 


8. Shift Operators

Shift Operators are used to shift the bits of a number left or right, thereby multiplying or dividing the number by two, respectively. They can be used when we have to multiply or divide a number by two. The general format , 

number shift_op number_of_places_to_shift;

  • << (Left shift): Shifts bits left, filling 0s (multiplies by a power of two).
  • >> (Signed right shift): Shifts bits right, filling 0s (divides by a power of two), with the leftmost bit depending on the sign.
  • >>> (Unsigned right shift): Shifts bits right, filling 0s, with the leftmost bit always 0.

Example: This example demonstrates the use of shift operators (<<, >>) to shift the bits of a number left and right.

Java
// Java Program to show the use of // shift operators import java.io.*;  class Geeks  {     public static void main(String[] args)     {         int a = 10;              // Using left shift         System.out.println("a<<1 : " + (a << 1));                // Using right shift         System.out.println("a>>1 : " + (a >> 1));     } } 

Output
a<<1 : 20 a>>1 : 5 


9. instanceof Operator

The instanceof operator is used for type checking. It can be used to test if an object is an instance of a class, a subclass, or an interface. The general format,  

object instance of class/subclass/interface

Example: This example demonstrates the use of the instanceof operator to check if an object is an instance of a specific class or interface

Java
// Java program to show the use of // Instance of operator public class Geeks  {     public static void main(String[] args)     {          Person obj1 = new Person();         Person obj2 = new Boy();          // As obj is of type person, it is not an         // instance of Boy or interface         System.out.println("obj1 instanceof Person: "                            + (obj1 instanceof Person));         System.out.println("obj1 instanceof Boy: "                            + (obj1 instanceof Boy));         System.out.println("obj1 instanceof MyInterface: "                            + (obj1 instanceof MyInterface));          // Since obj2 is of type boy,         // whose parent class is person         // and it implements the interface Myinterface         // it is instance of all of these classes         System.out.println("obj2 instanceof Person: "                            + (obj2 instanceof Person));         System.out.println("obj2 instanceof Boy: "                            + (obj2 instanceof Boy));         System.out.println("obj2 instanceof MyInterface: "                            + (obj2 instanceof MyInterface));     } }  // Classes and Interfaces used // are declared here class Person { }  class Boy extends Person implements MyInterface { }  interface MyInterface { } 

Output
obj1 instanceof Person: true obj1 instanceof Boy: false obj1 instanceof MyInterface: false obj2 instanceof Person: true obj2 instanceof Boy: true obj2 instanceof MyInterface: true 


Precedence and Associativity of Java Operators

Precedence and associative rules are used when dealing with hybrid equations involving more than one type of operator. In such cases, these rules determine which part of the equation to consider first, as there can be many different valuations for the same equation. The below table depicts the precedence of operators in decreasing order as magnitude, with the top representing the highest precedence and the bottom showing the lowest precedence.

Java-Operators


1. Precedence and Associativity

There is often confusion when it comes to hybrid equations which are equations having multiple operators. The problem is which part to solve first. There is a golden rule to follow in these situations. If the operators have different precedence, solve the higher precedence first. If they have the same precedence, solve according to associativity, that is, either from right to left or from left to right. The explanation of the below program is well written in comments within the program itself.

Example:

Java
public class Geeks {     public static void main(String[] args)     {         int a = 20, b = 10, c = 0;       	int d = 20, e = 40, f = 30;          // precedence rules for arithmetic operators.         // (* = / = %) > (+ = -)         // prints a+(b/d)         System.out.println("a+b/d = " + (a + b / d));          // if same precedence then associative         // rules are followed.         // e/f -> b*d -> a+(b*d) -> a+(b*d)-(e/f)         System.out.println("a+b*d-e/f = "                            + (a + b * d - e / f));     } } 

Output
a+b/d = 20 a+b*d-e/f = 219 


2. Be a Compiler

The compiler in our systems uses a lex tool to match the greatest match when generating tokens. This creates a bit of a problem if overlooked. For example, consider the statement a=b+++c; too many of the readers might seem to create a compiler error. But this statement is absolutely correct as the token created by lex is a, =, b, ++, +, c. Therefore, this statement has a similar effect of first assigning b+c to a and then incrementing b. Similarly, a=b+++++c; would generate an error as the tokens generated are a, =, b, ++, ++, +, c. which is actually an error as there is no operand after the second unary operand.

Example:

Java
public class Geeks {     public static void main(String[] args)     {         int a = 20, b = 10, c = 0;          // a=b+++c is compiled as         // b++ +c         // a=b+c then b=b+1         a = b++ + c;                System.out.println("Value of a(b+c), "                            + " b(b+1), c = " + a + ", " + b                            + ", " + c);          // a=b+++++c is compiled as         // b++ ++ +c         // which gives error.         // a=b+++++c;         // System.out.println(b+++++c);     } } 

Output
Value of a(b+c),  b(b+1), c = 10, 11, 0 


3. Using + over ()

When using the + operator inside system.out.println() make sure to do addition using parenthesis. If we write something before doing addition, then string addition takes place, that is, associativity of addition is left to right, and hence integers are added to a string first producing a string, and string objects concatenate when using +. It can create unwanted results.

Example:

Java
public class Geeks {     public static void main(String[] args)     {         int x = 5, y = 8;          // concatenates x and y as         // first x is added to "concatenation (x+y) = "         // producing "concatenation (x+y) = 5"         // and then 8 is further concatenated.         System.out.println("Concatenation (x+y) = " + x + y);          // addition of x and y         System.out.println("Addition (x+y) = " + (x + y));     } } 

Output
Concatenation (x+y) = 58 Addition (x+y) = 13 

Advantages of Operators

  • Operators in Java provide a concise and readable way to perform complex calculations and logical operations.
  • Operators in Java save time by reducing the amount of code required to perform certain tasks.
  • Using operators can improve performance because they are often implemented at the hardware level, making them faster than equivalent Java code.

Disadvantages of Operators

  • Operators in Java have a defined precedence, which can lead to unexpected results if not used properly.
  • Java performs implicit type conversions when using operators, which can lead to unexpected results or errors if not used properly.

Common Mistakes to Avoid

The common mistakes that can occur when working with Java Operators are listed below:

  • Confusing == with =: Using == for assignment instead of = for equality check leads to logical errors.
  • Incorrect Use of Floating Point Comparison: Comparing floating point numbers using == can lead to unexpected results due to precision issues.
  • Integer Division Confusion: Dividing two integers will result in integer division (truncating the result).
  • Overusing + for String Concatenation in Loops: Using + for concatenating strings in loops leads to performance issues because it creates new string objects on each iteration.

Next Article
Java Arithmetic Operators with Examples

K

kartik
Improve
Article Tags :
  • Java
  • Operators
  • Java-Operators
Practice Tags :
  • Java
  • Java-Operators
  • Operators

Similar Reads

    Basics of Java

    Learn Java - A Beginners Guide for 2024
    If you are new to the world of coding and want to start your coding journey with Java, then this learn Java a beginners guide gives you a complete overview of how to start Java programming. Java is among the most popular and widely used programming languages and platforms. A platform is an environme
    10 min read
    Introduction to Java
    Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android
    4 min read
    Similarities and Difference between Java and C++
    Nowadays Java and C++ programming languages are vastly used in competitive coding. Due to some awesome features, these two programming languages are widely used in industries as well as competitive programming. C++ is a widely popular language among coders for its efficiency, high speed, and dynamic
    6 min read
    Setting up Environment Variables For Java - Complete Guide to Set JAVA_HOME
    In the journey to learning the Java programming language, setting up environment variables for Java is essential because it helps the system locate the Java tools needed to run the Java programs. Now, this guide on how to setting up environment variables for Java is a one-place solution for Mac, Win
    6 min read
    Java Syntax
    Java is an object-oriented programming language that is known for its simplicity, portability, and robustness. The syntax of Java programming language is very closely aligned with C and C++, which makes it easier to understand. Java Syntax refers to a set of rules that define how Java programs are w
    6 min read
    Java Hello World Program
    Java is one of the most popular and widely used programming languages and platforms. In this article, we will learn how to write a simple Java Program. This article will guide you on how to write, compile, and run your first Java program. With the help of Java, we can develop web and mobile applicat
    6 min read
    Differences Between JDK, JRE and JVM
    Understanding the difference between JDK, JRE, and JVM plays a very important role in understanding how Java works and how each component contributes to the development and execution of Java applications. The main difference between JDK, JRE, and JVM is:JDK: Java Development Kit is a software develo
    3 min read
    How JVM Works - JVM Architecture
    JVM (Java Virtual Machine) runs Java applications as a run-time engine. JVM is the one that calls the main method present in a Java code. JVM is a part of JRE (Java Runtime Environment). Java applications are called WORA (Write Once Run Anywhere). This means a programmer can develop Java code on one
    7 min read
    Java Identifiers
    An identifier in Java is the name given to Variables, Classes, Methods, Packages, Interfaces, etc. These are the unique names used to identify programming elements. Every Java Variable must be identified with a unique name.Example:public class Test{ public static void main(String[] args) { int a = 2
    2 min read

    Variables & DataTypes in Java

    Java Variables
    In Java, variables are containers that store data in memory. Understanding variables plays a very important role as it defines how data is stored, accessed, and manipulated.Key Components of Variables in Java:A variable in Java has three components, which are listed below:Data Type: Defines the kind
    9 min read
    Scope of Variables in Java
    The scope of variables is the part of the program where the variable is accessible. Like C/C++, in Java, all identifiers are lexically (or statically) scoped, i.e., scope of a variable can be determined at compile time and independent of the function call stack. In this article, we will learn about
    7 min read
    Java Data Types
    Java is statically typed and also a strongly typed language because each type of data, such as integer, character, hexadecimal, packed decimal etc. is predefined as part of the programming language, and all constants or variables defined for a given program must be declared with the specific data ty
    14 min read

    Operators in Java

    Java Operators
    Java operators are special symbols that perform operations on variables or values. These operators are essential in programming as they allow you to manipulate data efficiently. They can be classified into different categories based on their functionality. In this article, we will explore different
    15 min read
    Java Arithmetic Operators with Examples
    Operators constitute the basic building block to any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they
    6 min read
    Java Assignment Operators with Examples
    Operators constitute the basic building block of any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they
    7 min read
    Java Unary Operator with Examples
    Operators constitute the basic building block to any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions be it logical, arithmetic, relational, etc. They are classified based on the functionality they p
    8 min read
    Java Relational Operators with Examples
    Operators constitute the basic building block to any programming language. Java too provides many types of operators which can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they
    10 min read
    Java Logical Operators with Examples
    Logical operators are used to perform logical "AND", "OR", and "NOT" operations, i.e., the functions similar to AND gate and OR gate in digital electronics. They are used to combine two or more conditions/constraints or to complement the evaluation of the original condition under particular consider
    8 min read
    Java Ternary Operator
    Operators constitute the basic building block of any programming language. Java provides many types of operators that can be used according to the need to perform various calculations and functions, be it logical, arithmetic, relational, etc. They are classified based on the functionality they provi
    5 min read
    Bitwise Operators in Java
    In Java, Operators are special symbols that perform specific operations on one or more than one operands. They build the foundation for any type of calculation or logic in programming.There are so many operators in Java, among all, bitwise operators are used to perform operations at the bit level. T
    6 min read

    Packages in Java

    Java Packages
    Packages in Java are a mechanism that encapsulates a group of classes, sub-packages, and interfaces. Packages are used for: Prevent naming conflicts by allowing classes with the same name to exist in different packages, like college.staff.cse.Employee and college.staff.ee.Employee.They make it easie
    8 min read

    Flow Control in Java

    Decision Making in Java (if, if-else, switch, break, continue, jump)
    Decision-making statements in Java execute a block of code based on a condition. Decision-making in programming is similar to decision-making in real life. In programming, we also face situations where we want a certain block of code to be executed when some condition is fulfilled.A programming lang
    10 min read
    Java if statement
    The Java if statement is the most simple decision-making statement. It is used to decide whether a certain statement or block of statements will be executed or not i.e. if a certain condition is true then a block of statements is executed otherwise not.Example:Java// Java program to illustrate If st
    5 min read
    Java if-else Statement
    The if-else statement in Java is a powerful decision-making tool used to control the program's flow based on conditions. It executes one block of code if a condition is true and another block if the condition is false. In this article, we will learn Java if-else statement with examples.Example:Java/
    3 min read
    Java if-else-if ladder with Examples
    The Java if-else-if ladder is used to evaluate multiple conditions sequentially. It allows a program to check several conditions and execute the block of code associated with the first true condition. If none of the conditions are true, an optional else block can execute as a fallback.Example: The b
    3 min read

    Loops in Java

    Java Loops
    Looping in programming languages is a feature that facilitates the execution of a set of instructions repeatedly while some condition evaluates to true. Java provides three ways for executing the loops. While all the ways provide similar basic functionality, they differ in their syntax and condition
    7 min read
    Java For Loop
    Java for loop is a control flow statement that allows code to be executed repeatedly based on a given condition. The for loop in Java provides an efficient way to iterate over a range of values, execute code multiple times, or traverse arrays and collections.Now let's go through a simple Java for lo
    4 min read
    Java while Loop
    Java while loop is a control flow statement used to execute the block of statements repeatedly until the given condition evaluates to false. Once the condition becomes false, the line immediately after the loop in the program is executed.Let's go through a simple example of a Java while loop:Javapub
    3 min read
    Java Do While Loop
    Java do-while loop is an Exit control loop. Unlike for or while loop, a do-while check for the condition after executing the statements of the loop body.Example:Java// Java program to show the use of do while loop public class GFG { public static void main(String[] args) { int c = 1; // Using do-whi
    4 min read
    For-Each Loop in Java
    The for-each loop in Java (also called the enhanced for loop) was introduced in Java 5 to simplify iteration over arrays and collections. It is cleaner and more readable than the traditional for loop and is commonly used when the exact index of an element is not required.Example: Using a for-each lo
    8 min read

    Jump Statements in Java

    Java Continue Statement
    In Java, the continue statement is used inside the loops such as for, while, and do-while to skip the current iteration and move directly to the next iteration of the loop.Example:Java// Java Program to illustrate the use of continue statement public class Geeks { public static void main(String args
    4 min read
    Java Break Statement
    The Break Statement in Java is a control flow statement used to terminate loops and switch cases. As soon as the break statement is encountered from within a loop, the loop iterations stop there, and control returns from the loop immediately to the first statement after the loop. Example:Java// Java
    3 min read
    Java return Keyword
    return keyword in Java is a reserved keyword which is used to exit from a method, with or without a value. The usage of the return keyword can be categorized into two cases:Methods returning a valueMethods not returning a value1. Methods Returning a ValueFor the methods that define a return type, th
    4 min read

    Arrays in Java

    Arrays in Java
    Arrays in Java are one of the most fundamental data structures that allow us to store multiple values of the same type in a single variable. They are useful for storing and managing collections of data. Arrays in Java are objects, which makes them work differently from arrays in C/C++ in terms of me
    15+ min read
    Java Multi-Dimensional Arrays
    Multidimensional arrays are used to store the data in rows and columns, where each row can represent another individual array are multidimensional array. It is also known as array of arrays. The multidimensional array has more than one dimension, where each row is stored in the heap independently. T
    10 min read
    Jagged Array in Java
    In Java, a Jagged array is an array that holds other arrays. When we work with a jagged array, one thing to keep in mind is that the inner array can be of different lengths. It is like a 2D array, but each row can have a different number of elements.Example:arr [][]= { {10,20}, {30,40,50,60},{70,80,
    6 min read

    Strings in Java

    Java Strings
    In Java, a String is the type of object that can store a sequence of characters enclosed by double quotes, and every character is stored in 16 bits, i.e., using UTF 16-bit encoding. A string acts the same as an array of characters. Java provides a robust and flexible API for handling strings, allowi
    9 min read
    String Class in Java
    A string is a sequence of characters. In Java, objects of the String class are immutable, which means they cannot be changed once created. In this article, we are going to learn about the String class in Java.Example of String Class in Java:Java// Java Program to Create a String import java.io.*; cl
    7 min read
    StringBuffer Class in Java
    The StringBuffer class in Java represents a sequence of characters that can be modified, which means we can change the content of the StringBuffer without creating a new object every time. It represents a mutable sequence of characters.Features of StringBuffer ClassThe key features of StringBuffer c
    11 min read
    Java StringBuilder Class
    In Java, the StringBuilder class is a part of the java.lang package that provides a mutable sequence of characters. Unlike String (which is immutable), StringBuilder allows in-place modifications, making it memory-efficient and faster for frequent string operations.Declaration:StringBuilder sb = new
    7 min read

    OOPS in Java

    Java OOP(Object Oriented Programming) Concepts
    Java Object-Oriented Programming (OOPs) is a fundamental concept in Java that every developer must understand. It allows developers to structure code using classes and objects, making it more modular, reusable, and scalable.The core idea of OOPs is to bind data and the functions that operate on it,
    13 min read
    Classes and Objects in Java
    In Java, classes and objects are basic concepts of Object Oriented Programming (OOPs) that are used to represent real-world concepts and entities. The class represents a group of objects having similar properties and behavior, or in other words, we can say that a class is a blueprint for objects, wh
    11 min read
    Java Methods
    Java Methods are blocks of code that perform a specific task. A method allows us to reuse code, improving both efficiency and organization. All methods in Java must belong to a class. Methods are similar to functions and expose the behavior of objects.Example: Java program to demonstrate how to crea
    8 min read
    Access Modifiers in Java
    In Java, access modifiers are essential tools that define how the members of a class, like variables, methods, and even the class itself can be accessed from other parts of our program. They are an important part of building secure and modular code when designing large applications. Understanding de
    7 min read
    Wrapper Classes in Java
    A Wrapper class in Java is one whose object wraps or contains primitive data types. When we create an object in a wrapper class, it contains a field, and in this field, we can store primitive data types. In other words, we can wrap a primitive value into a wrapper class object. Let's check on the wr
    6 min read
    Need of Wrapper Classes in Java
    Firstly the question that hits the programmers is when we have primitive data types then why does there arise a need for the concept of wrapper classes in java. It is because of the additional features being there in the Wrapper class over the primitive data types when it comes to usage. These metho
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences