Do the Interface contains static components like static methods and attribu

Do the Interface contains static components like static methods and attributes ?

>
You have to supply a bit more detail: is that Lotus
Notes API a Java API?Hmm, It's Java interface to Lotus Notes API
Does it use JNI? Perhaps it is used somewhere underneath, I do not know for sure, but I think so
Possibly the Lotus Notes
implementation keeps a
reference to those arrays, who knows?
Maybe, but I'd be really suprised if it did. I derive this thread from Lotus Notes class and provide my own "worker method", overriding Lotus API abstract one, where I reference arrays. Arrays are specific to my program and since they are private fields in thread's class Lotus Notes layer does not have any way of referencing them, nor any reason for this matter
For starters: if you zero out (set to null) your
references to those arrays
in your threads when the threads finish, there might
surface a useful
indication that you can blame Lotus Notes for this
Well, I've become deeply suspect of whether these Notes' threads do really finish :-) My method finishes for sure, but it is just a part of run() method of Lotus Notes thread. Anyway, you can always safely blame Lotus Notes for almost anything :-)

Similar Messages

  • Implementing interface with static method?

    Hi,
    I need to implement an interface with a static method. I tried to do it both with the interface method static and non-static, but it don't seam to work! Does it work?
    How can I make a work around?
    Thanks!

    Interfaces are designed to provide a contract that a particular object instance guarantees for it's Clients.
    Since a static method does not relate to any particular object instance there is no contract to define...hence you can't have an interface for static methods...
    What you could do however is return an object via a static method that does provide the implementation of the interface...
    i.e.public class MyClass
        static private String myInterfaceImpl = "<some class>";
        static public MyInterface getInterface ()
             return (MyInterface) MyClass.class.forName (MyClass.myInterfaceImpl).newInstance ();
    }That would return an object that provides the interface. I would presume you need the static method so that you don't have to pass around references to a particular object...this method gets around that...you could also create a single object at start up time and return a reference to that eveytime...
    Also, in a way static methods do define an interface...

  • The purpose of static methods ....?

    In lay mans terms can anyone tell me WHY we have static methods ?

    In lay mans terms can anyone tell me WHY we have
    static methods ?Static methods become class level methods and are no longer confined within the objects of the class.
    Static methods typically provide information about the class as a whole, such as the number of created objects etcetera. Another use is as an object factory. Instead of doing new all over the program you have a static create method you call to get new objects of the class.

  • What is the purpose of Static methods inside a class?

    Hi,
    What is the purpose of Static methods inside a class?
    I want the answers apart from "A static method does not require instance of class(to access) and it can directly be accessed by the class name itself"
    My question is what is the exact purpose of a static method ?
    Unlike attributes, a separate copy of instance attributes will be created for each instance of a class where as only one copy of static attributes will be created for all instances.
    Will a separate copy of instance method be created for each instance of a class and only one copy of static methods be create?
    Points will be rewarded for all helpful answers.

    Hi Sharma,
    Static methods is used to access statics attributes of a class. We use static attributes when we want to share the same attribute with all instances of a class, in this case if you chage this attribute through the instance A this change will change will be reflected in instance B, C........etc.
    I think that your question is correct -> a separate copy of instance method will be created for each instance of a class and only one copy of static methods be create ?
    "A static method does not require instance of class(to access) and it can directly be accessed by the class name itself"
    Static Method: call method class=>method.
    Instance Method: call method instance->method.
    Take a look at this wiki pages.
    [https://wiki.sdn.sap.com/wiki/x/o5k]
    [https://wiki.sdn.sap.com/wiki/x/ZtM]
    Best regards.
    Marcelo Ramos

  • HT1449 This was somewhat informative, but what happens after you receive the  "The folder containing "iTunes Library" cannot be found, and is required. Please choose or create a new iTunes library,"? I ran through all the steps, received this message. Now

    tried to move my itunes library to an external to free up space and run itunes off of an external. Went through all the steps. Received the message "The folder containing "iTunes Library" cannot be found, and is required. Please choose or create a new iTunes library," like it mentioned I might, and here is where the instructions end. Now what?

    tried to move my itunes library to an external to free up space and run itunes off of an external. Went through all the steps. Received the message "The folder containing "iTunes Library" cannot be found, and is required. Please choose or create a new iTunes library," like it mentioned I might, and here is where the instructions end. Now what?

  • How find the missing glyph using javascript [like indesign preflight], and replace same glyph available font or

    The situation:
    I want to use basetext font, but some of the glyphs are missing in it, and are highlighted with pink boxes. common font [stix, etc.] have much more glyphs than basetext font. I can apply common font [stix, etc.]manually for each of the missing glyphs or insert two character and use kerning set it up, but it is tedious.
    Question:
    How find the missing glyph using javascript [like indesign preflight], and replace same glyph available font or insert two character and use kerning set it up?
    Any one know how to do this?
    Thanks in Advance,
    ~Jack

    Try Peter kehrl's script
    http://www.kahrel.plus.com/indesign/missing_glyphs.jsx

  • Interface with static methods

    I'm writting a wrapper for exception handling.One of the classes uses log4j to log exceptions.I want to write a interface to generalize loggin.Idealy I should have an interface with certain static methods for loging (i.e logError,logDebugMessage,consoleError,consoleMessage,etc) , but Interface dosent allow that and neither do abstract classes can havstatic method declarations.The implementations of these methods will achieve the hiding of the complexity of using a logging package,log levels etc from the user.
    Let me know how best I can work something out for this.
    Thanks in advance

    Define them once (as final) in an abstract class. Then any subclass can call logError etc.
    Kind regards,
      Levi

  • What 's the advantage of static method.

    I think if a method is declared as static, the program should allocate some spaces for the method when the program start. However, I found many static method in an erp open source project. What make me confused is that it will cost many spaces.
    Perhaps they want to lose some spaces for speed???
    Can somebody answer my question.thanks!

    > I think if a method is declared as static, the
    program should allocate some spaces for the method
    when the program start. However, I found many static
    method in an erp open source project. What make me
    confused is that it will cost many spaces.
    Perhaps they want to lose some spaces for speed???
    Can somebody answer my question.thanks!
    To be sincere, I've never thought about performance cost when static methods are used. I decide to create and use them mainly whether I have the "feeling" that it will provide me benefits, in terms of designing. Yes, it's like a feeling. I am not able to explain you why or how I have this feeling, I'm not native in English language, so choosing the appropriate words to explain my ideas sometimes is hard to me. Besides. I admit that I am a little bit lazy in this moment, I don't want to search through some dictionary...;-).
    I think the more you develop your abilities and skills in java programming, the more you can feel, you can have this "feeling", and naturally you figure out in which situations using static methods is a better choice.

  • How to get the class name  static method which exists in the parent class

    Hi,
    How to know the name of the class or reference to instance of the class with in the main/static method
    in the below example
    class AbstA
    public static void main(String[] args)
    System.out.println(getXXClass().getName());
    public class A extends AbstA
    public class B extends AbstA
    on compile all the class and run of
    java A
    should print A as the name
    java B
    should print B as the name
    Are there any suggestions to know the class name in the static method, which is in the parent class.
    Regards,
    Raja Nagendra Kumar

    Well, there's a hack you can use, but if you think you need it,Could you let me the hack solution for this..
    you probably have a design flaw and/or a misunderstanding about how to use Java.)May be, but my needs seems to be very genuine..of not repeat the main method contents in every inherited class..
    The need we have is this
    I have the test cases inheriting from common base class.
    When the main method of the test class is run, it is supposed to find all other test cases, which belong to same package and subpackages and create a entire suite and run the entire suite.
    In the above need of the logic we wrote in the main method could handle any class provided it knows what is the child class from which this main is called.
    I applicate your inputs on a better way to design without replicating the code..
    In my view getClass() should have been static as the instance it returns is one for all its instances of that class.
    I know there are complications the way compiler handles static vars and methods.. May be there is a need for OO principals to advance..
    Regards,
    Raja Nagendra Kumar
    Edited by: rajanag on Jul 26, 2009 6:03 PM

  • Static method and exception

    I have file which is reading from file and deleting it.
    delete is done by static method.
    now i need to do like this if file is empty it should throw exception and delte the file.
    so i added else like this
    else{
    throw new empty("Empty");
    but it is only thorowing exception not deleting file.as that static code is unreachable after throwing exception.
    any idea

    Hi zodok now this is original file just go through else statement in bold
    containing boolean a=deleteFile(fileName);
    package com.dhl.auditdatamgr.utils;
    import java.io.BufferedInputStream;
    import java.io.BufferedReader;
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileNotFoundException;
    import java.io.FileReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.text.ParseException;
    import java.util.ArrayList;
    import java.util.List;
    import java.util.StringTokenizer;
    import java.util.regex.Pattern;
    import com.dhl.auditdatamgr.business.DetailedFacilityAuditData;
    import com.dhl.auditdatamgr.exceptions.FileFormatException;
    import com.dhl.auditdatamgr.exceptions.SystemException;
    import com.dhl.auditdatamgr.exceptions.EmptyFileException;
    import com.dhl.auditdatamgr.utils.db.DataUtil;
    * @author mahiseth
    public class AuditFileParser
          * Constructor
         protected AuditFileParser()
              super();
         public static List parseFile(String fileName, String regex)
              throws IllegalArgumentException, FileNotFoundException, FileFormatException,SystemException, EmptyFileException
              DataUtil.enforceNotNullOrEmpty(fileName);
              DataUtil.enforceNotNullOrEmpty(regex);
              List rowList = new ArrayList();
              BufferedReader br = null;
              try
                   br = new BufferedReader(
                                                 new FileReader(new File(fileName)));
                   String line = null;
                   DetailedFacilityAuditData detailedAuditData = null;
                   Integer huExpected = null;
                   Integer huMissing = null;
                   Integer huExtra = null;
                   Integer shipmentExpected = null;
                   Integer shipmentMissing = null;
                   Integer shipmentExtra = null;
                   Integer pieceIdsExpected = null;
                   Integer pieceIdsMissing = null;
                   Integer pieceIdsExtra = null;
                   Pattern p = Pattern.compile(regex);
                   //while((line = br.readLine()) != null)
                   if ((line = br.readLine()) != null){
                        //System.out.println("Line: " + line);
                        //Pattern p = Pattern.compile("[\\p{Punct}&&[|]]");
                        String [] lineItems = p.split(line.trim());
                        if (lineItems.length != 18){
                                                 System.out.println("line = >>" + line + "<<");
                                                    System.out.println("lineItems.length = " + lineItems.length);
                                                    System.out.println("lineItems = " + java.util.Arrays.asList(lineItems));
                        detailedAuditData = new DetailedFacilityAuditData();
                        DataUtil.enforceNotNullOrEmpty(lineItems[0]);     
                        DataUtil.enforceNotNullOrEmpty(lineItems[5]);
                        DataUtil.enforceNotNullOrEmpty(lineItems[6]);     
                        DataUtil.enforceNotNullOrEmpty(lineItems[3]);          
                        detailedAuditData.setHuid(lineItems[0]);
                        detailedAuditData.setAuditAtServiceArea(lineItems[5]);
                        detailedAuditData.setAuditAtFacility(lineItems[6]);
                        detailedAuditData.setAuditTime(DataUtil.convertToTimestamp(lineItems[3]));
                        detailedAuditData.setHuType(lineItems[4]);
                        detailedAuditData.setBuiltAtServiceArea(lineItems[1]);
                        detailedAuditData.setBuiltAtFacility(lineItems[2]);
                        if(lineItems[9] != null && !lineItems[9].equals(""))
                             huExpected = new Integer(Integer.parseInt(lineItems[9]));
                             detailedAuditData.setHuExpected(huExpected);
                        if(lineItems[12] != null && !lineItems[12].equals(""))
                             huMissing = new Integer(Integer.parseInt(lineItems[12]));
                             detailedAuditData.setHuMissing(huMissing);
                        if(lineItems[13] != null && !lineItems[13].equals(""))
                             huExtra = new Integer(Integer.parseInt(lineItems[13]));
                             detailedAuditData.setHuExtra(huExtra);
                        if(lineItems[7] != null && !lineItems[7].equals(""))
                             System.out.println("Shipment expected is: " + lineItems[7]);
                             shipmentExpected = new Integer(Integer.parseInt(lineItems[7]));
                             detailedAuditData.setShipmentExpected(shipmentExpected);
                        if(lineItems[10] != null && !lineItems[10].equals(""))
                             shipmentMissing = new Integer(Integer.parseInt(lineItems[10]));
                             detailedAuditData.setShipmentMissing(shipmentMissing);
                        if(lineItems[11] != null && !lineItems[11].equals(""))
                             shipmentExtra = new Integer(Integer.parseInt(lineItems[11]));
                             detailedAuditData.setShipmentExtra(shipmentExtra);
                        if(lineItems[8] != null && !lineItems[8].equals(""))
                             pieceIdsExpected = new Integer(Integer.parseInt(lineItems[8]));
                             detailedAuditData.setPieceIdsExpected(pieceIdsExpected);
                        if(lineItems[14] != null && !lineItems[14].equals(""))
                             pieceIdsMissing = new Integer(Integer.parseInt(lineItems[14]));
                             detailedAuditData.setPieceIdsMissing(pieceIdsMissing);
                        if(lineItems[15] != null && !lineItems[15].equals(""))
                             pieceIdsExtra = new Integer(Integer.parseInt(lineItems[15]));
                             detailedAuditData.setPieceIdsExtra(pieceIdsExtra);
                        detailedAuditData.setAuditor(lineItems[16]);
                        detailedAuditData.setAuditDate(DataUtil.convertToDate(lineItems[17]));
                        rowList.add(detailedAuditData);
              } else{
                   System.out.println("file");
                   boolean a=deleteFile(fileName);
                   System.out.println(a);
                   throw new EmptyFileException("File is Empty");
              catch (IOException e)
                   throw new SystemException("An error occurred while trying to read the audit data file. " ,e);
                   //e.printStackTrace();
              } catch (ParseException e)
                   throw new FileFormatException("An error occurred while parsing the audit data file. " ,e);
                   //e.printStackTrace();
              catch (ArrayIndexOutOfBoundsException ae)
                   throw new FileFormatException("A required field is missing. " ,ae);
              finally
                    try
                        br.close();
                   } catch (IOException e1)
                        e1.printStackTrace();
              return rowList;
          * @param fileName - File name or directory to be deleted
          * @return true if and only if the file is successfully deleted, false otherwise
          * @throws IllegalArgumentException
         public static boolean deleteFile(String fileName)
              throws IllegalArgumentException
              DataUtil.enforceNotNullOrEmpty(fileName);
              File f = new File(fileName);
              boolean deleteStatus = false;
              deleteStatus = f.delete();
              return deleteStatus;
    }

  • Static method and variables doubts

    i have a doubt
    i have the following method
    private static void checkActionType(String action) {
    if (action.startsWith(" a")) {
    ++totalAddedActions;
    } else if (action.startsWith(" c")) {
    ++totalChangedFolders;
    } else if (action.startsWith(" p")) {
    ++totalPersonalizedActions;
    } else if (action.startsWith(" r")) {
    ++totalRemovedActions;
    } else if (action.startsWith(" v")) {
    ++totalViewedActions;
    } else if (action.startsWith(" u")) {
    ++totalUpdateActions;
    to use it, i need to declare my int variables static, because im calling this method from another static method that is called by main method.
    but this can cause me problems ?
    if i have two instances of this class running, my statics int will show the right value?
    there is a better approach?

    Here is my class, i want some advices to know if i am doing right, because everything is a little new for me.
    My class, read a log file and based upon a regular expression, it can retrieve a general statistic or a personal statistic.
    package br.com.organox.aggregator;
    import java.io.BufferedReader;
    import java.io.FileReader;
    import java.io.IOException;
    import java.util.Vector;
    import org.apache.oro.text.regex.*;
    public class LogFileReader {
    private static Pattern regexpPattern;
    private static PatternMatcher patternMatcher;
    private static PatternCompiler patternCompiler;
    private static PatternMatcherInput patternInput;
    private static MatchResult matchResult;
    private static final String patternString = "^[^\']+User\\s+\'([^\']+)\'[^\']+session\\s+\'([^\']+)\'\\s+(\\S+)";
    // Integers used to store number of user, sessions and specific actions
    private static int totalUsers;
    private static int totalSessions;
    private static int totalAddedActions;
    private static int totalChangedFolders;
    private static int totalPersonalizedActions;
    private static int totalRemovedActions;
    private static int totalUpdateActions;
    private static int totalViewedActions;
    public static void main(String[] args) {
    if (args.length == 0) {
    System.out.println("No file name was specified");
    printClassUsage();
    } else if (args.length == 1) {
    printGeneralData(args[0]);
    } else if (args.length == 2) {
    System.out.println("You must set file name, data value and data type in order to " +
    "this class run properly");
    printClassUsage();
    } else {
    printSelectedData(args[0],args[1],args[2]);
    public static void printGeneralData(String fileName) {
    String data = "";
    //Users and the Session Vector are used to avoid count repeated values.
    Vector usersVector = new Vector();
    Vector sessionVector = new Vector();
    patternCompiler = new Perl5Compiler();
    patternMatcher = new Perl5Matcher();
    try {
    regexpPattern = patternCompiler.compile(patternString);
    } catch (MalformedPatternException mpe) {
    System.out.println("Error Compiling Pattern");
    System.out.println(mpe.getMessage());
    try {
    FileReader fileRead = new FileReader(fileName);
    BufferedReader buffRead = new BufferedReader(fileRead);
    while ((data = buffRead.readLine())!= null) {
    patternInput = new PatternMatcherInput(data);
    while(patternMatcher.contains(patternInput,regexpPattern)) {
    matchResult = patternMatcher.getMatch();
    // Avoid to insert repeated data in user and session Vectors
    if (usersVector.lastIndexOf(matchResult.group(1)) == -1) {
    usersVector.add(matchResult.group(1));
    if (sessionVector.lastIndexOf(matchResult.group(2)) == -1) {
    sessionVector.add(matchResult.group(2));
    increaseActionType(matchResult.group(3));
    for (int i=0;i<usersVector.size();i++) {
    totalUsers++;
    for (int i=0;i<sessionVector.size();i++) {
    totalSessions++;
    fileRead.close();
    buffRead.close();
    } catch (IOException ioe) {
    System.out.println("An I/O error occurred while getting log file data");
    ioe.printStackTrace();
    System.out.println("Users logged : " + totalUsers);
    System.out.println("Sessions opened : " + totalSessions);
    System.out.println("Added contents : " + totalAddedActions);
    System.out.println("Changed folders : " + totalChangedFolders);
    System.out.println("Personalized contents : " + totalPersonalizedActions);
    System.out.println("Removed contents : " + totalRemovedActions);
    System.out.println("Viewed Contents : " + totalViewedActions);
    System.out.println("Updated contents : " + totalUpdateActions);
    public static void printSelectedData(String fileName,String value,String valueType) {
    String data = "";
    String user = "";
    //Flag used to print the right result on screen
    String printFlag = "";
    Vector sessionVector = new Vector();
    Vector userVector = new Vector();
    Vector actionVector = new Vector();
    patternCompiler = new Perl5Compiler();
    patternMatcher = new Perl5Matcher();
    try {
    regexpPattern = patternCompiler.compile(patternString);
    } catch (MalformedPatternException mpe) {
    System.out.println("Error Compiling Pattern");
    System.out.println(mpe.getMessage());
    try {
    FileReader fileRead = new FileReader(fileName);
    BufferedReader buffRead = new BufferedReader(fileRead);
    while ((data = buffRead.readLine())!= null) {
    patternInput = new PatternMatcherInput(data);
    while(patternMatcher.contains(patternInput,regexpPattern)) {
    matchResult = patternMatcher.getMatch();
    if (valueType.equalsIgnoreCase("-user")) {
    printFlag = "userPrint";
    if ((matchResult.group(1).equalsIgnoreCase(value))) {
    userVector.add(matchResult.group(1));
    // avoid insert a repeated value inside session vector.
    if (sessionVector.lastIndexOf(matchResult.group(2)) == -1) {
    sessionVector.add(matchResult.group(2));
    increaseActionType(matchResult.group(3));
    if (userVector.size() == 0) {
    printFlag = "userPrintError";
    } else if (valueType.equalsIgnoreCase("-session")) {
    printFlag = "sessionPrint";
    if ((matchResult.group(2).equalsIgnoreCase(value))) {
    user = matchResult.group(1);
    sessionVector.add(matchResult.group(2));
    increaseActionType(matchResult.group(3));
    if (sessionVector.size() == 0) {
    printFlag = "sessionPrintError";
    } else if (valueType.equalsIgnoreCase("-action")) {
    printFlag = "actionPrint";
    if ((matchResult.group(3).equalsIgnoreCase(value))) {
    if (userVector.lastIndexOf(matchResult.group(1)) == -1) {
    userVector.add(matchResult.group(1));
    actionVector.add(matchResult.group(3));
    if (actionVector.size() == 0) {
    printFlag = "actionPrintError";
    fileRead.close();
    buffRead.close();
    } catch (IOException ioe) {
    System.out.println("An I/O error occurred while getting log file data");
    ioe.printStackTrace();
    if (printFlag.equals("userPrint")) {
    for (int i=0;i<sessionVector.size();i++) {
    totalSessions++;
    System.out.println("Sessions opened by user " + value + " : " + totalSessions);
    System.out.println("Added contents by user " + value + " : " + totalAddedActions);
    System.out.println("Changed folders by user " + value + " : " + totalChangedFolders);
    System.out.println("Personalized contents by user " + value + " : " + totalPersonalizedActions);
    System.out.println("Removed contents by user " + value + " : " + totalRemovedActions);
    System.out.println("Viewed contents by user " + value + " : " + totalViewedActions);
    System.out.println("Updated contents by user " + value + " : " + totalUpdateActions);
    } else if (printFlag.equals("userPrintError")) {
    System.out.println("This user " + value + " was not found on log file");
    } else if (printFlag.equals("sessionPrint")){
    System.out.println("Session " + value + " was opened by user " + user);
    System.out.println("Added contents by session " + value + " : " + totalAddedActions);
    System.out.println("Changed folders by session " + value + " : " + totalChangedFolders);
    System.out.println("Personalized contents by session " + value + " : " + totalPersonalizedActions);
    System.out.println("Removed contents by session " + value + " : " + totalRemovedActions);
    System.out.println("Viewed Contents by session " + value + " : " + totalViewedActions);
    System.out.println("Updated contents by session " + value + " : " + totalUpdateActions);
    } else if (printFlag.equals("sessionPrintError")){
    System.out.println("This session " + value + " was not found on log file");
    } else if (printFlag.equals("actionPrint")){
    System.out.println("Action " + value + " was performed " + actionVector.size() +
    " times for " + userVector.size() + " different user(s)");
    } else if (printFlag.equals("actionPrintError")){
    System.out.println("This action " + value + " was not found on log file");
    } else {
    System.out.println("Wrong search type!");
    System.out.println("Accepted types are: ");
    System.out.println("-user -> Search for a specified user");
    System.out.println("-session -> Search for a specified session");
    System.out.println("-action -> Search for a specified action");
    private static void increaseActionType(String action) {
    if (action.startsWith("a")) {
    ++totalAddedActions;
    } else if (action.startsWith("c")) {
    ++totalChangedFolders;
    } else if (action.startsWith("p")) {
    ++totalPersonalizedActions;
    } else if (action.startsWith("r")) {
    ++totalRemovedActions;
    } else if (action.startsWith("v")) {
    ++totalViewedActions;
    } else if (action.startsWith("u")) {
    ++totalUpdateActions;
    }

  • Static methods and how to access

    Hi,
    This seems like a silly quesion but i am trying to access a static method but it tells me that i cant.
    The method i am calling from is not static
    Thanks

    syntax: class name dot static method name (assuming the method is accessible): StaticMethodClassName.aStaticMethod();
    can't reference a class member (variable, object, method, ...) from a static method because a static method is not a class member (it is simply a method whose scope is confined to that of the class in which it is defined).
    example:
    class Foo
    int i;
    public static void hasSyntaxErr() // this method is not a member of Foo
    i = 0; // not allowed because i is a member of Foo
    class Fooo
    void testStatic() { Foo.hasSyntaxErr(); }
    }

  • Why global var can be initialized with a static method and not by other static global var declared after its usage

    Take this:
    class test
    static int i=j;
    static int j=10;
    this will give illegal forward reference ....
    but this will compile successfully ..
    class test
    static int i=test1();
    static test1()
    return 20;
    plz assume we have main method in both cases ..
    java would be loading all static members first and would be assigning default values .. and then will be running all the initializers from to bottom ..
    Why second case is a compile success and not first .. as in second also test1 method is declared after its usage ..
    Plz help.
    Thanks
    Abhishek Roshan

    Why second case is a compile success and not first .. as in second also test1 method is declared after its usage ..
    Because the implementors of Java intentionally chose to do it that way.
    There are TWO stages to the process: preparation (which occurs first) and initialization.
    See the Java Language Spec section 12.4.1 'When Initialization Occurs
    The intent is that a class or interface type has a set of initializers that put it in a consistent state, and that this state is the first state that is observed by other classes. The static initializers and class variable initializers are executed in textual order, and may not refer to class variables declared in the class whose declarations appear textually after the use, even though these class variables are in scope (§8.3.2.3). This restriction is designed to detect, at compile time, most circular or otherwise malformed initializations.
    Note the clause beginning 'may not refer to class variables'. And the authors give the reason for that restriction in the last sentence: detect circular initializations.
    Then if you check that referenced section 8.3.2.3 you will find this
    http://docs.oracle.com/javase/specs/jls/se7/html/jls-8.html#jls-8.3.2.3
    8.3.2.3. Restrictions on the use of Fields during Initialization
    The declaration of a member needs to appear textually before it is used only if the member is an instance (respectively static) field of a class or interface C and all of the following conditions hold:
      The usage occurs in an instance (respectively static) variable initializer of C or in an instance (respectively static) initializer of C.
      The usage is not on the left hand side of an assignment.
      The usage is via a simple name.
      C is the innermost class or interface enclosing the usage.
    When a method is used (your example 2) no circular initialization can occur because methods are not 'initialized'.

  • Difference between calling static method and not static method?

    Hi,
    Suppose i want to write a util method, and many class might call this method. what is better? writing the method as static method or not static method. what is the difference. what is the advantace in what case?

    writing the method as static method or not static
    method. what is the difference.The difference is the one between static and non-static. Any tutorial or the JLs will clarify the difference, no need to repeat it here.
    what is the advantace in what case?It's usually not like you have much of a choice. If you need access to an instance's attributes, you can't make it static. Otherwise, make it static.

  • Static method and threads?

    I have a question regarding "static". for example, I have the following code
    class Test{
    public int i=0;
    public static calculateInt(){
    ....some operations on i;
    if two processes attempt to call Test.calculateInt() at the same time. What will the effects be? shall these two calls be implemented totally independent? each call holds it own "i" for calculation. OR there will be operation conflicit on i.
    what if I change "public i" to :private i", the same effects?

    You can't operate on i in a static method, since i is an instance variable.
    If you make i static, then you can operate on it in a static method. In that case, all threads will share a single i--there's only one i for the whole class, and threads don't change that. Making it private won't change that.
    If you make the method into an instance (non-static) method, then any threads operating on the same instance will share the same i, regardless of whether it's public or private. Different threads operating on different instances will each have their own i.
    Java's Thread Tutorial
    JavaWorld: Introduction to Java threads
    IBM: Introduction to Java threads
    Google: java+threads+tutorial
    Also check out http://java.sun.com/j2se/1.4.2/docs/api/java/lang/ThreadLocal.html

Maybe you are looking for

  • Dragging items in Cover Flow

    I really hope I'm not the only one this happens to. For some reason about 2 times out of 15 when I try to drag items from the list under the 'covers' in a finder window it won't let me. I.e. say I have 3 files in my finder and it's in cover flow view

  • ALV Grid : How to use Matcode / Search Help ? :-)

    Hi all, I'm using REUSE_ALV_GRID_DISPLAY, and I want to edit a field and use a matchcode/search help to enable the user to choose in a list. In my Fieldcat routine I've :         w_fieldcat_alv-edit          = 'X'.         w_fieldcat_alv-datatype    

  • Problem when updating the notes through synchroniz...

    I use to update my outlook 2003 notes regularly now it won't updating. I re-install the pc suite once, as soon as I re-installed it worked but only one time. My PC Suite version is 7.0.8.2 Mobile Phone N70 Music Edition.

  • Roles in forms

    i have created roles in database successfully....when i try to connect through same users by forms 5.0 after applying menu and menu item security thing....i get an error user is not entitled to run form builder...contact your DBA... being developer h

  • Could not load file or assembly 'Oracle.DataAccess, Version=2.112.3.0

    Hi, I am using windows 7 64 bit Enterprise Edition, Visual Studio 2010 Premium, and my app is built using .net framework 4.0. I downloaded and install ODP.NET 11.2.0.32 but when I add reference Oracle.DataAccess to my app, its giving me the following