Posted on 2006-04-30
Medium Priority
Last Modified: 2010-03-31
Can anyone tell me what exactly Static means and when it should be used.  I kinda know when to use it but I am not sure I quite get the concept of it.

Question by:yattias
LVL 24

Expert Comment

ID: 16575276
static means: global (always present) for a variable.
                    accessing static variables for a method.
                    to be executed at startup for a block {}

Example:     static int count = 0;    // to count objects of this kind, 0 == no objects, still a variable,
                  static void counter() { ++ count; }  // to access this variable.


Author Comment

ID: 16575302
I am not so sure I fully understand your definition of static.  Could you be more specific?
LVL 23

Accepted Solution

Siva Prasanna Kumar earned 100 total points
ID: 16576095
Generally Static varaibles are used to share some thing b/w the Objects.

In simple terms Static variables doesn't belong to any Object in particular they belong to the Class.

They are Very Useful in situations when you want to count the Number of Objects of the Class are created for example.

In similar fashion Static method also Belong to the Class So only when you want to use them you just need to say Classname.functionName.

check out

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 30

Expert Comment

by:Mayank S
ID: 16576288
Basically its a member of the class for instantiating or using which you don't need to create objects of the class.

Explained here: http://www.mindprod.com/jgloss/static.html 
LVL 24

Assisted Solution

sciuriware earned 100 total points
ID: 16577179
And static variables and methods are bundled in classes just to make them globally
usable without any object relationship.
For instance:
the class Math bundles all static calculation methods, like abs() and sqrt().
It would be weird to create an object, just to compute a square root.

LVL 30

Expert Comment

by:Mayank S
ID: 16577217
Yes, you can use them for utilities (where you would expect the same result from a method and you don't need any instance data-members), and static is also made use of in the singleton design pattern.

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month16 days, 9 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question