Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Java Jdk7 Other Operators in java 7

Related Tutorials


 
 

Share on Google+Share on Google+

Other Operators in java 7

Advertisement
In this section you will learn about the Other Operators. This is one type of operators.

Other Operators in java 7

In this section you will learn about the Other Operators. This is one type of operators.

Conditional Operator (? :):

This is also called ternary operator. It contains three operand and two operators. ? and : combined used for ternary operator. It works like if-else statement so you can say ternary operator is short form of if-else statement. So it checks the condition and if it is true then process first expression otherwise process another expression.

Syntax :

boolean Expression ? expression1 : expression2;

Example :

In this example we are using ternary operator to print the highest number in x and y.

package operator;

class ConditionalOperator {
	public static void main(String[] args) {
		int x = 10;
		int y = 20;
		int z;
		z = (x > y ? x : y); //Conditional Operator
		System.out.println("Highest number in x and y : " + z);
	}
}

Output :

Highest number in x and y : 20

Instance operators :
It is another kind of operator used to compare the object to the given type. It is used to test if an object is an instance of a class, an instance of a subclass, or an instance of a class that implements a particular interface

package operator;

class InstanceOfOperator {
	public static void main(String[] args) {
		ArithmaticOperator operator = new ArithmaticOperator();
		boolean result = operator instanceof ArithmaticOperator;
		System.out.println("Instance Operator : " + result);
	}
}

Output :

Instance Operator : true
Advertisement

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 21, 2012

Related Tutorials

Discuss: Other Operators in java 7  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com