Reserved words & Operators in Java

Reserved words & Operators in Java

Keywords / Reserved words

Hi guys, I am back with another topic on Java, which is 5th article of our ongoing java programming series. So In today's article we will focusing on reserved words of Java language which has been used throughout the language for their pre-defined meanings.

Meanwhile if you are reading this article series for the first time then, do checkout the previous articles of the series.

Article-4 Article-3?Article-2?Article-1?click to read the respective article in ongoing java series.

  • What are keywords?
  • If any predefined word having both

  1. word recognition
  2. internal functionality

  • Then that predefined words are called as Keywords .
  • What is reserved words?
  • If any predefined words having only word recognition without internal functionality then that predefined word is called as Reserved words .
  • example:
  • goto, const etc
  • To develop a java application, we have different list of keywords provided by Java.
  • Data Types & Return Types

bytes, short, int, long, float, double, char, boolean, void .        

  • Access Modifiers

public, protected, private, static, final, abstract, native,
volatile, transient, synchronized, strictfp .. etc        

  • Program Flow Controllers.

if, else, switch, case, default, for, while, do, break, continue,
return .. etc.        

  • Class/ objects related keywords

class, enum, extends, interface, implements, package, import, 
new, this, super, ... etc        

  • Exception Handling keywords

throw, throws, try, catch, finally         

The history of different version of java can be seen here https://en.wikipedia.org/wiki/Java_version_history

Operators

Operator is a symbol, which performs a particular operation over the provided operands.

In java programming language we have given below lists of operators:

  1. Arithmetic Operators:

+,-.,*,/,%,++, --        

  1. Assignment Operators

=, +=, -=, *=, /=, %= ...        

  1. Comparision Operators

==, !=, <, >, <=, >=,...        

  1. Boolean Operator

&&, ||, !, ^        

  1. Bitwise Logical Operator

&, |, ^, <<, >>...         

  1. Ternary Operator

Expression ? resultGenerated : falseResult        

Example 1:

No alt text provided for this image

Output:

>java Operators
The number is 10
The post increased number is10
the pre increased number is 12
the post decreased number is 12
the pre decreased number is 10
the number is : 10        

Example-2:

class ComplexOperator{
	public static void main(String[] args){
		int num = 5;
		System.out.println("The number is " + ++num-++num);
	}
}        
No alt text provided for this image

Output:

>java ComplexOperator
-1        

Example- 3

class ComplexOperator{
	public static void main(String[] args){
		int num = 5,  a = 10;
		//System.out.println(++num - ++num);
		System.out.println((--a + --a) * (++a - a--) + (--a + a--) * (++a + a++));
	}
}        
No alt text provided for this image

Output

>java ComplexOperator
196        
No alt text provided for this image


class BooleanOperator{
	public static void main(String[] args){
		boolean firstDecesion = true;
		boolean secondDecesion = false;
		System.out.println(firstDecesion && secondDecesion);
		System.out.println(firstDecesion && firstDecesion);
		System.out.println(secondDecesion && firstDecesion);
		System.out.println(secondDecesion && secondDecesion);
		
		
		System.out.println(firstDecesion || secondDecesion);
		System.out.println(firstDecesion || firstDecesion);
		System.out.println(secondDecesion || firstDecesion);
		System.out.println(secondDecesion || secondDecesion);
		
		
		System.out.println(firstDecesion ^ secondDecesion);
		System.out.println(firstDecesion ^ firstDecesion);
		System.out.println(secondDecesion ^ firstDecesion);
		System.out.println(secondDecesion ^ secondDecesion);
		
		
	}
	
}        

Output

>java BooleanOperator
false
true
false
false
true
true
true
false
true
false
true
false        

  • Bitwise Operation

class BitwiseOperation{
	public static void main(String[] args){
		//create variable
		int firstNum =10;
		int secondNum = 2;
		//Bitwise operation using Bitwise operator
		System.out.println("The bitwise AND is: " + (firstNum & secondNum));
		System.out.println("The bitwise OR is: " + (firstNum | secondNum));
		System.out.println("The bitwise XOR is: " + (firstNum ^ secondNum));
		//left and right shift operations
		System.out.println("The bitwise Left Shift is: " + (firstNum << secondNum));
		System.out.println("The bitwise Right Shift is: " + (firstNum >> secondNum));
	}
}        


  • Output

>java BitwiseOperation
The bitwise AND is: 2
The bitwise OR is: 10
The bitwise XOR is: 8
The bitwise Left Shift is: 40
The bitwise Right Shift is: 2        

Comparison of & vs &&

In case of Logical AND operator && , if the first operand value is false then it is not required to check the second operand value, directly, we can predict the result of overall expression will be false.

In case of Bitwise AND operator & , even first operand value is false, still, JVM evaluates second operand value then only JVM will the overall result of the expression as false. So here evaluating second operand value is unnecessary, at the same time it also increases execution time which reduces the application performance.

Note: If the first operand value is true than it is manadatory for JVM to evaluate the second operand value, In order to get overall expression result.

Based on the number of operands involved with an Operator, It can be classified as :

  1. Unary Operator ( performs operation on only one operand)
  2. Binary Operator ( performs operation on two operands)
  3. Ternary Operator ( performs operation on three operands)

That's all for this article guys, will meet again with new concept of Java till then bye bye !! Be healthy keep coding....

要查看或添加评论,请登录

Praveen Kumar的更多文章

  • Differences between Abstraction & Encapsulation in Java

    Differences between Abstraction & Encapsulation in Java

    Understanding the concepts of abstraction and encapsulation is crucial for any Java developer. However, these concepts…

  • Unlocking Backend Brilliance: A Journey into NestJS for Creating RESTful API

    Unlocking Backend Brilliance: A Journey into NestJS for Creating RESTful API

    If you're just starting out on your journey in backend development, you're in for a treat. NestJS is not your average…

  • All About Rate Limiter

    All About Rate Limiter

    What is Rate Limiter? A rate limiter is a system component that restricts the rate at which requests are made to a…

  • How to integrate ChatGPT in your web application

    How to integrate ChatGPT in your web application

    So, let's talk about trending #chatgpt . I will try to tell everything about ChatGPT & it's capabilities.

  • Number System in Java | Article - 4

    Number System in Java | Article - 4

    Hi, guys so in previous article of our Java Series we saw language fundamentals of Java. If you are new to this article…

  • REST API using Express & MongoDB

    REST API using Express & MongoDB

    Getting Started The only thing we need to get started with this project is a blank folder with npm package initialized.…

  • Java Language Fundamentals

    Java Language Fundamentals

    Hi guys, here comes the third article in the series of Java articles series. In this article basically we will be…

  • Naming Conventions in Java

    Naming Conventions in Java

    Java Article Series - 2 So In continuation of the previous article on Java, today we will be going through Java naming…

  • Introduction to Java

    Introduction to Java

    Java Series Article - 1 Hi guys here I am introducing java article series in which I will try to cover the things I…

  • Basics of Web Pages

    Basics of Web Pages

    HTML, defines the content of every web page on the internet. By "marking up" our raw content with HTML tags, we are…

社区洞察

其他会员也浏览了