• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

static

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I struggle to really understand "static", what is "static" in java, what is it really for...it is not getting clear in my mind.
 
Ranch Hand
Posts: 954
4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Static is used in different conditions ex: A class, a variable or a method.

A class is used as static when it is coupled with the outer class and no existence is required outside.

A variable is static when it is shared between all the instances or the value is required before any instance created. Ex: Connection creation

A method is static when behaviour of a class is not dependent on any of its instance. Example: In a class there is a method add which calculates
the sum of 2 two numbers, this method is not dependent on any instance so we can use that method as static.
 
Ranch Hand
Posts: 175
17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A static member is a member that is associated with a class.
  • The serialVersionUID field is static because it is an attribute that is associated with a class i.e. it associates a version number with a serializable class.
  • The valueof() method in the String class is static because it defines a behaviour that is associated with the String class i.e. it returns a string representation of its argument. Because it is not associated with an instance, the JVM will not pass this to the valueof() method.

  • A non-static member is a member that is associated with an instance of a class.
  • The id field is non-static because it is an attribute that is associated with an instance of a class i.e. it associates a unique identity with an instance of a class.
  • The length() method in the String class is non-static because it defines a behaviour that is associated with an instance of the String class i.e. it returns the length of an instance of the String class. Because it is associated with an instance, the JVM will pass this to the length() method.
  •  
    Now I am super curious what sports would be like if we allowed drugs and tiny ads.
    the value of filler advertising in 2021
    https://coderanch.com/t/730886/filler-advertising
    reply
      Bookmark Topic Watch Topic
    • New Topic