Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

Keywords, Relational and Boolean Operators
Previous Home Next

Keywords are predefined identifiers reserved by Java for a specific purpose and are used only in a limited, specified manner. Java has a richer set of keywords than C or C++. The following keywords are reserved for Java:

abstractdoubleintsuper
booleanelseinterfaceswitch
breakextendlongsynchronized
bytefalsenativethis
byvaluefinalnewthreadsafe
casefinallynullthrow
catchfloatpackagetransient
charforprivatetrue
classgotoprotectedtry
constifpublicvoid
continueimplementsreturnwhile
defaultimportshort

Relational and Boolean Operators

Java has the full complement of relational operators. For testing the equality you use a double equal sign ==. For example, the value of 5 == 6, is false.

We use a != for inequality. For e.g. the value of the following evaluates to true 3 != 7 is true.

Next we have have the <(less than), > (greater than), <= (less than or equal), and >=(greater than or equal) operators.

Java also uses && for the logical AND operator and || for the logical OR operator. As you can easily remember from the != operator, the exclamation point ! is the logical negation operator. The && and || operators are evaluated in short circuit fashion. This means that when we have an expression like:

p && q

 

If the truth value of the expression p has been determined to false, the value for the expression q is not calculated. For example consider the following expression


int p=7;
int q=1;
if((p==6)&&(q==1))
{
p=p+1;
q=q-1;
}

In the above e.g. the first condition p==6 is evaluated to false, so second condition q==1 is never evaluated. Similarly, if p evaluates to true, then the value of p || q is automatically true, without evaluating q.

Java also supports the ternary ?: operator that is occasionally useful. The expression condition ? p : q evaluates to p if the condition is true, else it evaluates to q.

Example:


p > q ? p : q

The above expression gives the value p if p is greater than q or else it will give q.

Previous Home Next