Java syntax - ClassName.class.method()

ClassName.class.method()
what that mean?
e.g.
String a = Animal.class.getName();
if u know, pls explain in details, that will be grateful, :-)

The ".class" notation is known as a class literal. It evaluates to the Class object for the class mentioned.
So Foo.class gives an instance of java.lang.Class that contains metadata about the class Foo. The ".method()" part is just invoking a method on that Class object (not a Foo object), just like invoking any other method. In this case, it invokes java.lang.Class' getName() method.

Similar Messages

  • How use XSD and Java? What classes/methods?

    I want to use an XSD instead of a DTD with my XML and Java. Does anyone know the classes/methods I should use to do this? Is it even possible? Can you send sample code?

    here is the helper function... hope it helps...
    import java.io.IOException;
    import java.math.*;
    import java.text.*;
    import org.xml.sax.Attributes;
    import org.xml.sax.ContentHandler;
    import org.xml.sax.ErrorHandler;
    import org.xml.sax.Locator;
    import org.xml.sax.SAXException;
    import org.xml.sax.SAXParseException;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.XMLReaderFactory;
    public class SAXParserDemo
         public SAXParserDemo()
         public void performDemo(String uri)
              System.out.println("Parsing XML file: " + uri + "\n\n");
              ContentHandler contentHandler = new MyContentHandler();
              ErrorHandler errorHandler = new MyErrorHandler();
              try
                   XMLReader parser = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
                   parser.setContentHandler(contentHandler);
                   parser.setErrorHandler(errorHandler);
                   parser.setFeature("http://xml.org/sax/features/validation", true);
                   parser.parse(uri);
              catch(IOException e)
                   System.out.println("Error reading URI: " + e);
              catch(SAXException e)
                   System.out.println("Error in parsing: " + e);
         public static void main(String[] args)
              if(args.length != 1)
                   System.out.println("Usage: java SAXParserDemo [XML URI]");
                   System.exit(0);
              String uri = args[0];
              SAXParserDemo parserDemo = new SAXParserDemo();
              parserDemo.performDemo(uri);
    class MyErrorHandler implements ErrorHandler
         public void warning(SAXParseException exception) throws SAXException
              throw new SAXException("Warning encountered."+exception);
         public void error(SAXParseException exception) throws SAXException
              throw new SAXException("Error encountered: "+exception);
         public void fatalError(SAXParseException exception) throws SAXException
              throw new SAXException("Fatal error encountered."+exception);
    class MyContentHandler implements ContentHandler
         private Locator locator;
         public void setDocumentLocator(Locator locator)
              //System.out.println("     * setDocumentLocator() called");
              this.locator = locator;
         public void startDocument() throws SAXException
              //System.out.println("System Message: Parsing begins...");
         public void endDocument() throws SAXException
              //System.out.println("System Message: ...Parsing ends.");
         public void processingInstruction(String target, String data) throws SAXException
              //System.out.println("System Message: PI: Target: "+target+" and Data: "+data);
         public void startPrefixMapping(String prefix, String uri)
              //System.out.println("System Message: Mapping starts on prefix "+prefix+" mapped to URI "+uri);
         public void endPrefixMapping(String prefix)
              //System.out.println("System Message: Mapping ends on prefix "+prefix);
         public void startElement(String namespaceURI, String localName, String rawName, Attributes atts) throws SAXException
              //System.out.println("System Message: startElement: "+localName);
              if(!namespaceURI.equals(""))
                   //System.out.println("System Message: in namespace "+namespaceURI+" ("+rawName+")");
              else
                   //System.out.println("System Message: has no associated namespace");
              int i;
              for(i=0;i<atts.getLength();i++)
                   //System.out.println("System Message: Attribute: "+atts.getLocalName(i)+"="+atts.getValue(i));
         public void endElement(String namespaceURI, String localName, String rawName) throws SAXException
              //System.out.println("System Message: endElement: "+localName+"\n");
         public void characters(char[] ch, int start, int length) throws SAXException
              String s = new String(ch, start, length);
              //System.out.println("System Message: characters: "+s);
         public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException
              String s = new String(ch, start, length);
              //System.out.println("System Message: ignorableWhitespace: ["+s+"]");
         public void skippedEntity(String name) throws SAXException
              //System.out.println("System Message: Skipping entity: "+name);
    }

  • An unseen java syntax: " className .this"

    As I studied the Java Tutorial, "How to use File Choosers", I found a strange Java expression in FileChooserDemo.java as listed below
    public class FileChooserDemo extends JFrame {
        public FileChooserDemo() {
            final JFileChooser fc = new JFileChooser();
                // In response to a button click:
                // int returnVal = fc.showOpenDialog(aComponent);
                int returnVal = fc.showOpenDialog(FileChooserDemo.this);
    }What's "FileChooserDemo.this" really mean?
    Remark: "FileChooserDemo.this" could not be substitued with "this", it caused a compilation error.

    Hi s_plyw,
    the syntax you have seen meens that showOpenDialog() get a referenz of the current instance of FileChooserDemo. You need this syntax for inner classes, to get a referenz of the class where the inner class is nested. If you only use 'this' you will get an instance of the inner class.
    public class A {
    public int val = 5;
    public A() {
    new B();
    private class B {
    public int val = 10;
    public B() {
    System.out.println("->" + A.this.val);
    System.out.println("->" + this.val);
    public static void main(String[] args) {
    new A();
    produce:
    ->5
    ->10
    Look at the langspec (can be downloaded from the sun sites) for the syntax. I think in 'thinking in java' are more examples.
    J�rgen

  • Php5 static class method access syntax error

    Dreamweaver is complaining about this syntax
    $class = 'ClassName';
    $class::method(); // static method
    Is there a way to omit these error warnings?

    Thanks for pointing out the reference to the change in PHP syntax.
    To the best of my knowledge, there is no way to turn off the syntax checking. You can turn off code hints, but that doesn't have any effect on the syntax checker.
    I suggest that you file a bug report to Adobe using the form at https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform. Include the reference to the syntax change with your report.

  • How to call inner class method in one java file from another java file?

    hello guyz, i m tryin to access an inner class method defined in one class from another class... i m posting the code too wit error. plz help me out.
    // test1.java
    public class test1
         public test1()
              test t = new test();
         public class test
              test()
              public int geti()
                   int i=10;
                   return i;
    // test2.java
    class test2
         public static void main(String[] args)
              test1 t1 = new test1();
              System.out.println(t1.t.i);
    i m getting error as
    test2.java:7: cannot resolve symbol
    symbol : variable t
    location: class test1
              System.out.println(t1.t.geti());
    ^

    There are various ways to define and use nested classes. Here is a common pattern. The inner class is private but implements an interface visible to the client. The enclosing class provides a factory method to create instances of the inner class.
    interface I {
        void method();
    class Outer {
        private String name;
        public Outer(String name) {
            this.name = name;
        public I createInner() {
            return new Inner();
        private class Inner implements I {
            public void method() {
                System.out.format("Enclosing object's name is %s%n", name);
    public class Demo {
        public static void main(String[] args) {
            Outer outer = new Outer("Otto");
            I junior = outer.createInner();
            junior.method();
    }

  • How to write javascript in java class method

    Hi,
    any one please resolved this,
    i want to write javascript window closing code into java class method, in that method i want to write javascript code & wanted to call in jsf page on commandButton action event,
    my code is below but it is not working properly
    public void closeWindowClicked(ActionEvent event) {
              try
         FacesContext facesContext = FacesContext.getCurrentInstance();
         String javaScriptText = "window.close();";
         // Add the Javascript to the rendered page's header for immediate execution
         AddResource addResource = AddResourceFactory.getInstance(facesContext);
         addResource.addInlineScriptAtPosition(facesContext, AddResource.HEADER_BEGIN, javaScriptText);
    catch(Exception e)
         System.out.println(""+e);
    for calling into jsf code is below
    <h:commandButton action="#{parentBean.closeWindowClicked}" value="OK" />
    /*Note- i want to closed the window by caling method contain javascript only, i don't want any ajax code in method */
    please any one can resolved this.
    Thanks

    /*Note- i want to closed the window by caling method contain javascript only, i
    don't want any ajax code in method */ When the user presses your button, do your business logic and then send them to a page containing the following (note: untested code ahead):
    <html>
    <head>
        function onLoadHandler()
            window.close();
    </head>
    <body onload="onLoadHandler();">
        <p>Window closing....</p>
    </body>
    </html>

  • How I build my own libraries of classes/methods in java ?

    How I build my own libraries of classes/methods in java ? how then I refer a functionX() (i mean method) in LibraryX ? can you give a short/brief example of a library with a class with a method and a main method of normal class calling this method (of external's added library's) ?

    Just another cross poster.
    [http://www.java-forums.org/new-java/12389-how-i-build-my-own-libraries-classes-methods-java.html]
    db
    edit And [http://forums.java.net/jive/thread.jspa?messageID=305387]
    Edited by: Darryl.Burke

  • Calling ABAP class methods from JAVA application

    Hi All,
    I want to fetch ITS related information (SITSPMON Tcode) in my JAVA application. But i didnt find much BAPIs for the same. While debugging I came accross few class methods with help of which I can get the required information. So is there any way we can call and execute methods of ABAP classes through java application?
    for e.g. I want to call GET_VERSION method of CL_ITSP_UTIL class.
    Thanks,
    Arati.

    Hi,
    Yes, as per my knowledge the only way to interact is using BAPI exposed as RFCs. So try to invoke those class methods in one CUSTOM BAPI and expose that BAPI as RFC and consume that RFC to get those details.
    Regards,
    Charan

  • Setting Control-Flow- Case on java class/method

    hello All :D
    i have little problem about control flow case, in my case i've 2 page where before load to the page i'wanna make condition (if-else)
    when the user choose the field, the java class get the value for make true condition. In this case, i wanna implement ControlFlowCase in java class/method, so anyone help..?
    thx
    agungdmt

    Have you considered using router activity - http://download.oracle.com/docs/cd/E17904_01/web.1111/b31974/taskflows_activities.htm#CJHFFGAF ?

  • Syntax Error in Test - Class Method

    Hello all,
    I've created a Class, and when I try to test one of the methods (from within SE24), I'm getting the following error:  "Syntax error in test.  Display generated test environment?" (When I say Yes, I'm taken to %_JJ_TESTFRAME_CLASS program)
    The strange thing is that the code passed the sytax check, and has been activated.   Additionally, there's no error logged in ST22. 
    Any ideas as to what might cause this?
    Thanks in advance,
    Lisa

    a@s,
    Thanks for the quick reply.  I do not have anything in either the Protected or Private sections.  Here's the definitions in my Public section:
    public section.
      types TYPE_V_CUST type STRING .
      types TYPE_V_ZIP type STRING .
      types TYPE_V_OFFICE type STRING .
      types TYPE_SHORT type STRING .
      types TYPE_LONG type STRING .
      types TYPE_BDCDATA type BDCDATA .
      types:
        type_table_bdcdata type TABLE OF type_bdcdata .
      types TYPE_V_STATUS_FOUND type STRING .
      types:
        begin of type_statab,
          city_state(30),                   " City/State
          store_location(20),               " Store # or Loc Name
          service_office(20),               " Office Name
          phoned_in_by(20),                 " Phoned/Reported by
          date_phoned_in(10),               " Date phoned in
          response_date(10),                " Response date
          notification type qmel-qmnum,     " Notification #
          po_number type viqmel-bstnk,      " PO number
          invoice_number(80),               " Invoice #
          invoice_amount type vbak-netwr,   " Inv Amt
          invoice_due_date type vbak-erdat, " Inv Due date
          aufnr type aufk-aufnr,            " Service Order #
          text_line type zlbbil_repairs-text_line1,
          END OF type_statab .
      types:
        type_table_statab type TABLE OF type_statab .
      class-data WA_BDCDATA type BDCDATA .
      class-data BDCDATA type TYPE_TABLE_BDCDATA .
      class-data WA_VIQMEL type VIQMEL .
      class-data WA_VBAK type VBAK .
      class-data WA_STATAB type TYPE_STATAB .
      class-data:
        statab TYPE TABLE OF type_statab .
      class-methods CREATE_NOTIF
        importing
          !V_ZIP type TYPE_V_ZIP
          !V_CUST type TYPE_V_CUST
          !V_OFFICE type TYPE_V_OFFICE
          !V_SHORT_TEXT type TYPE_SHORT
          !V_LONG_TEXT type TYPE_LONG
        exporting
          !V_NOTIF_FMT type BAPI2080_NOTHDRE-NOTIF_NO .
      class-methods FILL_BDC_DYNPRO
        importing
          !PROGRAM type BDCDATA-PROGRAM
          !DYNPRO type BDCDATA-DYNPRO .
      class-methods FILL_BDC_FIELD
        importing
          !FNAM type BDCDATA-FNAM
          !FVAL type BDCDATA-FVAL .
      class-methods EMAIL_NOTIF_OFF
        importing
          !V_NOTIF_FMT type BAPI2080_NOTHDRE-NOTIF_NO .
      class-methods EMAIL_NOTIF_CUST
        importing
          !V_NOTIF_FMT type BAPI2080_NOTHDRE-NOTIF_NO
          !V_EMAIL type STRING .
      class-methods GET_NOTIF_STATUS
        importing
          !V_NOTIF type BAPI2080_NOTHDRE-NOTIF_NO
        exporting
          !V_STATUS_FOUND type TYPE_V_STATUS_FOUND .
      class-methods GET_REPAIRS_DONE
        importing
          !WA_VIQMEL type VIQMEL
        changing
          !STATAB type TYPE_TABLE_STATAB
          !WA_STATAB type TYPE_STATAB .
    Anything jump out?

  • Essential PL/SQL , Java Classes/Methods for working on BLOB

    &#61623; Are there any methods/procedures with which we could work on a BLOB object which contains purely text?
    &#61623; Essential PL/SQL , Java Classes/Methods for working on BLOB:
    null

    &#61623; Are there any methods/procedures with which we could work on a BLOB object which contains purely text?
    &#61623; Essential PL/SQL , Java Classes/Methods for working on BLOB:
    null

  • Invoking remote java classes/methods

    Hi,
    I just wanted to ask for opinions and suggestions regarding my attempt to call a remote java class method using PL/SQL. I didn't want to load it in the database since the configurations for the java class were already set using Spring Integration. I just wanted to supply constructor arguments and run the method and then retrieve the result. Are there any good or easier ways on doing this?
    Thanks in advance

    Very curious Susan,
    A server JVM might not want to host mobile code from other clients, not that it's unsafe, it's just that it allows clients to crash the server JVM at will. They should have it configured to automatically restart though.
    Did they delete the java.rmi.* packages from the server JVM runtime? I don't understand why they'd do that.
    If you can pry some reasons from them, I'd be very interested to hear them. Perhaps they just want more money, in order to allow you this privilige.
    John
    PS I've updated representation for you, and ejp, on the cajo project supporting The Land Down Under!

  • New improvement for Java syntax

    Hi developers
    I develop in java each day and the new project that I am envolved uses too much multithreading. So i thought that a litle improvement could be made on java syntax.
    When two threads uses the same class attribute we must synchronize the access to this.
    class myClass {
    private int myAtribute = 0;
    thread1: We must access the attribute synchronized....
    shynchronized (this) {
    myAttribute = 1;
    thread2: The same....
    synchronized (this) {
    myAttribute = 3;
    thread2: But if i don't care.... :-(
    myAttribute = 4;
    Ok, that is the problem.
    I thought to solve this the java language must give us the chance to declare attributes in the way...
    private synchronize int myAttribute = 0;
    to be only accesed by sinchronized methods or by synchronized blocks in order to force interpreter to check if any method access this attribute without being synchronized in compiling time.

    In your example, wouldn't the volatile keyword normally suffice?
    private volatile int myAttribute = 0;Graeme

  • What is the exact mean of  classname.class.

    what is the exact mean of classname.class. what situations it will be use ful . how to use . give me one example .

    Each class, interface, or enum loaded into the JVM has an associated Class object. This contains a lot of information about the class in question, including lists of fields and methods. <classname>.class gives you a reference to the Class object of the class mentioned.
    See the java.lang.Class javadocs for all the things you can do with a Class object.
    For example:
    theImage = new ImageIcon(MainClass.class.getResource("item.png"));to retrieve an image file from the directory containing the MainClass class file.

  • Calling up class methods

    I suffer problems understanding how to call up class methods from within my programs and would like to see further examples of coding and a lending hand with the problem below, program one ProductClass works out stock item lines of a product, the program then needs to ask for the StaticProduct Class(the second program attached) to check for a valid barcode length and for how many odds and even numbers are within it a valid barcode would be 5000127062092
    I would very much appreciate some help:
    * This is a program to Enter and check product codes and prices
    * and give a summary of values at the end
    * @author (Jeffrey Jones)
    * @version (version 2 5th April 2003)
    public class ProcessProduct
    public static void main(String args[])
    StaticProduct Product = new StaticProduct();
    //declare variables
    String manuf;
    String name;
    int sLength;
    String p;
    String barcode;
    int price;
    int quantity;
    int totalPrice=0;
    int transactions=1;
    int totalQuantity=0;
    int totalValue=0;
    int averageCost=0;
    //Input Details
    System.out.print("Enter Product Manufacturer : ");
    manuf = UserInput.readString();
    //start of while loop checking for 0 to exit loop
    while (!manuf.equals("0"))
    System.out.print("Enter Product Name : ");
    name = UserInput.readString();
    System.out.print("Enter Bar Code : ");
    barcode = UserInput.readString();
    //check for invalid data
    if (StaticProduct.isValidBarcode(barcode))
    {barcode = new code();
                        p = new Product("manuf","name","quantity","price");
                        }//closing bracket of if
    else
    {//error handling
    }//closing bracket of if
    //check for quantity input and errors
    System.out.print("Enter Quantity : ");
    quantity = UserInput.readInt();
    if (quantity<=0)
    { System.out.print(" Error, invalid value ");
    System.exit(0);
    }// check for invalid entries
    System.out.print("Enter Price :");
    price = UserInput.readInt();
    //check for price input and errors
    if (price<=0)
    { System.out.print(" Error, invalid value ");
    }// check for invalid entries
    //total price value
    totalPrice=price*quantity;
    //Output of correctly inputted data
    System.out.println(manuf+":"+name+":"+barcode+":"+price);
    System.out.println(quantity+" @ "+price+" = "+totalPrice);
    //update variables quantities
    //update total quantity
    totalQuantity = (totalQuantity + quantity);
    //keep count of total value
    totalValue = (totalValue + totalPrice);
    //keep count of totqal no of transactions
    transactions = (transactions++);
    //Input Details
    System.out.print("Enter Product Manufacturer : ");
    manuf = UserInput.readString();
    }//closure of loop
    //display final totals
    System.out.println("Transactions: "+transactions);
    System.out.println("Total quantity: "+totalQuantity);
    System.out.println("Total value: "+totalValue);
    System.out.println("Average Cost: "+totalValue/totalQuantity);
    System.exit(0);
    }//closing bracket input and output of data
    }//end class
    * Write a description of class StaticProduct here.
    * @author Jeffrey Jones
    * @version 1 1st April 2003
    public class StaticProduct
    * isValidBarcode method - to check for correct barcode and length
    * @return boolean
    public static boolean isValidBarcode(String barcode) {
    barcode = new barcode();
    // validateBarcode length
    if ( barcode.length() != 13 ) {
    System.out.println("Invalid barcode " + barcode + " not 13 characters");
    return false;
    }//if
    for ( int i = 0; i < barcode.length(); i++ ){// Check every char a digit
    if ( ! Character.isDigit( barcode.charAt(i) ) ){
    System.out.println("Invalid barcode " + barcode + " not all digits");
    return false;
    }//if
    }//endfor
    int sum1 = 0; // Sum first + third + etc.
    for ( int i = 0; i < barcode.length() - 1; i += 2 ){
    sum1 += barcode.charAt(i) - '0';
    }//endfor
    int sum2 = 0; // Sum second + fourth + etc.
    for ( int i = 1; i < barcode.length() - 1; i += 2 ){
    sum2 += barcode.charAt(i) - '0';
    }//endfor
    int check = sum1 + 3 * sum2; // 1st sum + three times 2nd sum.
    check = check % 10; // Remainder on division by 10.
    if ( check != 0 ){
    check = 10 - check;
    }//endif
    if (check != barcode.charAt(12) - '0'){
    System.out.println("Invalid barcode " + barcode + " check digit error");
    }//endif
    return ( check == barcode.charAt(12) - '0' );
    }//end isValidBarcode
    public static void main(String[] argv) {
    System.out.println(isValidBarcode("1234567890123"));
    System.out.println(isValidBarcode("123"));
    System.out.println(isValidBarcode(""));
    System.out.println(isValidBarcode("5018374496652"));
    }//end main
    }//end class

    Read through your text book or some java tutorials from this site to understand what classes are, what are methods, etc.
    Your program is full of wrong initializations (as you rightly said you dont understand how to call up class method I would add that you dont understand how to call classes and what do they return e.g.
    You have declared
    String p;
    then you go ahead and do this
    p = new Product("manuf","name","quantity","price"); This is syntax for calling a class is this class returning a String? :s
    Please go through the basics of Object Oriented Programming and then start with the coding part else you will face such very many difficulties and waste more time of yours in just coding with no results.
    Look for the tutorials on this site and read through them and do example as given in them.

Maybe you are looking for