You are on page 1of 30

Introduction to Java

A small history of Java:


Java is a programming language created by James Gosling from Sun Microsystems
(Sun) in 1991. The target of Java is to write a program once and then run this
program on multiple operating systems. The first publicly available version of Java
(Java 1.0) was released in 1995. Sun Microsystems was acquired by the Oracle
Corporation in 2010. Oracle has now the steermanship for Java. In 2006 Sun started
to make Java available under the GNU General Public License (GPL). Oracle
continues this project calledOpenJDK.

Over time new enhanced versions of Java have been released. The current version
of Java is Java 1.8 which is also known as Java 8.

Java is defined by a specification and consists of a programming language, a


compiler, core libraries and a runtime (Java virtual machine) The Java runtime
allows software developers to write program code in other languages than the Java
programming language which still runs on the Java virtual machine. The Java
platform is usually associated with the Java virtual machine and the Java core
libraries.

The Java language was designed with the following properties:

 Platform independent: Java programs use the Java virtual machine as abstraction
and do not access the operating system directly. This makes Java programs
highly portable. A Java program (which is standard-compliant and follows
certain rules) can run unmodified on all supported platforms, e.g., Windows or
Linux.
 Object-orientated programming language: Except the primitive data types, all
elements in Java are objects.
 Strongly-typed programming language: Java is strongly-typed, e.g., the types of
the used variables must be pre-defined and conversion to other objects is
relatively strict, e.g., must be done in most cases by the programmer.
 Interpreted and compiled language: Java source code is transferred into the
bytecode format which does not depend on the target platform. These bytecode
instructions will be interpreted by the Java Virtual machine (JVM). The JVM
contains a so called Hotspot-Compiler which translates performance critical
bytecode instructions into native code instructions.
 Automatic memory management: Java manages the memory allocation and de-
allocation for creating new objects. The program does not have direct access to
the memory. The so-called garbage collector automatically deletes objects to
which no active pointer exists.

The Java syntax is similar to C++. Java is case-sensitive, e.g., variables


called myValue and myvalue are treated as different variables.

Java terminology
Before we start learning Java, lets get familiar with common java terms.

Java Virtual Machine (JVM)

This is generally referred as JVM. Before, we discuss about JVM lets see the
phases of program execution. Phases are as follows: we write the program, then we
compile the program and at last we run the program.
1) Writing of the program is of course done by java programmer like you and me.
2) Compilation of program is done by javac compiler, javac is the primary java
compiler included in java development kit (JDK). It takes java program as input
and generates java bytecode as output.
3) In third phase, JVM executes the bytecode generated by compiler. This is called
program run phase.

So, now that we understood that the primary function of JVM is to execute the
bytecode produced by compiler. Each operating system has different JVM,
however the output they produce after execution of bytecode is same across all
operating systems. That is why we call java as platform independent language.

bytecode
As discussed above, javac compiler of JDK compiles the java source code into
bytecode so that it can be executed by JVM. The bytecode is saved in a .class file
by compiler.

Java Development Kit(JDK)

While explaining JVM and bytecode, I have used the term JDK. Let’s discuss
about it. As the name suggests this is complete java development kit that includes
JRE (Java Runtime Environment), compilers and various tools like JavaDoc, Java
debugger,etc.
In order to create, compile and run Java program you would need JDK installed on
your computer.
Java Runtime Environment(JRE)

JRE is a part of JDK which means that JDK includes JRE. When you have JRE
installed on your system, you can run a java program however you won’t be able to
compile it. JRE includes JVM, browser plugins and applets support. When you
only need to run a java program on your computer, you would only need JRE.

1.4. Java Runtime Environment vs. Java Development Kit


A Java distribution typically comes in two flavors, the Java Runtime
Environment (JRE) and the Java Development Kit (JDK).

The JRE consists of the JVM and the Java class libraries. Those contain the
necessary functionality to start Java programs.

The JDK additionally contains the development tools necessary to create Java
programs. The JDK therefore consists of a Java compiler, the Java virtual machine
and the Java class libraries.

Main Features of JAVA


Features of Java

Where it is used?
According to Sun, 3 billion devices run java. There are many devices where java is
currently used. Some of them are as follows:

1. Desktop Applications such as acrobat reader, media player, antivirus etc.


2. Web Applications such as irctc.co.in, javatpoint.com etc.
3. Enterprise Applications such as banking applications.
4. Mobile
5. Embedded System
6. Smart Card
7. Robotics
8. Games etc.

Types of Java Applications


There are mainly 4 type of applications that can be created using java
programming:
1) Standalone Application

It is also known as desktop application or window-based application. An


application that we need to install on every machine such as media player,
antivirus etc. AWT and Swing are used in java for creating standalone applications.

2) Web Application

An application that runs on the server side and creates dynamic page, is called web
application. Currently, servlet, jsp, struts, jsf etc. technologies are used for creating
web applications in java.

3) Enterprise Application

An application that is distributed in nature, such as banking applications etc. It has


the advantage of high level security, load balancing and clustering. In java, EJB is
used for creating enterprise applications.

4) Mobile Application

An application that is created for mobile devices. Currently Android and Java ME
are used for creating mobile applications.

Java Version History

There are many java versions that has been released. Current stable release of Java
is Java SE 8.

1. JDK Alpha and Beta (1995)


2. JDK 1.0 (23rd Jan, 1996)
3. JDK 1.1 (19th Feb, 1997)
4. J2SE 1.2 (8th Dec, 1998)
5. J2SE 1.3 (8th May, 2000)
6. J2SE 1.4 (6th Feb, 2002)
7. J2SE 5.0 (30th Sep, 2004)
8.
Comparison C++ Java
Index

Platform- C++ is platform- Java is platform-independent.


independent dependent.

Mainly used for C++ is mainly Java is mainly used for application programming. It is
used for system widely used in window, web-based, enterprise and
programming. mobile applications.

Goto C++ supports Java doesn't support goto statement.


goto statement.

Multiple C++ supports Java doesn't support multiple inheritance through


inheritance multiple class. It can be achieved by interfaces in java.
inheritance.

Operator C++ supports Java doesn't support operator overloading.


Overloading operator
overloading.

Pointers C++ supports Java supports pointer internally. But you can't write
pointers. You the pointer program in java. It means java has
can write pointer restricted pointer support in java.
program in C++.

Compiler and C++ uses Java uses compiler and interpreter both.
Interpreter compiler only.

Call by Value C++ supports Java supports call by value only. There is no call by
and Call by both call by reference in java.
reference value and call by
reference.

Structure and C++ supports Java doesn't support structures and unions.
Union structures and
unions.

Thread Support C++ doesn't Java has built-in thread support.


have built-in
support for
threads. It relies
on third-party
libraries for
thread support.

Documentation C++ doesn't Java supports documentation comment (/** ... */) to
comment support create documentation for java source code.
documentation
comment.

Virtual C++ supports Java has no virtual keyword. We can override all non-
Keyword virtual keyword static methods by default. In other words, non-static
so that we can methods are virtual by default.
decide whether
or not override a
function.

unsigned right C++ doesn't Java supports unsigned right shift >>> operator that
shift >>> support >>> fills zero at the top for the negative numbers. For
operator. positive numbers, it works same like >> operator.

Inheritance Tree C++ creates a Java uses single inheritance tree always because all
new inheritance classes are the child of Object class in java. Object
tree always. class is the root of inheritance tree in java.

Understanding first java program


Let's see what is the meaning of class, public, static, void, main, String[],
System.out.println().

o class keyword is used to declare a class in java.


o public keyword is an access modifier which represents visibility, it means it
is visible to all.
o static is a keyword, if we declare any method as static, it is known as static
method. The core advantage of static method is that there is no need to
create object to invoke the static method. The main method is executed by
the JVM, so it doesn't require to create object to invoke the main method. So
it saves memory.
o void is the return type of the method, it means it doesn't return any value.
o main represents startup of the program.
o String[] args is used for command line argument. We will learn it later.
o System.out.println() is used print statement. We will learn about the
internal working of System.out.println statement later.

What happens at compile time?


o At compile time, java file is compiled by Java Compiler (It does not interact
with OS) and converts the java code into bytecode.

What happens at runtime?


At runtime, following steps are performed:

Classloader: is the subsystem of JVM that is used to load class files.


Bytecode Verifier: checks the code fragments for illegal code that can violate
access right to objects.
Interpreter: read bytecode stream then execute the instructions.

Simple Java Program:

class FirstProgram

{
public static void main(String args[])
{

System.out.println("Hai, welcome");

}
}
Save the File name as same as the Class name
FirstProgram.java
Compile and Run the Program shown below:

Variables in Java
To declare a variable follow this syntax:

data_type variable_name=value;
int i=10;
Similarly we can assign the values to the variables while declaring them, like this:

char ch = 'A';
int number = 100;
or we can do it like this:

char ch;
int number;
...
ch = 'A';
number = 100;

Rules for Framing the Variables in Java:


1) Variables naming cannot contain white spaces, for example: int num ber =
100; is invalid because the variable name has space in it.
2) Variable name can begin with special characters such as $ and _
3) As per the java coding standards the variable name should begin with a
lower case letter, for example int number; For lengthy variables names that
has more than one words do it like this: int smallNumber; int bigNumber;
(start the second word with capital letter).
4) Variable names are case sensitive in Java.

Types of Variables in Java


There are three types of variables in Java.
1) Local variable 2) Static (or class) variable 3) Instance variable

Static (or class) Variable


Static variables are also known as class variable because they are associated with
the class and common for all the instances of class. For example, If I create three
objects of a class and access this static variable, it would be common for all, the
changes made to the variable using one of the object would reflect when you
access it through other objects.

Example of static variable


public class StaticVarExample {
public static String myClassVar="class or static variable";
public static void main(String args[]){
StaticVarExample obj = new StaticVarExample();
StaticVarExample obj2 = new StaticVarExample();
StaticVarExample obj3 = new StaticVarExample();
//All three will display "class or static variable"
System.out.println(obj.myClassVar);
System.out.println(obj2.myClassVar);
System.out.println(obj3.myClassVar);

//changing the value of static variable using obj2


obj2.myClassVar = "Changed Text";

//All three will display "Changed Text"


System.out.println(obj.myClassVar);
System.out.println(obj2.myClassVar);
System.out.println(obj3.myClassVar);
}
}

Instance variable
Each instance(objects) of class has its own copy of instance variable. Unlike static
variable, instance variables have their own separate copy of instance variable. We
have changed the instance variable value using object obj2 in the following
program and when we displayed the variable using all three objects, only the obj2
value got changed, others remain unchanged. This shows that they have their own
copy of instance variable.

Example of Instance variable


public class InstanceVarExample {
String myInstanceVar="instance variable";
public static void main(String args[]){
InstanceVarExample obj = new InstanceVarExample();
InstanceVarExample obj2 = new InstanceVarExample();
InstanceVarExample obj3 = new InstanceVarExample();
System.out.println(obj.myInstanceVar);
System.out.println(obj2.myInstanceVar);
System.out.println(obj3.myInstanceVar);

obj2.myInstanceVar = "Changed Text";

System.out.println(obj.myInstanceVar);
System.out.println(obj2.myInstanceVar);
System.out.println(obj3.myInstanceVar);
}
}

Local Variable
These variables are declared inside method of the class. Their scope is limited to
the method which means that You can’t change their values and access them
outside of the method.

In this example, I have declared the instance variable with the same name as local
variable, this is to demonstrate the scope of local variables.

Example of Local variable


public class VariableExample {
// instance variable
public String myVar="instance variable";
public void myMethod(){
// local variable
String myVar = "Inside Method";
System.out.println(myVar);
}
public static void main(String args[]){
// Creating object
VariableExample obj = new VariableExample();
/* We are calling the method, that changes the
* value of myVar. We are displaying myVar again after
* the method call, to demonstrate that the local
* variable scope is limited to the method itself.
*/
System.out.println("Calling Method");
obj.myMethod();
System.out.println(obj.myVar);
}
}

Data Types in Java


Data types represent the different values to be stored in the variable. In java, there
are two types of data types:

o Primitive data types


o Non-primitive data types

Data Type Default Value Default size


boolean false 1 bit

char '\u0000' 2 byte

byte 0 1 byte

short 0 2 byte

int 0 4 byte

long 0L 8 byte

float 0.0f 4 byte

double 0.0d 8 byte

byte:
This can hold whole number between -128 and 127. Mostly used to save memory
and when you are certain that the numbers would be in the limit specified by byte
data type.
Default size of this data type: 1 byte.
Default value: 0
Example:

class JavaExample {
public static void main(String[] args) {
byte num;
num = 113;
System.out.println(num);
}
}

Try the same program by assigning value assigning 150 value to variable num, you
would get type mismatch error because the value 150 is out of the range of byte
data type. The range of byte as I mentioned above is -128 to 127.

short:
This is greater than byte in terms of size and less than integer. Its range is -32,768
to 32767.
Default size of this data type: 2 byte

short num = 45678;

int: Used when short is not large enough to hold the number, it has a wider range: -
2,147,483,648 to 2,147,483,647
Default size: 4 byte
Default value: 0

Example:

class JavaExample {
public static void main(String[] args) {
short num;
num = 150;
System.out.println(num);
}
}
The byte data type couldn’t hold the value 150 but a short data type can because it
has a wider range.

long:
Used when int is not large enough to hold the value, it has wider range than int
data type, ranging from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807.
size: 8 bytes
Default value: 0

Example:

class JavaExample {
public static void main(String[] args) {
long num = -12332252626L;
System.out.println(num);
}
}
double: Sufficient for holding 15 decimal digits
size: 8 bytes
Example:

class JavaExample {
public static void main(String[] args) {
double num = -42937737.9d;
System.out.println(num);
}
}

float: Sufficient for holding 6 to 7 decimal digits


size: 4 bytes

class JavaExample {
public static void main(String[] args) {
float num = 19.98f;
System.out.println(num);
}
}
boolean: holds either true of false.
class JavaExample {
public static void main(String[] args) {
boolean b = false;
System.out.println(b);
}
}
char: holds characters.
size: 2 bytes

class JavaExample {
public static void main(String[] args) {
char ch = 'Z';
System.out.println(ch);
}
}
Literals in Java
A literal is a fixed value that we assign to a variable in a Program.

int num=10;
Here value 10 is a Integer literal.

char ch = 'A';
Here A is a char literal

Integer Literal
Integer literals are assigned to the variables of data type byte, short, int and long.

byte b = 100;
short s = 200;
int num = 13313131;
long l = 928389283L;
Float Literals
Used for data type float and double.

double num1 = 22.4;


float num2 = 22.4f;
Note: Always suffix float value with the “f” else compiler will consider it as
double.

Char and String Literal


Used for char and String type.

char ch = 'Z';
String str = "BeginnersBook";

Operators in Java
Types of Operator in Java
1)Basic Arithmetic Operators
2)Assignment Operators
3)Auto-increment and Auto-decrement Operators
4)Logical Operators
5)Comparison(relational) operators
6)Bitwise Operators
7) Ternary Operator

The Arithmetic Operators


Assume integer variable A holds 10 and variable B holds 20, then –

Operator Description Example

Adds values on either side of the operator. A + B will


+ (Addition)
give 30

Subtracts right-hand operand from left-hand operand. A - B will


- (Subtraction)
give -10

Multiplies values on either side of the operator. A * B will


* (Multiplication)
give 200

Divides left-hand operand by right-hand operand. B / A will


/ (Division)
give 2

Divides left-hand operand by right-hand operand and returns B % A will


% (Modulus)
remainder. give 0

Increases the value of operand by 1. B++ gives


++ (Increment)
21

-- (Decrement) Decreases the value of operand by 1. B-- gives 19


public class Test {

public static void main(String args[]) {


int a = 10;
int b = 20;
int c = 25;
int d = 25;

System.out.println("a + b = " + (a + b) );
System.out.println("a - b = " + (a - b) );
System.out.println("a * b = " + (a * b) );
System.out.println("b / a = " + (b / a) );
System.out.println("b % a = " + (b % a) );
System.out.println("c % a = " + (c % a) );
System.out.println("a++ = " + (a++) );
System.out.println("b-- = " + (a--) );

// Check the difference in d++ and ++d


System.out.println("d++ = " + (d++) );
System.out.println("++d = " + (++d) );
}
}

The Relational Operators


There are following relational operators supported by Java language.
Assume variable A holds 10 and variable B holds 20, then –

Operator Description Example

== (equal to) Checks if the values of two operands are equal or not, (A == B) is
if yes then condition becomes true. not true.

Checks if the values of two operands are equal or not, (A != B) is


!= (not equal to)
if values are not equal then condition becomes true. true.

Checks if the value of left operand is greater than the


(A > B) is not
> (greater than) value of right operand, if yes then condition becomes
true.
true.

Checks if the value of left operand is less than the


(A < B) is
< (less than) value of right operand, if yes then condition becomes
true.
true.

Checks if the value of left operand is greater than or


>= (greater than (A >= B) is
equal to the value of right operand, if yes then
or equal to) not true.
condition becomes true.

Checks if the value of left operand is less than or equal


<= (less than or (A <= B) is
to the value of right operand, if yes then condition
equal to) true.
becomes true.

public class Test {

public static void main(String args[]) {


int a = 10;
int b = 20;

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("b >= a = " + (b >= a) );
System.out.println("b <= a = " + (b <= a) );
}
}
The Bitwise Operators
Java defines several bitwise operators, which can be applied to the integer types,
long, int, short, char, and byte.
Bitwise operator works on bits and performs bit-by-bit operation. Assume if a =
60 and b = 13; now in binary format they will be as follows −
a = 0011 1100
b = 0000 1101
-----------------
a&b = 0000 1100
a|b = 0011 1101
a^b = 0011 0001
~a  = 1100 0011
The following table lists the bitwise operators −
Assume integer variable A holds 60 and variable B holds 13 then −

Operator Description Example

& (bitwise Binary AND Operator copies a bit to the result (A & B) will give 12 which is
and) if it exists in both operands. 0000 1100

Binary OR Operator copies a bit if it exists in (A | B) will give 61 which is


| (bitwise or)
either operand. 0011 1101
^ (bitwise Binary XOR Operator copies the bit if it is set (A ^ B) will give 49 which is
XOR) in one operand but not both. 0011 0001

(~A ) will give -61 which is


~ (bitwise Binary Ones Complement Operator is unary and 1100 0011 in 2's complement
compliment) has the effect of 'flipping' bits. form due to a signed binary
number.

Binary Left Shift Operator. The left operands


A << 2 will give 240 which is
<< (left shift) value is moved left by the number of bits
1111 0000
specified by the right operand.

Binary Right Shift Operator. The left operands


A >> 2 will give 15 which is
>> (right shift) value is moved right by the number of bits
1111
specified by the right operand.

Shift right zero fill operator. The left operands


>>> (zero fill value is moved right by the number of bits A >>>2 will give 15 which is
right shift) specified by the right operand and shifted values 0000 1111
are filled up with zeros.

public class Test {

public static void main(String args[]) {


int a = 60; /* 60 = 0011 1100 */
int b = 13; /* 13 = 0000 1101 */
int c = 0;

c = a & b; /* 12 = 0000 1100 */


System.out.println("a & b = " + c );

c = a | b; /* 61 = 0011 1101 */
System.out.println("a | b = " + c );

c = a ^ b; /* 49 = 0011 0001 */
System.out.println("a ^ b = " + c );

c = ~a; /*-61 = 1100 0011 */


System.out.println("~a = " + c );
c = a << 2; /* 240 = 1111 0000 */
System.out.println("a << 2 = " + c );

c = a >> 2; /* 15 = 1111 */
System.out.println("a >> 2 = " + c );

c = a >>> 2; /* 15 = 0000 1111 */


System.out.println("a >>> 2 = " + c );
}
}
The Logical Operators:
The following table lists the logical operators −
Assume Boolean variables A holds true and variable B holds false, then −

Operator Description Example

Called Logical AND operator. If both the operands


&& (logical and) (A && B) is false
are non-zero, then the condition becomes true.

Called Logical OR Operator. If any of the two


|| (logical or) operands are non-zero, then the condition becomes (A || B) is true
true.

Called Logical NOT Operator. Use to reverses the


! (logical not) logical state of its operand. If a condition is true !(A && B) is true
then Logical NOT operator will make false.

public class Test {

public static void main(String args[]) {


boolean a = true;
boolean b = false;

System.out.println("a && b = " + (a&&b));


System.out.println("a || b = " + (a||b) );
System.out.println("!(a && b) = " + !(a && b));
}
}

The Assignment Operators


Following are the assignment operators supported by Java language −

Operato Description Example


r

Simple assignment operator. Assigns values from right side operands C = A + B


to left side operand. will assign
=
value of A
+ B into C

Add AND assignment operator. It adds right operand to the left C += A is


operand and assign the result to left operand. equivalent
+=
to C = C +
A

Subtract AND assignment operator. It subtracts right operand from the C -= A is


left operand and assign the result to left operand. equivalent
-=
to C = C –
A

Multiply AND assignment operator. It multiplies right operand with C *= A is


the left operand and assign the result to left operand. equivalent
*=
to C = C *
A

/= Divide AND assignment operator. It divides left operand with the right C /= A is
operand and assign the result to left operand. equivalent
to C = C /
A

Modulus AND assignment operator. It takes modulus using two C %= A is


operands and assign the result to left operand. equivalent
%=
to C = C %
A

C <<= 2 is
<<= Left shift AND assignment operator. same as C
= C << 2

C >>= 2 is
>>= Right shift AND assignment operator. same as C
= C >> 2

C &= 2 is
&= Bitwise AND assignment operator. same as C
=C&2

bitwise exclusive OR and assignment operator. C ^= 2 is


^= same as C
=C^2

bitwise inclusive OR and assignment operator. C |= 2 is


|= same as C
=C|2
public class Test {

public static void main(String args[]) {


int a = 10;
int b = 20;
int c =0;
c = a + b;
System.out.println("c = a + b = " + c );
c += a ;
System.out.println("c += a = " + c );
c -= a ;
System.out.println("c -= a = " + c );
c *= a ;
System.out.println("c *= a = " + c );
a = 10;
c = 15;
c /= a ;
System.out.println("c /= a = " + c );
a = 10;
c = 15;
c %= a ;
System.out.println("c %= a = " + c );
c <<= 2 ;
System.out.println("c <<= 2 = " + c );
c >>= 2 ;
System.out.println("c >>= 2 = " + c );
c >>= 2 ;
System.out.println("c >>= 2 = " + c );
c &= a ;
System.out.println("c &= a = " + c );
c ^= a ;
System.out.println("c ^= a = " + c );
c |= a ;
System.out.println("c |= a = " + c );
}
}

Miscellaneous Operators
There are few other operators supported by Java Language.

Conditional Operator ( ? : )
Conditional operator is also known as the ternary operator. This operator
consists of three operands and is used to evaluate Boolean expressions. The goal
of the operator is to decide, which value should be assigned to the variable. The
operator is written as −
variable x = (expression) ? value if true : value if false
Following is an example −
Example
public class Test {
public static void main(String args[]) {
int a, b;
a = 10;
b = (a == 1) ? 20: 30;
System.out.println( "Value of b is : " + b );

b = (a == 10) ? 20: 30;


System.out.println( "Value of b is : " + b );
}
}

instanceof Operator
This operator is used only for object reference variables. The operator checks
whether the object is of a particular type (class type or interface type). instanceof
operator is written as −
( Object reference variable ) instanceof (class/interface type)
If the object referred by the variable on the left side of the operator passes the IS-
A check for the class/interface type on the right side, then the result will be true.
Following is an example –
Example
public class Test {
public static void main(String args[]) {
String name = "James";

// following will return true since name is type of String


boolean result = name instanceof String;
System.out.println( result );
}
}

Example:
class Vehicle {}

public class Car extends Vehicle {

public static void main(String args[]) {

Vehicle a = new Car();


boolean result = a instanceof Car;
System.out.println( result );

Precedence of Java Operators


Operator precedence determines the grouping of terms in an expression. This
affects how an expression is evaluated. Certain operators have higher precedence
than others; for example, the multiplication operator has higher precedence than
the addition operator −
For example, x = 7 + 3 * 2; here x is assigned 13, not 20 because operator * has
higher precedence than +, so it first gets multiplied with 3 * 2 and then adds into
7.
Here, operators with the highest precedence appear at the top of the table, those
with the lowest appear at the bottom. Within an expression, higher precedence
operators will be evaluated first.
Category Operator Associativity

Postfix expression++ expression-- Left to right

Unary ++expression –-expression +expression –expression ~ ! Right to left

Multiplicative */% Left to right

Additive +- Left to right

Shift << >> >>> Left to right

Relational < > <= >= instanceof Left to right

Equality == != Left to right

Bitwise AND & Left to right

Bitwise XOR ^ Left to right

Bitwise OR | Left to right

Logical AND && Left to right

Logical OR || Left to right


Conditional ?: Right to left

Assignment = += -= *= /= %= ^= |= <<= >>= >>>=

You might also like