** Java notes based on Operator and Expression and Statement **
Class:
=======
A class is a blueprint of an object that contains several data member and methods in a Java
program. It contains several objects that carries the behavior and characteristics of the
class. It is also termed as an object maker or an object factory.
Instance variable:
================
The variable that is declared under the class without static modifier is termed as Instance
variable or non-static variable. In each call of this type of variable a new copy is created
and for this reason multiple copies of this type of variable is used in the program.
Java Expression:
================
Java Expression is a combination of variables, constants, and operators arranged as per the
syntax of the language. Basically the Java expression ends with semicolon (;).
Example: X= a + 2;
Pure Expression:
================
In Pure Expression only one type of data values are used and multiple type of data is not
allowed. Example:
int a =10, b= 20;
int c = a + b;
Here the type of c should be declared as int type to specify it as Pure Expression.
Impure Expression:
==================
In Impure Expression multiple type of data values are used and the resultant type of data is
decided as per the high precedence of data types and data values.
Example:
int a =10; float b= 20.5f;
float c = a + b;
Here the type of c should be declared as float type to specify it as Impure Expression.
Impure Expression is also termed as Mixed Expression.
Class Variable:
=============
When we declare a variable with static modifier under the class then it is termed as Class
variable / Static variable. In Java program only one copy of that variable is used
throughout the class.
Null literal:
=============
When we declare a literal with \0 then it is termed as null literal in Java. The null is a
reserve word in Java not a keyword. It is basically used the default value of an object.
Compound Statement:
=====================
A Compound statement begins with a left curly brace and ends with a right curly brace. In
between, write any sequence of statements, one after another.
For example,
{
x = 1;
y = 0;
}
Compound statement contains two smaller statements. The statements are done one after
the other, from the beginning to the end.
Difference between = and = = operator:
=================================
=
It is an assignment operator
It is used to assign the value of any operand.
Example: X = 5;
==
It is a relational is equal operator.
It is used to compare the value of two operands.
Example:
if ( X = = 5)
{…...} //Body of if
Difference between & and && operator:
==================================
& It is Bitwise AND operator
&& It is Logical AND operator
& It is basically calculate product of each binary digit of two operands
&& It join multiple conditions and the overall condition is true if all the conditions
are true
Difference between | and || operator:
===============================
| It is Bitwise OR operator
|| It is Logical OR operator
| It is basically calculate OR operation of each binary digit of two operands
|| It join multiple conditions and the overall condition is true if all the conditions are
true or any one of the condition is true.
Special Operator:
==============
Java supports some special operators of interest such as instanceof operator and
member selection operator (.)
instanceof Operator:
=================
The instanceof is an object reference operator and returns true if the object on the
left-hand side is an instance of the class given on the right-hand side. This operator
allows us to determine whether the object belongs to a particular class or not.
Example: person instanceof Student
Is true if the object person belongs to the class Student; otherwise it is false.
Dot Operator:
===========
The dot operator (.) is used to access the instance variables and methods of class
objects.
Example: person1 . age // Reference to the variable age
person1 . exam ( ) // Reference to the method exam ( )
It is also used to access classes and sub-packages from a package.
Java API:
=========
Java Application Programming Interface (API) is a list of all classes that are part of the
Java development kit (JDK). It includes all Java packages, classes, and interfaces, along
with their methods, fields, and constructors. These prewritten classes provide a
tremendous amount of functionality to a programmer.
Infinite loop:
===========
Infinite loop is one kind of loop that is not finite in nature and the loop will execute
endlessly due to the loop condition or the step value is both improper or missing so the
loop condition always satisfied and for this reason it is executed repeatedly.
Example:
for (int i = 1; ; i++) // Missing loop condition
{…...} // Body of loop
for (int i = 1; i<=5 ; ) // Missing step value
{…...} // Body of loop
for (int i = 1; i>=1 ; i++) // Improper loop condition so condition is always true
{…...} //Body of loop
for (int i = 1; i<=1 ; i- -) // Improper step value so condition is always true
{…...} //Body of loop
for ( ; ; ) // Missing all three parts so condition is always true
{…...} //Body of loop
Significance of void keyword:
=========================
To indicate that the function does not return any value to the calling module.
The function just transfer the control to the calling module
Name the keyword to declare a constant: final
Name the data type that occupies 16 bits of memory space of numeric type: short
Name the data type that occupies 16 bits of memory space of non-numeric type: char
The default fractional data type: double
The range of byte data type: -128 to +127
The range of short data type: -32768 to +32767
Embedded Statement:
=================
The statement in which two assignment operator is used to assign the data value of the
variable and storing the resultant data that type of statement is termed as Embedded
Statement. Example:
int a = 10 , b = 30 ; // Here value is only assigned two int type variables named as ‘a’ & b’
a = a + b – ( b = a ) ; // It is an Embedded Statement
In the above statement the value of ‘a’ and ‘b’ is added first then the value of ‘b’ is
replaced by the value of ‘a’ then it is subtracted from the sum and finally the
resultant data value is assigned to the variable ‘a’.
It is actually performed the task of swapping the value of two variables using one
line statement.
Expression Statement:
=================
The statement that itself an expression in Java program is termed as Expression
Statement. Example:
Prefix expression statement: ++a ; or - - a ;
Postfix expression statement: a++ ; or a - - ;
Function calling statement: display ( ) ;