• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

static question

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i cant figure out why did they put static
on oe variable
and not on the other

private int sp;
private Object[] data;
private static final int DEFAULT_SIZE = 5;
private static final int RESCALE = 5;
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess it depends on the *need*.

A similar question posted by you is answered here.

I believe that will help you get an answer
 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i noticed that the static ones dont change while the others
changes

is that what its all about??
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by johny doe:
i noticed that the static ones dont change while the others
changes

is that what its all about??



don't change means? in what context? Actually they are NOT bound to any specific instance of a class, rather to the whole class in common.

You can go for 'static' when you want to have some common data for all your instances of a class. Otherwise, each instance will have its own copy of the variables if declared non-static.
 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when i make non static mathod
how do i call it from a static mathod??
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for quoting my post, Raghavan Muthu.

There is another similar thread, probably with better discussion on, here.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to do anything to make a method "non-static" (it would be better to call it an "instance method"). All you have to do is not write "static."

You can't get access to an instance member of a class from a static method.
 
johny doe
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the difference between
when i define variable as
int

and

integer

what is the differnce between the two??
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Johny Doe,

Are you listening to the answers to your queries first? Pay attention to the answers firt.

Moreover, please do NOT post an irrelevant and a new question in an already running thread. Kindly use one thread per question.

Start a new thread for your int, integer difference question. Hope you will stick to the rules of the forum.
 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
muthu,

if you want to answer the quesions pls do the clarification here itself..dont link with other questions and all...

raja
SCJP 1.4
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by thirumala raju:

if you want to answer the quesions pls do the clarification here itself..dont link with other questions and all...



Quoting the FAQ, as Muthu is doing, is absolutely the correct thing to do; please take the time to learn about our community's norms before going about telling folks how to behave. Thanks.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by thirumala raju:
if you want to answer the quesions pls do ...


Please use real words when posting to the forums. Abbreviations such as "pls" in place of "please" only serve to make your posts more difficult to read and less likely to generate useful responses.

Please read this for more information.

thanks,
bear
JavaRanch sheriff
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic