
Quick Contact
Java Tutorial
- What is Java?
- History of Java
- Hello Java Program
- Features of Java
- Basic Syntax
- Java Setup
- Data Types in Java
- Java Variables
- Operators in Java
- JVM
- Java If-else Statement
- Switch Case Statement
- Java Loops
- Do-While Loop
- Java While Loop
- Continue Statement
- Break Statement in Java
- Constructors in Java
- Oops Concept in Java
- Features of OOPs
- Inheritance
- Exeception handeling
- Aggregation (HAS-A relationship) in Java
- Method Overriding in Java
- Method Overloading
- Java Static Keyword
- Java This Keyword
- Java Final Keyword
- Polymorphism
- Static Binding and Dynamic Binding
- Abstract class in Java
- Access Modifiers in Java
- Difference between abstract class and interface
- Interface in Java
- Garbage Collection in Java
- Java Package
- Encapsulation
- Serialization and Deserialization in Java
- Java Inner Classes
- Java Applets
- Multithreading in Java
- Thread Priorities in Java
- Thread Creation
- Inter Thread Communication
- Wrapper Classes in Java
- Java Input Output
- Java AWT Introduction
- Java Layout Manager
- Java Layout Policy
- Java AWT Events
- Collection Framework
- Collection Framework List Interface
- Swing in Java
- Swing Utility Classes
- Swing Layout Managers
- Java JDBC
- Hibernate Framework Overview – Architecture and Basics
Springboot
- Spring Environment Setup
- Spring Boot CRUD REST API Project using IntelliJ IDEA | Postman | MySQL
- Dockerizing Spring Boot Application | Spring Boot Docker Tutorial
- spring-boot-restapidocumentation with swagger
- Spring Boot HttpClient Overview
- Apache HttpClient POST HTTP Request Example
- Apache HttpClient PUT HTTP Request Example
- Apache HttpClient DELETE HTTP Request Example
- Apache HttpClient HTML Form POST Request Example
- Spring Boot JSP Exampl
- Deploying Spring Boot WAR file with JSP to Tomcat
- Spring Boot Annotations
- Spring Core Annotations
- Spring MVC Annotations with Examples
- Spring Scheduling Annotations
- Spring - Java-based Container Configuration
- Spring Java Based Configuration Example
Hibernate
- Hibernate 5 hello world
- Hibernate- One to One Unidirectional Mapping Annotation Example
- Hibernate - Batch Processing
- Hibernate - Interceptors
- Hibernate 5 - Create, Read, Update and Delete (CRUD) Operations Example
- Hibernate Transaction Management
- Hibernate One to Many Unidirectional Mapping Example
- Hibernate One to Many Bidirectional Mapping Example
- Hibernate Many to Many Annotation Mapping Example
- Hibernate Primary KeyJoin Column
- Hibernate First Level Cache with Example
- Hibernate XML Configuration Example with Maven + Eclipse + MySQL Database
- Hibernate Java Configuration Example
- JPA 2 with Hibernate 5 Bootstrapping Example
- JPA and Hibernate Cascade Types
- Hibernate/JPA - Primary Key Generation
- Hibernate 5 - Enum Type Mapping Example
- Hibernate Component Mapping
- Hibernate Object States – Transient,Persistent and Detached
- Hibernate 5 - Save an Entity Example
- Hibernate 5 - Persist an Entity Example
- Hibernate 5 - saveOrUpdate() Method Example
- Hibernate 5 - get(), load() and byId() Method Examples
- Hibernate 5 - merge() Example
- Hibernate 5 - Delete or Remove an Entity Example
- Hibernate 5 - load() Method Example
- Hibernate Session Interface Methods
- Hibernate Session.clear() Method Example
- Introduction Of Java strutes to Architecture
- Struts 2 - Architecture
- Struts 2 - Configuration Files
- Struts 2 - Actions
- Struts 2 - Interceptors
- Struts 2 - Results & Result Types
- Struts 2 - Value Stack/OGNL
- Struts 2 - File Uploading
- Struts 2 - Database Access
- Struts 2 - Validations Framework
JAVA FX
- JavaFX Tutorial
- Introduction to JavaFX Pane
- JavaFX Popup
- JavaFX group
- JavaFX Controller
- JavaFX Gradient Color
- JavaFXAnchorPane
- JavaFXTabPane
- JavaFX Scene
- JavaFX Stage
- JavaFXWebView
- JavaFX Timeline
- JavaFX Timer
- JavaFX Image
- JavaFX Background
- JavaFX dialog
- JavaFX Font
- JavaFXTextArea
- JavaFXObservableList
- JavaFX GUI
- JavaFX FXML
- JavaFXEventHandler
- JavaFXGradle
- JavafxScrollpane
- JavaFXAPI
Operators in Java
The operator set in Java is extremely rich. Broadly, the operators available in Java are divided in the following categories.
- Relational Operators
- Arithmetic Operators
- Logical Operators
- Bitwise Operators
- Misc Operators
- Assignment Operators
The Relational Operator
Java also supports several relational operators. The list of relational operators that are supported by Java are given below.
Operation | Operator | Description |
---|---|---|
Equal To | == | Compares the value of two variables for equality |
Not Equal To | != | Compares the value of two variables for inequality |
Greater Than | > | Checks if one value is greater than the other value |
Lesser Than | < | Checks if one value is lesser than the other value |
Greater Than Or Equal To | >= | Checks if one value is greater than or equal to the other value |
Lesser Than Or Equal To | <= | Checks if one value is lesser than or equal to the other value |
The Arithmetic Operator
Operations in Java are used in essentially the same manner as in algebra. They are used with variables for performing arithmetic operations. Here is a list of arithmetic operators available in Java.
Operation | Operator | Description |
---|---|---|
Addition | + | Add the values of two variables |
Subtraction | – | Subtract the values of two variables |
Multiplication | * | Multiplies the values of two variables |
Division | / | Divides the values of two variables |
Modulus | % | The resultant value is the remainder of division |
Increment | ++ | Increases the value by 1 |
Decrement | — | Decreases the value by 1 |
The Logical Operators
Logical operators are an integral part of any operator set. The logical operators supported by Java are listed in the table below.
Operation | Operator | Description |
---|---|---|
Logical AND | && | Returns True if both the conditions mentioned are true |
Logical OR | || | Returns True if one or both the conditions mentioned are true |
Logical NOT | ! | Returns True if the condition mentioned is False |
The Bitwise Operators
The bitwise operators available in Java can be easily applied to a number of data types. These data types include byte, short, long, int and char. Typically, any bitwise operator performs the concerned operation bit-wise. For instance, if you consider the example of an integer x, which has the value 60. Therefore, the binary equivalent of x is 00111100. Consider another variable y, with the value 13 or 00001101. If we perform the bitwise operation & on these two numbers, then you will get the following result:
x&y = 0000 1100
The table shown below shows a list of bitwise operators that are available in Java.
Operation | Operator | Description |
---|---|---|
BINARY AND | & | Perform the AND Operation |
BINARY OR | | | Perform the OR Operation |
BINARY XOR | ^ | Perform the XOR Operation |
ONE’S COMPLEMENT | ~ | Perform the complementation operation on a unary variable |
BINARY LEFT SHIFT | << | Perform the left shifting of bits |
BINARY RIGHT SHIFT | >> | Perform the right shifting of bits |
Misc Operators
In addition to the above mentioned, there are several other operators, which are supported by Java.
Conditional Operator (? :):
The conditional operator is a ternary operator that contains three operands. Essentially, this operator is used for the evaluation of Boolean expressions. The operator tests the first operand or condition and if the condition is true, then the second value is assigned to the variable. However, if the condition is false, the third operand is assigned to the variable.
The syntax of this operator is as follows:
variable a = (< condition>) ? valueiftrue : valueiffalse
Sample implementation:
public class myTest {
public static void main(String args[]){
int x, y;
x = 5;
y = (x == 5) ? 15: 40;
System.out.println( “y = ” + y );
y = (x == 34) ? 60: 95;
System.out.println( “x = ” + y );
}
}
The compilation and execution of this code shall give the following result:
Output
y= 15
y= 95
instance of operator
Only object reference variables can be used with this operator. The objective of this operator is to check is an object is an instance of an exiting class.
The syntax of this operator is as follows:
(< object reference variable>) instanceof(< interface/class>)
Sample implementation of this operator and its purpose of use is given below:
public class myTest {
public static void main(String args[]){
int x = 4;
boolean resultant = x instanceof int;
System.out.println( resultant );
}
}
The output of this code shall be true. This operator can also be used in comparison. A sample implementation of this is given below:
class Animal {}
public class Monkey extends Animal {
public static void main(String args[]){
Animal newa = new Monkey();
boolean resultant = newa instanceof Monkey;
System.out.println( resultant );
}
}
The output for this code will also be true.
The Assignment Operator
There are following assignment operators supported by Java language:
Operation | Operator | Description |
---|---|---|
Simple assignment operator | = | Assigns a value on the right to the variable in the left |
Add – assignment operator | += | Adds the value on the right to the value of the variable on the left and assigns the resultant to the variable on the left |
Subtract – assignment operator | -= | Subtracts the value on the right to the value of the variable on the left and assigns the resultant to the variable on the left |
Multiply – assignment operator | *= | Multiplies the value on the right to the value of the variable on the left and assigns the resultant to the variable on the left |
Divide – assignment operator | /= | Divides the value on the right to the value of the variable on the left and assigns the resultant to the variable on the left |
Modulus -assignment operator | %= | It takes the modulus of the LHS and RHS and assigns the resultant to the variable on the left |
Left shift – assignment operator | <<= | It takes the left shift of the LHS and RHS and assigns the resultant to the variable on the left |
Right shift – assignment operator | >>= | It takes the right shift of the LHS and RHS and assigns the resultant to the variable on the left |
Bitwise – assignment operator | &= | It takes the bitwise AND of the LHS and RHS and assigns the resultant to the variable on the left |
bitwise exclusive OR – assignment operator | ^= | It takes the bitwise XOR of the LHS and RHS and assigns the resultant to the variable on the left |
bitwise inclusive OR – assignment operator | |= | It takes the bitwise OR of the LHS and RHS and assigns the resultant to the variable on the left |
Precedence of Java Operator
More often than not, operators are used in combinations in expressions. However, you must have also realized that it becomes difficult to predict the order in which operations will take place during execution. The operator precedence table for Java shall help you predict operator operations in an expression deduction. For instance, if you are performing addition and multiplication in the same expression, then multiplication takes place prior to addition. The following table illustrates the order and hierarchy of operators in Java. The associativity for all the operators is left to right.
Operator | Category |
---|---|
() [] . (dot operator) | Postfix |
++ – – ! ~ | Unary |
* / % | Multiplicative |
+ – | Additive |
>> >>> << | Shift |
> >= < <= | Relational |
== != | Equality |
& | Bitwise AND |
| | Bitwise OR |
^ | Bitwise XOR |
&& | Logical AND |
|| | Logical OR |
?: | Conditional |
= += -= *= /= %= >>= <<= &= ^= |= | Assignment |
, | Comma |
Apply Now for Advanced Java Training Course