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.

Similar Messages

  • 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

  • What is the advantage of using methods to return objects?

    Hello there,
    What is the advantage of using static methods to return
    objects? Isnt this a Factory Pattern ?
    What is the real advantage of using methods to return objects
    rather than using public constructors to create objects ?
    Can some one please explain
    Regards

    I think there were two questions. The first (why
    static) is well answered but I hope somebody can
    answer the general question - why whatever =
    createSomething(); as opposed to whatever
    = new Something(); - because inquiring minds
    want to know.I thought I answered that question. Perhaps I need to be more specific.
    For the Singleton pattern, you don't want a new instance (except possibly the first time, if you're using lazy instantiation).
    For the Factory pattern, you might not always want an instance of the actual class containing the static methods, so new won't work.
    If, on the other hand, neither of the above holds, there is no reason not to use new (unless, of course, anyone can come up with another use of static creators).
    RObin

  • 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 benefit of static in a method/function

    hello,
    can u explain the benefit of static in a function?
    and why i cannot called a function in a static method..example :
    class jalaninFungsi{
         public static void main(String args[])
              tesfungsi();
         public  void tesfungsi()
              System.out.println("ini tesfungsi");
    }its produce error : non-static method tesfungsi() cannot be referenced from static context
    thanks.

    A class is an object.
    So for example:
    class STUDENT
    public String getStudentName()
    return name;
    public int getStudentGPA()
    return GPA;
    In this case, to be able to call the function getStudentName() and getStudentGPA() you will actually need a STUDENT object.
    That means you must have declared e.g. STUDENT A; (in the main method for example), then to call those two functions above you'll need to write A.getStudentName(); and A.getStudentGPA();
    HOWEVER if you have static method, you don't need to create an object of that class type. You can just simply call the class name and then use the dot operator and call the function. e.g.:
    class STUDENT
    public static String getStudentName()
    return name;
    public static int getStudentGPA()
    return GPA;
    Notice that these are static methods, so to access these methods you just need to write STUDENT.getStudentName(); or STUDENT.getStudentGPA();
    Again, notice that here I don't use A . but instead I used the class name (STUDENT.)
    However, this is not logically correct in this (my) particular case to make those two methods static. You'll need to read more by yourself about the usage of static method. I am just trying to explain it to you why there is such thing called static methods in java.
    - o.z.

  • I want to transfer all my iPhoto, iTunes, contacts, etc. files from my MacBook, which I am selling to a MacBook Pro. What is the easiest and safest method of achieving this? Can the files backed up on Time Machine be transferred to the Pro?.

    I want to transfer all my iPhoto, iTunes, contacts,documents, etc. files from my MacBook, which I am selling, to a MacBook Pro. What is the easiest and safest method of achieving this? Can the files backed up on Time Machine from the MacBook be transferred to the Pro in some way? I would like to capture the files as they appear on the MacBook, such as "Events" in iPhoto and the various song categories within iTunes without having to rename them all once saved on the Pro, which is the case with photos when I simply save them to thumb drive and import them to the Pro. Sny advice would be appreciated.
    Best regards,
    Rob.

    Michael,
                 Thanks for all your assistance. There is no need for apologies, Migration Assistant did indeed create a second account for the MacBook data. It has just taken me some time to figure out how to access it. I now have all the MB data in one account and the MBP files in another, which suits me fine. In fact, it is an advantage in my case as it keeps the private and business aspects separated.
    I will however try the fatcatsoftware to transfer all the iPhoto files to my iMac, where I keep my main photo library. and it will be of help to keep the events, etc in the transfer. As far as iTunes is concerned, I have HomeSharing on all my computers and this has obviated the need to worry about playlists being transferred successfully. However, HomeSharing did not appear to share the iPhone/iPod apps that were stored on the MB and although these have now come across with the new MacBook account on the MBP, I was wondering whether my iPhone and iPod will be recognised by the MBP and sync with it? Will I need to have the MB account open to achieve this or will the MBP recognise and sync with the iPhone/iPod automatically irrespective of which account is open?
    Thanks for the tip on deauthorising my iTunes account from the MB before sellng. This I will do and I believe the best way to remove all of my data from the hard drive is to reinstall the MacOSX operating system software. Is this the right approach to securely delete everything?
    Thanks again for sharing your expertise and your guidance through this exercise.
    Best regards,
    Rob.

  • What are the advantage of using a passive monitoring technique ?

    What are the advantage of using a passive monitoring technique

    Hi Plawansai,
    I saw your question that is still unanswered.
    I believe an advantage of using a passive monitoring technique is that it won't interfer with live traffic, as it does not inject traffic into the network or modify the traffic that is already on the network.
    One drawback anyway, is that post-processing time can take a large amount of time with passive monitoring!
    A combination of the two monitoring methods seems to be the route to go.
    V.

  • What are Parameters? How are they differenet from Variables? Why can't we use variables for passing data from one sequnece to another? What is the advantage of using Parameters instead of Variables?

    Hi All,
    I am new to TestStand. Still in the process of learning it.
    What are Parameters? How are they differenet from Variables? Why can't we use variables for passing data from one sequnece to another? What is the advantage of using Parameters instead of Variables?
    Thanks in advance,
    LaVIEWan
    Solved!
    Go to Solution.

    Hi,
    Using the Parameters is the correct method to pass data into and out of a sub sequence. You assign your data to be passed into or out of a Sequence when you are in the Edit Sequence Call dialog and in the Sequence Parameter list.
    Regards
    Ray Farmer

  • What is the advantages of using Interface?

    Hi,
    I still don't get what's the advantages of using interface. Reusability? is it the main advantage? thanks in advance.

    What is GOF?
    Interface is a good program practice when working with RMI (Remote Method Invocation) application. Imagine your anti-virus. When you connect to internet your software invoke a method into your software vendor site and download the new definitions. Now every anti-virus Subscription is different. The method you invoke, will depends on your Subscription. If you hard code the method abstractly, you will not achieve this functionality.
    Another concept is that because Java does not practice multile inheritance interface is a goog way to interface into another class.
    Example
    I want to extends to multiple class which java do not support. I will write an interface i.e I want to extends to FileOutputStream, OutputStream, Object, Integer, String, ActionEvent, Window etc.
    I will write an interface like this
    interface MyClass {
    pulic void setFileOutputStream ( FileOutputStream file );
    public void setOutputStream ( OutputStream );
    public Object getObject ( );
    public Seriable getInterget ( )
    ------------------- //You get the gist
    With this interface you can implement they behaviours
    You could say, why don't we just import them. When yo import them you have already hard coded there behaviour. But this way you can apply diferent behaviour throughout you application development. And any class that implement them must provide ways of using it.

  • What is the advantage of using EventQueue.invokeLater ?

    Hi, what is the advantage of using
    public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new MainForm().setVisible(true);
    }over
    public static void main(String args[]) {
         new MainForm().setVisible(true);
    }

    You can update the GUI components in any thread. However their behaviour is not always correct if you do so.
    Using invokeLater ensures that the GUI thread performs changes to the GUI components and draws them correctly.

  • What is VIEW in Database table what is the advantage

    Hi:
    I would like to get your opinion on what is the advantage of Table VIEW?
    I read a note saying it is all about simplifying Query.
    But when you come to XMLTYPE where there is only ONE ROW and NO COLUMN,
    How do you create XMLVIEW for a large XML files?
    Please help
    Ali_02

    Overview of Views
    Read here...
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10713/schemaob.htm#i20690
    XMLView or XMLTYPE ?
    Overview of XML in Oracle Database
    Read here...
    http://download.oracle.com/docs/cd/E11882_01/server.112/e10713/cncptdev.htm#CNCPT1535
    Edited by: ordba on Mar 4, 2010 9:50 AM

  • What is the advantage of using IB to create XIBs/Class Objects over coding?

    Hi all,
    I hoping someone can provide me some pros and cons as to when I should use IB to create XIBs and/or class objects as opposed to directly coding them.
    For example, if I choose Apple's Template for creating a Navigation Based Application (cocoa touch), the project creates two NIB files - MainMenu and RootViewController.
    However looking at one of demo apps SimpleDrillDown, it does not have a RootViewController XIB and instead creates it via code.
    Another example from the same two apps is that the template generates a "Navigation Controller" class object in the Mainmenu.xib. SimpleDrillDown does not bother with this in the XIB, but uses code to generate the controller:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Create the navigation and view controllers
    RootViewController *rootViewController = [[RootViewController alloc] init];
    UINavigationController *aNavigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
    self.navigationController = aNavigationController;
    [aNavigationController release];
    [rootViewController release];
    // Configure and show the window
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
    as opposed to the template which only needs this:
    - (void)applicationDidFinishLaunching:(UIApplication *)application {
    // Configure and show the window
    // Navigation Controller is defined in MainWindow.xib
    [window addSubview:[navigationController view]];
    [window makeKeyAndVisible];
    So what are the advantages of each approach. Why does apple suggest one approach and yet all its demos use another.
    Any thoughts, answers gratefully received.
    TIA, Michael.

    You can do whatever you're comfortable with, but most of the best Cocoa programmers--the ones on the Mac, I mean--recommend putting everything you can into Interface Builder.
    It's a little like the difference between writing a program to do a bunch of financial calculations and using a spreadsheet. Yeah, the program can do everything the spreadsheet can--and more besides--but you'll find it far easier to create, use and modify the spreadsheet.
    Interface Builder takes away a lot of completely meaningless choices ("What order should I create the objects in? How should I name the variables? How should I create their frames? What order should I set the attributes in?"), leaving you with an interface optimized for creating and arranging objects, and allowing your code to focus on what you really do need to think about--your application's logic.
    (By the way--part of the reason Apple's demos don't all use Interface Builder is that the very first SDK releases didn't have it. Back then, you had to create all your views programatically. Believe me, I have no wish to go back to setting autoresize masks manually. Now get off my lawn, whippersnapper.)

  • What are the advantages of compressor and it it even necessary

    what are the advantages of compressor and it it even necessary?

    Necessary for some and not for others – probably a large majority – who can by with the presets avalaible in FCX.
    The users who need Compressor are those who want to control the parameters of the encodes to get the best possible trade-off between file size and quality. Or those who want to do things like standards conversions, complex frame speed changes, better re-scaling capabilities, de-interlacing, re-interlacing, output formats beyond which are available in FCX, chapter markers for DVD and Blu-Ray authoring, batch conversions for multiple purposes through droplets, access to clusters for faster rendering.
    Russ

  • What are the advantages of WiFi + cellular as to just WiFi devices

    What are the advantages of WiFi + cellular as to just WiFi devices

    Advantages of Wi-Fi and cellular iPad.
    1. You can use it in places without Wi-Fi.
    2. The cellular model have GPS.

  • What are the advantages of varying write speeds and burn speeds?

    What are the advantages of varying write speeds and burn speeds?

    The slower the speed, the fewer burn errors (or, in other words, you'll burn fewer "coasters"). I've always tried to burn at a slower speed, i.e. 2x - 4x. I'd rather wait a few minutes more and I've never had any burn errors.

Maybe you are looking for