Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. what is the basic purpose of static class/methode

what is the basic purpose of static class/methode

Scheduled Pinned Locked Moved Java
performancequestion
7 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    khurram_shahzad
    wrote on last edited by
    #1

    Please tell me some details about static class/methode, i search for it on internet in forms etc but i didn't yet setisfied and still unable to explain it in confident and clear way :( the most common questions about static class/methode in my mind are, - why use static class My Knowledge >> They provide access to class static methode directly without creating its instance. they have same instance in memory .. means every use/access to this methode can have changes effect for every one. ANY OTHER BENEFIT AND PURPOSE !! Also please tell me clearly the basic purpose of static class/method ... in interviews they always as to me about it and i always failed to answer clearly to him :sigh:

    N L _ R 4 Replies Last reply
    0
    • K khurram_shahzad

      Please tell me some details about static class/methode, i search for it on internet in forms etc but i didn't yet setisfied and still unable to explain it in confident and clear way :( the most common questions about static class/methode in my mind are, - why use static class My Knowledge >> They provide access to class static methode directly without creating its instance. they have same instance in memory .. means every use/access to this methode can have changes effect for every one. ANY OTHER BENEFIT AND PURPOSE !! Also please tell me clearly the basic purpose of static class/method ... in interviews they always as to me about it and i always failed to answer clearly to him :sigh:

      N Offline
      N Offline
      Nagy Vilmos
      wrote on last edited by
      #2

      Static can be used in various ways. Anything that needs to be shared across all instances of a class can either be made static - easy - or passed around in another object - hard. Certain design patterns - I'm thinking the singleton here - rely on static methods to encapsulate class functionality and control behaviour. Any method that does not (or must not) use instance data should be static to prevent it accessing the instance data. There is no need to instantiate an object to call a static method - say a helper class providing oft called methods - have a look at the static methods on String.


      Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre

      K 1 Reply Last reply
      0
      • K khurram_shahzad

        Please tell me some details about static class/methode, i search for it on internet in forms etc but i didn't yet setisfied and still unable to explain it in confident and clear way :( the most common questions about static class/methode in my mind are, - why use static class My Knowledge >> They provide access to class static methode directly without creating its instance. they have same instance in memory .. means every use/access to this methode can have changes effect for every one. ANY OTHER BENEFIT AND PURPOSE !! Also please tell me clearly the basic purpose of static class/method ... in interviews they always as to me about it and i always failed to answer clearly to him :sigh:

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Have a look at the Java Tutorials[^], they contain an excellent introduction to all aspects of the language.

        I must get a clever new signature for 2011.

        1 Reply Last reply
        0
        • K khurram_shahzad

          Please tell me some details about static class/methode, i search for it on internet in forms etc but i didn't yet setisfied and still unable to explain it in confident and clear way :( the most common questions about static class/methode in my mind are, - why use static class My Knowledge >> They provide access to class static methode directly without creating its instance. they have same instance in memory .. means every use/access to this methode can have changes effect for every one. ANY OTHER BENEFIT AND PURPOSE !! Also please tell me clearly the basic purpose of static class/method ... in interviews they always as to me about it and i always failed to answer clearly to him :sigh:

          _ Offline
          _ Offline
          _Erik_
          wrote on last edited by
          #4

          Static methods are frequently used in several design patterns (Singleton, DataFactory...) but, to give you something very simple and easy to understand, think about Math class. How do yo use it?

          a = Math.abs(n);
          a = Math.floor(n);
          a = Math.sqrt(n);
          ...

          So, as you can see, we don't have to create an instance of Math class, becouse we just use its static methods. In these cases, we say the Math class only offers services, and that is why all of its methods are static.

          K 1 Reply Last reply
          0
          • _ _Erik_

            Static methods are frequently used in several design patterns (Singleton, DataFactory...) but, to give you something very simple and easy to understand, think about Math class. How do yo use it?

            a = Math.abs(n);
            a = Math.floor(n);
            a = Math.sqrt(n);
            ...

            So, as you can see, we don't have to create an instance of Math class, becouse we just use its static methods. In these cases, we say the Math class only offers services, and that is why all of its methods are static.

            K Offline
            K Offline
            khurram_shahzad
            wrote on last edited by
            #5

            Thanks for your help .... Thanks a lot

            1 Reply Last reply
            0
            • N Nagy Vilmos

              Static can be used in various ways. Anything that needs to be shared across all instances of a class can either be made static - easy - or passed around in another object - hard. Certain design patterns - I'm thinking the singleton here - rely on static methods to encapsulate class functionality and control behaviour. Any method that does not (or must not) use instance data should be static to prevent it accessing the instance data. There is no need to instantiate an object to call a static method - say a helper class providing oft called methods - have a look at the static methods on String.


              Panic, Chaos, Destruction. My work here is done. or "Drink. Get drunk. Fall over." - P O'H OK, I will win to day or my name isn't Ethel Crudacre! - DD Ethel Crudacre

              K Offline
              K Offline
              khurram_shahzad
              wrote on last edited by
              #6

              Thanks for your help .... Thanks a lot

              1 Reply Last reply
              0
              • K khurram_shahzad

                Please tell me some details about static class/methode, i search for it on internet in forms etc but i didn't yet setisfied and still unable to explain it in confident and clear way :( the most common questions about static class/methode in my mind are, - why use static class My Knowledge >> They provide access to class static methode directly without creating its instance. they have same instance in memory .. means every use/access to this methode can have changes effect for every one. ANY OTHER BENEFIT AND PURPOSE !! Also please tell me clearly the basic purpose of static class/method ... in interviews they always as to me about it and i always failed to answer clearly to him :sigh:

                R Offline
                R Offline
                Ramaiah Raj
                wrote on last edited by
                #7

                static can be declared for variables and methods. When instance variables declared as static then its called class variables. Local variable can not be static.Each and every object share the same variables. In the sense when one object modify the variable the result will be reflected in all objects. With out creating object static variable methods can be accessed.Before object creation static variables initialized or instantiated.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups