What is the use of private static method/variable?

Hi All,
I have read lots of books and tried lots of things but still not very clear on the
topic above.
When exactly do we HAVE to use private static methods?
private implies its only for class, cannot be accessed outside.
But then static means, it can be accessed giving classname.method.
They seem to be contradicting each other.
Any examples explaining the exact behaviour will be well appreciated.
Thanks,
Chandra Mohan

Static doesn't really "mean" that the method/field is intended for use outside the class - that is exactly what the access modifier is for.
Static implies that it is for use in relation to the class itself, as opposed to an instance of the class.
One good example of a private static method would be a utility method that is (only) invoked by other (possibly public) static methods; it is not required outside the class (indeed, it might be dangerous to expose the method) but it must be called from another static method so it, in turn, must be static.
Hope this helps.

Similar Messages

  • What is the use of OTYPE_REF in Add method

    what is the use of OTYPE_REF in Add method

    class A
    static public void m(){}
    class B extends A
    static public void m(){}
    }is this over riding? well static methods are bind at
    compile time then there shouldnt be any over riding
    in case of static methods but when we use final
    keyword in the method of class A it makes an error.
    when static methods are bind at compile time then
    what is the use of final keyword with static methods?there is none, since static methods cannot be overridden and final prevents them from being overridden

  • What is the use of passing String[] args in main() method?

    what is the use of passing String[] args in main() method?
    Is there any specific use for this ?

    actually my sir asked me the same question & I gave
    the same reply as given by you........but he further
    asked what is the use of this also??
    ie accepting cmd line args at runtime??is there any
    specific purpose ??Apart from the one you just mentioned? No

  • Which java keyword cannot be used inside the body of a static method?

    Which java keyword cannot be used inside the body of a static method, but may be used without problems in a non-static method?

    But javac doesn't complain. So I was not partially wrong -- I was completely wrong.It's still better not to use the "this", though. When you explictly reference a static member via an instance reference (theFoo.bar or this.bar, as opposed to Foo.bar) the JLS requires a check that the reference is non-null. Clearly "this" is always non-null, but javac still puts in half of the check. Take the simple class public class Test {
        static int field;
        public void setField(int i) {this.field=i;}
        public void staticSetField(int i) {field=i;}
    } and observe the bytecodes produced: $ javap -c Test
    Compiled from "Test.java"
    public class Test extends java.lang.Object{
    static int field;
    public Test();
      Code:
       0:   aload_0
       1:   invokespecial   #1; //Method java/lang/Object."<init>":()V
       4:   return
    public void setField(int);
      Code:
       0:   aload_0
       1:   pop
       2:   iload_1
       3:   putstatic       #2; //Field field:I
       6:   return
    public void staticSetField(int);
      Code:
       0:   iload_1
       1:   putstatic       #2; //Field field:I
       4:   return
    }The JIT will get rid of it, but you may as well avoid the waste in the first place. (And if you really do want to check that the reference is non-null, do the check explicitly so that maintainers know it's intentional).

  • Why do we need private static method or member class

    Dear java gurus,
    I have a question about the use of private and static key words together in a method or inner class.
    If we want to hide the method, private is enough. a private static method is sure not intended to be called outside the class. So the only usage I could see is that this private static method is to be called by another static method. For inner class, I see the definition of Entry inner class in java.util.Hashtable, it is static private. I don't know why not just define it as private. Could the static key word do anything better.
    Could anybody help me to clear this.
    Thanks,

    What don't you get? Private does one thing, andstatic does >something completely different.
    If you want to listen to music, installing an airconditioner doesn't help>
    Hi, if the private keyword is the airconditioner, do
    you think you could get music from the static keyword
    (it acts as the CD player) in the following codes:You're making no sense and you're trying to stretch the analogy too far.
    Private does one thing. If you want that thing, use private.
    Static does something completely different and unrelated. If you want that thing, use static.
    If you want both things, use private static.
    What do you not understand? How can you claim that you understand that they are different, and then ask, "Why do we need static if we have private"? That question makes no sense if you actually do understand that they're different.

  • What is the use of passing object reference to itself ?

    What is the use of passing object reference to itself ?
    regards,
    namanc

    There is an use for returning an object reference from itself, for instance:
    class C {
    public:
         C append(C c) {
             // do something interesting here, and then:
             return this;
    }You can "chain" calls, like this:
    C c = new C();
    C d = new C();
    C e = new C();
    c.append (d).append (e);Maybe the OP has "inverted" the common usage, or thought about a static method of a class C that requires a parameter of type C (effectively being a sort of "non-static method").
    class C {
        static void doAnotherThing (C c) {
            c.doSomething(); //-- effectively C.doAnotherThing(c) is an "alternative syntax" for c.doSomething()

  • What is the use of Serializable Interface in java?

    Hello friends,
    I have one dout and i want to share with u guys:
    Why Serializable interface made and actully
    what's the use of it?
    At which place it become useful ?
    It is not contain any method then why it is made?
    If anyone have any idea about this then please reply.
    Thanks in advace
    Regards,
    Jitendra Parekh

    t is not contain any method then why it is made?To point out to the user of a class (and the programs) that the design of this class is conforming to certain restraints needed for Serialization.

  • What are the parameters in Call transaction method?

    Hi ABAPER'S,
        Please give me what are the parameters in call transaction method?
    Thanks,
    Prakash

    Processing batch input data with CALL TRANSACTION USING is the faster of the two recommended data transfer methods. In this method, legacy data is processed inline in your data transfer program.
    Syntax:
    CALL TRANSACTION <tcode>
    USING <bdc_tab>
    MODE  <mode>
    UPDATE  <update>
    <tcode> : Transaction code
    <bdc_tab> : Internal table of structure BDCDATA.
    <mode> : Display mode:
    A
    Display all
    E
    Display errors only
    N
    No display
    <update> : Update mode:
    S
    Synchronous
    A
    Asynchronous
    L
    Local update
    A program that uses CALL TRANSACTION USING to process legacy data should execute the following steps:
    Prepare a BDCDATA structure for the transaction that you wish to run.
    With a CALL TRANSACTION USING statement, call the transaction and prepare the BDCDATA structure. For example:
    CALL TRANSACTION 'TFCA' USING BDCDATA
    MODE 'A'
    UPDATE 'S'.
    MESSAGES INTO MESSTAB.
    IF SY-SUBRC <> 0.
    <Error_handling>.
    ENDIF.
    The MODE Parameter
    You can use the MODE parameter to specify whether data transfer processing should be displayed as it happens. You can choose between three modes:
    A Display all. All screens and the data that goes in them appear when you run your program.
    N No display. All screens are processed invisibly, regardless of whether there are errors or not. Control returns to your program as soon as transaction processing is finished.
    E Display errors only. The transaction goes into display mode as soon as an error in one of the screens is detected. You can then correct the error.
    The display modes are the same as those that are available for processing batch input sessions.
    The UPDATE Parameter
    You use the UPDATE parameter to specify how updates produced by a transaction should be processed. You can select between these modes:
    A Asynchronous updating. In this mode, the called transaction does not wait for any updates it produces to be completed. It simply passes the updates to the SAP update service. Asynchronous processing therefore usually results in faster execution of your data transfer program.
    Asynchronous processing is NOT recommended for processing any larger amount of data. This is because the called transaction receives no completion message from the update module in asynchronous updating. The calling data transfer program, in turn, cannot determine whether a called transaction ended with a successful update of the database or not.
    If you use asynchronous updating, then you will need to use the update management facility (Transaction SM12) to check whether updates have been terminated abnormally during session processing. Error analysis and recovery is less convenient than with synchronous updating.
    S Synchronous updating. In this mode, the called transaction waits for any updates that it produces to be completed. Execution is slower than with asynchronous updating because called transactions wait for updating to be completed. However, the called transaction is able to return any update error message that occurs to your program. It is much easier for you to analyze and recover from errors.
    L Local updating. If you update data locally, the update of the database will not be processed in a separate process, but in the process of the calling program. (See the ABAP keyword documentation on SET UPDATE TASK LOCAL for more information.)
    The MESSAGES Parameter
    The MESSAGES specification indicates that all system messages issued during a CALL TRANSACTION USING are written into the internal table <MESSTAB> . The internal table must have the structure BDCMSGCOLL .
    You can record the messages issued by Transaction TFCA in table MESSTAB with the following coding:
    (This example uses a flight connection that does not exist to trigger an error in the transaction.)
    DATA: BEGIN OF BDCDATA OCCURS 100.
    INCLUDE STRUCTURE BDCDATA.
    DATA: END OF BDCDATA.
    DATA: BEGIN OF MESSTAB OCCURS 10.
    INCLUDE STRUCTURE BDCMSGCOLL.
    DATA: END OF MESSTAB.
    BDCDATA-PROGRAM = 'SAPMTFCA'.
    BDCDATA-DYNPRO = '0100'.
    BDCDATA-DYNBEGIN = 'X'.
    APPEND BDCDATA.
    CLEAR BDCDATA.
    BDCDATA-FNAM = 'SFLIGHT-CARRID'.
    BDCDATA-FVAL = 'XX'.
    APPEND BDCDATA.
    BDCDATA-FNAM = 'SFLIGHT-CONNID'.
    BDCDATA-FVAL = '0400'.
    APPEND BDCDATA.
    CALL TRANSACTION 'TFCA' USING BDCDATA MODE 'N'
    MESSAGES INTO MESSTAB.
    LOOP AT MESSTAB.
    WRITE: / MESSTAB-TCODE,
    MESSTAB-DYNAME,
    MESSTAB-DYNUMB,
    MESSTAB-MSGTYP,
    MESSTAB-MSGSPRA,
    MESSTAB-MSGID,
    MESSTAB-MSGNR.
    ENDLOOP.
    The following figures show the return codes from CALL TRANSACTION USING and the system fields that contain message information from the called transaction. As the return code chart shows, return codes above 1000 are reserved for data transfer. If you use the MESSAGES INTO <table> option, then you do not need to query the system fields shown below; their contents are automatically written into the message table. You can loop over the message table to write out any messages that were entered into it.
    Return codes:
    Value
    Explanation
    0
    Successful
    <=1000
    Error in dialog program
    > 1000
    Batch input error
    System fields:
    Name:
    Explanation:
    SY-MSGID
    Message-ID
    SY-MSGTY
    Message type (E,I,W,S,A,X)
    SY-MSGNO
    Message number
    SY-MSGV1
    Message variable 1
    SY-MSGV2
    Message variable 2
    SY-MSGV3
    Message variable 3
    SY-MSGV4
    Message variable 4
    Error Analysis and Restart Capability
    Unlike batch input methods using sessions, CALL TRANSACTION USING processing does not provide any special handling for incorrect transactions. There is no restart capability for transactions that contain errors or produce update failures.
    You can handle incorrect transactions by using update mode S (synchronous updating) and checking the return code from CALL TRANSACTION USING. If the return code is anything other than 0, then you should do the following:
    write out or save the message table
    use the BDCDATA table that you generated for the CALL TRANSACTION USING to generate a batch input session for the faulty transaction. You can then analyze the faulty transaction and correct the error using the tools provided in the batch input management facility.

  • What is the advantages of polymorphism over method overriding?

    what is the advantages of polymorphism over method overriding,that means if we are able to to create object at different instances at diff time for that sub class reff variable than what is the need of careating object of super class data type(i.e why always it is necessary to have upcasting for polymorphism?but if we can achive the same output without upcasting).....please tell me..lets have complete discuss..

    Seriously though....
    WebLogic (for which I have deployed many apps on) as
    well as Websphere are both high end Java application
    servers, meaning J2EE servers (in short). They allow
    one to deploy Enterprise Archive(EAR), a Web
    Archive(WAR), or an EJB Archive (in a JR file).
    These two servers allow one to deploy EJBs, use
    e JNDI, JMS, connectors, and other J2EE technologies
    - Tomcat does not. well, EJBs - no
    JNDI, yes - http://tomcat.apache.org/tomcat-4.1-doc/jndi-resources-howto.html
    JMS - yes (with an implementation, such as ActiveMQ: http://activemq.codehaus.org/Tomcat)
    Not sure what you mean by "connectors".
    Tomcat provides quite a bit of functionality (but yes, no EJBs)

  • What is the use of delta in BW side when we have delta in R/3

    Hi,
    what is the use of delta in BW side when we are already using delta in R/3 side?
    Like,
    Generic extraction:-
    with different delta extractions (Time stamp, Calendar day, Numeric pointer).
    Lo-Cockpit extraction with change log method.
    Co/Pa extraction with time stamp method.
    So from this delta activation first time full data will be loaded and after that only changed data will be loaded because of these deltas in R/3 side.
    So now my question is what is the exact use of delta in BW side with ODS/DSO because data already reached to BW with delta activation right.
    Can you please explain me what is the exact use of BW delta?
    Thanks in advance.
    Points to be added.
    Regards,
    Shyam.

    The purpose of Delta Queue is same in R/3 and BW.
    In BW, Delta Queue is used to capture changes made to objects within BW. (for Eg: BW Statastics)or Update data from one BW system to another BW system (if you have multiple BW systems).
    Message was edited by:
            Praveen Vujjini

  • What is the use of Generic class in java

    hi everyone,
    i want to know that
    what is the use of Generic class in java ?
    regards,
    dhruvang

    Simplistically...
    A method is a block of code that makes some Objects in the block of code abstract (those abstract Objects are the parameters of the method). This allows us to reuse the method passing in different Objects (arguments) each time.
    In a similar way, Generics allows us to take a Class and make some of the types in the class abstract. (These types are the type parameters of the class). This allows us to reuse the class, passing in different types each time we use it.
    We write type parameters (when we declare) and type arguments (when we use) inside < >.
    For example the List class has a Type Parameter which makes the type of the things in the list become abstract.
    A List<String> is a list of Strings, it has a method "void add(String)" and a method "String get(int)".
    A List<File> is a list of Files, it has a method "void add(File)" and a method "File get(int)".
    List is just one class (interface actually but don't worry about that), but we can specify different type arguments which means the methods use this abstract type rather than a fixed concrete type in their declarations.
    Why?
    You spend a little more effort describing your types (List<String> instead of just List), and as a benefit, you, and anyone else who reads your code, and the compiler (which also reads your code) know more accurately the types of things. Because more detail is known, the compiler is able to tell you when you screw up (as opposed to finding out at runtime). And people understand your code better.
    Once you get used to them, its a bit like the difference between black and white TV, and colour TV. When you see code that doesn't specify the type parameters, you just get the feeling that you are missing out on something. When I see an API with List as a return type or argument type, I think "List of what?". When I see List<String>, I know much more about that parameter or return type.
    Bruce

  • What is the use of setup tables in LO extraction

    Hi Friends,
    What is the use of setup tables in LO extraction, what is the functionality of setup tables
    Thanks in advance

    hi,
    to prepare data to be extracted to bw,
    more details take a look Roberto's weblog
    /people/sap.user72/blog/2004/12/16/logistic-cockpit-delta-mechanism--episode-one-v3-update-the-145serializer146
    /people/sap.user72/blog/2004/12/23/logistic-cockpit-delta-mechanism--episode-two-v3-update-when-some-problems-can-occur
    /people/sap.user72/blog/2005/01/19/logistic-cockpit-delta-mechanism--episode-three-the-new-update-methods
    /people/sap.user72/blog/2005/04/19/logistic-cockpit-a-new-deal-overshadowed-by-the-old-fashioned-lis
    /people/sap.user72/blog/2005/02/14/logistic-cockpit--when-you-need-more--first-option-enhance-it
    hope this helps.

  • What is the use of points earned in apple support communities??

    what is the use of points earned in apple support communities??

    mende1      Valmojado, Toledo, Spain
    This solved my questionRe: How the heck do you get points on your apple support communities account?
    Jul 12, 2013 10:20 PM (in response to BMPU)
    To get points, you have to answer questions. If the user that created the post tested your solution and it worked, he/she (may) give you a "This solved my question". As you can see in the right part of this page, a solved question adds 10 points to your account. If you helped solve the problem, you receive 5 points. On a single thread, the original poster can only give 1 "This solved my question" and 2 "This helped me", so you can receive a total of 20 points.
    With these points, there are levels that you can see in this page > https://discussions.apple.com/static/apple/tutorial/reputation.html When you level up, you receive privileges like report posts, access to Community Calls... The most important level respecting to privileges is the level 6, that gives you access to a special forum called "The Lounge" (where you can talk about anything you want, complain about an user or report problems with the forum), and you also receive gifts from Apple and other privileges

  • What is the use of the setter dependency injection in Spring?

    What is the use of the dependency setter injection ?
    In a database driven app, I retrieve results, use the javabeans set methods to save stuff in javabeans and then call get on it.
    What is the use of having something set externally from a xml already ?
    Can someone provide an example when the setter injection can be used?
    I wouldnt imaginge using it to get usernames, passwords, databaseurl because we use JNDI for that...
    Is the dependency setter meant as something additional to web.xml so you dont have to get params from web.xml?

    No, you would indicate in the XML that the Hibernate object and the TransactionFactory (I am being vague here) have a dependency. You then specify whether you want setter or constructor injection. When Spring creates the Hibernate Object, it will attempt to also create a TransactionFactory and pass that to the Hibernate Object's setter. "Auto-wiring" them together for you.
    - Saish

  • What is the use of Marker Interfaces?

    What is the use of marker interfaces?
    As it is not having any methods or fileds what is the benefit I will get by implementing those interfaces?
    Servlet implements SingleThread
    What it will do behind the scenes exactly as singleThread model is marker interface

    The use of marker interfaces is to act as markers (shock horror)
    It is quite a common way to tell a program what a class can/can't do: Cloneable, Serializable etc etc
    This doesn't change the functionality of the class itself, but is more an indication as to what can be done with this class.
    In this case the servlet container can then tell whether or not it implements the interface, and can treat it accordingly. Implementing this interface tells the container you want it to run this servlet in singleThreaded mode.
    Thats all there is to it.
    It would be along the lines of
    Servlet servlet = loadServlet("...")
    if (servlet instanceof SingleThreadModel){
    // Single threaded servlet - start new process for it
    else {
    // regular servlet - reuse existing object.

Maybe you are looking for

  • Can I use air play to mirror anything that's on the screen of my iPad

    I have the nfl gamerewind app on my iPad. I'd like to use air play to mirror the games from my iPad to my TV screen.  Is this possible? Or, is it possible to mirror the screen of my Windows 7 laptop to my TV using Apple TV? Thanks for any help, I am

  • What to look for in a used iBook G3?

    Hi, I'm in the process of looking at a used iBook G3 with 640 MB SDRAM and 40 GB HD. Anything I should look for that could make or break a deal? (I'm new to Apple and have never owned or used one)! thanks in advance

  • FI-CO Configuration

    Hello SAP Gurus, Simulate Inventory Mgmt; Entry of Simulation Data Plant appears as error. Can any of you help in rectifying this .  My plant is not showing in the drop down menu. If the plant was not created let me know the path and how to rectify t

  • Unable to initialize Graphing service in Solaris 9 using ColdFusion MX 7

    Upgraded from CMFX 6,1,0,63958 to CMFX 7.0.2 on Solaris 2.9 No errors during upgrades. Upon starting the CMFX 7, I am seeing this in the cfserver.log. I cannot reach the CFMX administrator page. 07/07 15:55:44 Information [main] - Starting graphing..

  • OIM notification framework

    Hello, I'm stuck in one point,as i'm new in this.i was trying OIM notification framework,in which there is one process where we have to create java code for notification resolver and then register it in oim as plugin..in this java code itmust impleme