O slideshow foi denunciado.
Utilizamos seu perfil e dados de atividades no LinkedIn para personalizar e exibir anúncios mais relevantes. Altere suas preferências de anúncios quando desejar.

Java static keyword

1.850 visualizações

Publicada em

the program in the below link
https://drive.google.com/open?id=0B4tMuSViaMcVLUxqVV9HY3ZDZkU
the name of progam that use in the slide with a hint in the up-right of the slide
static keyword
oop

Publicada em: Software
  • Seja o primeiro a comentar

Java static keyword

  1. 1. Java static keyword Object Oriented Programming
  2. 2. Why main method (only) static in java?
  3. 3. how objects are created?  Basic Steps of how objects are created 1. Class is loaded by JVM 2. Static variable and methods are loaded and initialized and available for use 3. Constructor is called to instantiate the non static variables 4. Non static variables and methods are now available • As all the non static variable are available only after the constructor is called, there is a restriction on using non static variable in static methods.
  4. 4. what’s the use of static Keyword and Why?  The static keyword is used when a member variable of a class has to be shared between all the instances of the class.  All static variables and methods belong to the class and not to any instance of the class Why ?  The static keyword in java is used for memory management mainly.  Static keyword is used to save your time and typing .
  5. 5. Static and Non-static  We can access static variables without creating an object of the class  As they are already available at class loading time.  We cannot use non static methods and variables without creating an object of the class as they are bound to the instance of the class.  They are initialized by the constructor when we create the object using new operator.
  6. 6. The static can be: static Variables Methods Class Blocks Constructor!
  7. 7. Static Variables  The static variable can be used to refer the common property of all objects (that is not unique for each object).  The static variable gets memory only once in class area at the time of class loading.  Advantage of static variable :- It makes your program memory efficient (i.e. it saves memory). Student8.java Counter.java
  8. 8. Static Variables
  9. 9. Static Methods  A static method belongs to the class rather than object of a class.  A static method can be invoked without the need for creating an instance of a class.  static method can access static data member and can change the value of it. Student9.java Calculate.java
  10. 10. Static Classes (Only Nested Class)  A Class can be made static only if it is a nested Class.  The nested static class can be accessed without having an object of outer class. StClass.java
  11. 11. Static Blocks  Static block is mostly used for changing the default values of static variables.  This block gets executed when the class is loaded in the memory.  A class can have multiple Static blocks, which will execute in the same sequence in which they have been written into the program. Stblocks.java Stblocks2.java
  12. 12. Static Constructors  they are not allowed in Java. Why ??  Search.
  13. 13. The End Thank You 

×