Build your professional network on facebook via our app Go to app
 
 
Posted in Community :

JAVA/J2EE/FAQ/JOB

 
Activity: Question posted: 03 28 2011 12:12:36 +0000, 5 answers, 187 views, last activity 10 19 2011 13:21:01 +0000
 
Share
 
 
  Rate : 
 
 

what is efferent between using STATIC keyword with out using Static keyword in java programming language.

 
  Answer modified by     piyush sharma, Software Developer, Navyug InfoSolutions Private Limited  | 10 19 2011 13:21:01 +0000
[ Delete ]
[ Edit ]
Not Rated

static means something that is shared among the objects,that is of class level.It is loaded in the memory at the compile time.Objects can't directly access it thus to access a static variable class name is used like

className.member

now problem is that main() is the entry point of the program since Java follows OOPS that's why u have to access the function using object.since object creation statement is in main() function so how JVM will access the function.For this,function is kept static so that JVM can access it without creating its object.

  Answered by     Sharad Gupta, Software Developer, Tripura Technologies, Hyderabad  | 03 28 2011 14:17:02 +0000
[ Delete ]
[ Edit ]
Not Rated

Program execution starts from Main(). & it should be called before the creation of any object. By using static the Main() can now be called directly through the class name and there is no need to create the object to call it. So Main() is declared as static.

  Answered by     Sharad Gupta, Software Developer, Tripura Technologies, Hyderabad  | 03 28 2011 14:16:46 +0000
[ Delete ]
[ Edit ]
Not Rated

Program execution starts from Main(). S it should be called before the creation of any object. By using static the Main() can now be called directly through the class name and there is no need to create the object to call it. So Main() is declared as static.

  Answered by     Sharad Gupta, Software Developer, Tripura Technologies, Hyderabad  | 03 28 2011 14:07:30 +0000
[ Delete ]
[ Edit ]
Not Rated

Mr. Jagadeesh, Many language follows the OOPs concept so one Main OOPs concept is Every things should be in a Class, nothing should be outside the class. if you don't use the STATIC keyword before Main function then you have to  created the object of class, it will be outside so it destroys the OPPS concept. therefore we used the Static keyword before main (not only main in all function where we don't want to create the object of class)

[ Delete ]
[ Edit ]
Not Rated

static method is the Main method: When a program is launched, no instances of any class are present in memory. As the Main method is static, it can be called without creating an object and can then assume control of the program. It is the Main method's task to create the objects that the program requires to function correctly. Static Methods: Static methods are useful when creating functions that are not reliant on any instance of a class. Creating a Static Method: public static int CalculateMass(int density, int volume) { return density * volume; } Calling a Static Method: static void Main(string[] args) { int density = 50; int volume = 100; int mass = MassCalculator.CalculateMass(density, volume); Console.WriteLine("Mass: {0}", mass); // Outputs "Mass: 5000" } The static modifier can be used with classes, fields, methods, properties, operators, events and constructors, but cannot be used with indexers, destructors, or types other than classes. Reference:http://msdn.microsoft.com/en-us/library/98f28cdx(VS.80).aspx

 
Leading Search firm for Semiconductor and Telecom Companies
Leading Search firm for Semiconductor and Telecom Companies
Viewers also viewed
YES vs NO
 
253 referals 10 arguments, 250 views
Yes vs No
 
197 referals 6 arguments, 426 views
Indian constitute is old one and not suitable for our culture. vs It is copy of England and...
 
51 referals 10 arguments, 363 views
more...  
Unanswered Questions (64)
Dear all, I have joined one of the leading company on Aug 2010. Before joining, i had to sign a...
 
0 referals 0 answers, 0 views
Why day by day decreasing opportunities in pharma field More experience people they did't get...
 
0 referals 0 answers, 0 views
Hello! Mr.Harikumar. I have done my PG in MBA Finance (Chandigarh Business School affiliated to...
 
1 referals 0 answers, 0 views