& Operator in Java with Examples Last Updated : 10 Oct, 2019 Comments Improve Suggest changes 18 Likes Like Report The & operator in Java has two definite functions: As a Relational Operator: & is used as a relational operator to check a conditional statement just like && operator. Both even give the same result, i.e. true if all conditions are true, false if any one condition is false. However, there is a slight difference between them, which highlights the functionality of & operator: && operator: It only evaluates the next condition, if the condition before it is true. If anyone condition is false, it does not evaluate the statement any further. & operator: It evaluates all conditions even if they are false. Thus, any change in the data values due to the conditions will only be reflected in this case. Example: Java // Java program to demonstrate // & operator as relational operator import java.io.*; class GFG { public static void main(String[] args) { int x = 5, y = 7, z = 9; System.out.println("Demonstrating && operator"); if ((x > y) && (x++ > z)) ; else System.out.println("Value of x: " + x); System.out.println("\nDemonstrating & operator"); if ((x > y) & (x++ > z)) ; else System.out.println("Value of x: " + x); } } Output: Demonstrating && operator Value of x: 5 Demonstrating & operator Value of x: 6 As a Bitwise AND: & operator is used for adding Bitwise numbers in Java. Bitwise numbers are binary numbers stored in the form of integers. Some people will ask what is the use of these Bitwise numbers anyway? Why not store every number in its decimal form and perform the normal operations using our traditional operators: +, -, /, %, *. Its because all our encoding and decoding of data is done in bits, as they allow packing a huge amount of information into a tiny space. Example: Java // Java program to demonstrate // & operator as bitwise operator import java.io.*; class GFG { public static void main(String[] args) { int a = 12; int b = 25; System.out.println("Demonstrating & operator\n"); int c = a & b; System.out.println(a + " & " + b + " = " + c); } } Output: Demonstrating & operator 12 & 25 = 8 Create Quiz Comment D daksheshgusain2001 Follow 18 Improve D daksheshgusain2001 Follow 18 Improve Article Tags : Java Java-Operators Explore Java BasicsIntroduction to Java3 min readJava Programming Basics9 min readJava Methods6 min readAccess Modifiers in Java4 min readArrays in Java7 min readJava Strings7 min readRegular Expressions in Java3 min readOOP & InterfacesClasses and Objects in Java5 min readAccess Modifiers in Java4 min readJava Constructors4 min readJava OOP(Object Oriented Programming) Concepts10 min readJava Packages2 min readJava Interface7 min readCollectionsCollections in Java12 min readCollections Class in Java13 min readCollection Interface in Java4 min readIterator in Java4 min readJava Comparator Interface5 min readException HandlingJava Exception Handling6 min readJava Try Catch Block4 min readJava final, finally and finalize4 min readChained Exceptions in Java3 min readNull Pointer Exception in Java5 min readException Handling with Method Overriding in Java4 min readJava AdvancedJava Multithreading Tutorial3 min readSynchronization in Java7 min readFile Handling in Java4 min readJava Method References9 min readJava 8 Stream Tutorial7 min readJava Networking6 min readJDBC Tutorial5 min readJava Memory Management3 min readGarbage Collection in Java6 min readMemory Leaks in Java3 min readPractice JavaJava Interview Questions and Answers15+ min readJava Programs - Java Programming Examples7 min readJava Exercises - Basic to Advanced Java Practice Programs with Solutions5 min readJava Quiz1 min readJava Project Ideas For Beginners and Advanced15+ min read Like