Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
The instance of keyword 
 

The keyword instanceOf in java programming language is a boolean operator that is used to test whether an object is of an specified type or not and returns the value accordingly.

 

The instance of keyword

                         

The keyword instanceOf in java programming language is a boolean operator that is used to test whether an object is of an specified type or not and returns the value accordingly. Keywords are basically reserved words which have specific meaning relevant to a compiler. It takes an object reference as its first reference and a class or interface as its second operand and produces a result true or false based on the condition. It also lets the developer to create their own type classes having runtime behavior specified by the developer. aMoneyType, aDateType, aCheckingAccountID, etc are some to the examples of the such type of classes. 

Syntax: Here is the syntax for using an instanceOf keyword

if (node instanceof TreeNode){

/ write your code here

}

Where, condition (node instanceOf  TreeNode) returns true if the class node is an instance or is an instance of a subclass of TreeNode.

Example: Here is the example how the instanceOf operator is used.

public class MainClass {
  public static void main(String[] a) {
    String s = "Hello";
    if (s instanceof java.lang.String) { 
      System.out.println("is a String");
    }
  }
}

It returns the output "is a String" after checking the condition because the condition returns true.

Note: Here are some points which must be noted.

  • While applying the instanceOf operator on a null reference then it returns false.

                         

» View all related tutorials
Related Tags:

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.