Java Tutorial

by Dinesh Thakur Category: Operators and Expressions

The conversion of a data type which is carried out automatically by the compiler without programmer intervention is called the implicit type conversion. When two variables of different data types are involved in the same expression, the Java compiler uses built-in library functions to trans- form the variables to common data type before evaluating the expression. To decide which variable's data type is to be converted, the Java compiler follows certain rules and converts the lower data type to that of a higher data type. This is known as widening a type.



 
by Dinesh Thakur Category: Operators and Expressions

The bitwise complement operator (~), which perform a bitwise negation of an integer value. Bitwise negation means that each bit in the number is toggled. In other words, all the binary 0s become 1s and all the binary 1s become 0s.

 
by Dinesh Thakur Category: Operators and Expressions

The assignment operator (=) is the most commonly used binary operator in Java. It evaluates the operand on the tight hand side and then assigns the resulting value to a variable on the left hand side. The right operand can be a variable, constant, function call or expression. The type of right operand must be type compatible with the left operand. The general form of representing assignment operator is

 
by Dinesh Thakur Category: Operators and Expressions

Relational operators also known as comparison operators are used to check the relation between two operands. In other words, the operators used to make comparisons between two operands are called relational operators. Relational operators are binary operators and hence require two operands. The result of a relational operation is a Boolean value that can only be true or false according to the result of the comparison.

 
by Dinesh Thakur Category: Operators and Expressions

In addition to the implicit type conversion, Java also provides the facility of explicit type conversion within an expression. In implicit type conversion, a value of lower data type is converted to a value of higher data type. This results in no loss of information. However, if you try to convert a value of higher data type to that of lower data type then java compiler generates an error message "possible loss of precision". For example:



 
by Dinesh Thakur Category: Operators and Expressions

Java has two very useful operators. They are increment (++) and decrement (- -) operators. The increment operator (++) add 1 to the operator value contained in the variable. The decrement operator (- -) subtract from the value contained in the variable.

 
by Dinesh Thakur Category: Operators and Expressions

The Arithmetic operators are used to perform arithmetic operations. The Arithmetic operators are binary operators that work with integers, floating point numbers and even characters (i.e. they can be used with any primitive type except the boolean).

 
by Dinesh Thakur Category: Operators and Expressions

Java provides an extensive bit manipulation operator for programmers who want to communicate directly with the hardware. These operators are used for testing, setting or shifting individual bits in a value. In order to work with these operators, one should be aware of the binary numbers and two's complement format used to represent negative integers.

 
by Dinesh Thakur Category: Operators and Expressions

The bitwise AND, OR, and XOR operators (&, |,and /\) all act on the individual bits of an integer. These operators are useful when an integer is being used as a bit field.

 
by Dinesh Thakur Category: Operators and Expressions

This Java break statement with label example shows how to use java break statement to terminate the labeled loop.



 
by Dinesh Thakur Category: Operators and Expressions

Most of the computer languages typically support advanced math operations (such as square root, trigonometric sine, cosine etc.) by way of function libraries. Java also provides a range of methods that support such functions in the standard libraries Math class stored in the package java.lang. Java's Math class contains a collection of methods and two constants that compute standard mathematical functions.



 
by Dinesh Thakur Category: Operators and Expressions

Arithmetic operators are used to perform arithmetic calculations. Java provides basic arithmetic operators. They are +,-, *, /, %. The different Arithmetic operators that were used in java programming.



 
by Dinesh Thakur Category: Operators and Expressions

Besides the assignment operator in Java has combined operators assignment. They contribute to reducing the amount of code as impracticable two operations by an operator. The combined operators have the following syntax:

 
by Dinesh Thakur Category: Operators and Expressions

Like the break statement, the continue statement also skips the remaining statements of the body of the loop where it is defined but instead of terminating the loop, the control is transferred to the beginning of the loop for next iteration. The loop continues until the test condition of the loop becomes false.

 
by Dinesh Thakur Category: Operators and Expressions

This Java continue statement with label example shows how to use java continue statement to skip to next iteration of the labeled loop.



 
by Dinesh Thakur Category: Operators and Expressions

Here is the Java Example for Area of Triangle

 
by Dinesh Thakur Category: Operators and Expressions

The break statement terminates the execution of the loop in which it is defined and the control is transferred immediately to the next executable statement after the loop. The break statement is normally used with either while, do-while, for or a switch statement. It is mostly used to exit early from the loop by skipping the remaining statements of loop or switch control structures.

 
by Dinesh Thakur Category: Operators and Expressions

In this example we reviewed six comparison operator <, <=,>,> =, == And ! =. Comparison operators always produce a boolean result value (true or false). Java has several comparison operator, which can be used for the comparison of any combination of integers, with float or symbols.

 
by Dinesh Thakur Category: Operators and Expressions

This Java break statement example shows how to use java break statement to terminate the loop. The Java break statement has two forms labeled and unlabeled. in the below example You can see unlabeled form.



 
by Dinesh Thakur Category: Control Structures

Different types of control statements: the decision making statements (if-then, if-then-else and switch), looping statements (while, do-while and for) and branching statements (break, continue and return).

 

Page 6 of 40



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.