SlideShare a Scribd company logo
1 of 13
Java static keyword
Object Oriented Programming
Why main method (only) static in java?
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.
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 .
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.
The static can be:
static
Variables Methods Class Blocks Constructor!
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
Static Variables
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
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
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
Static Constructors
๏‚ด they are not allowed in Java.
Why ?? ๏Š Search.
The End
Thank You ๏Š

More Related Content

What's hot

String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)Anwar Hasan Shuvo
ย 
L21 io streams
L21 io streamsL21 io streams
L21 io streamsteach4uin
ย 
Methods in java
Methods in javaMethods in java
Methods in javachauhankapil
ย 
Wrapper class
Wrapper classWrapper class
Wrapper classkamal kotecha
ย 
constructors in java ppt
constructors in java pptconstructors in java ppt
constructors in java pptkunal kishore
ย 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptxvishal choudhary
ย 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in javaTalha mahmood
ย 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in JavaKurapati Vishwak
ย 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statementsKuppusamy P
ย 
Packages in java
Packages in javaPackages in java
Packages in javaKavitha713564
ย 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaMOHIT AGARWAL
ย 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloadinggarishma bhatia
ย 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)arvind pandey
ย 
Java string handling
Java string handlingJava string handling
Java string handlingSalman Khan
ย 

What's hot (20)

String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)
ย 
Java IO
Java IOJava IO
Java IO
ย 
L21 io streams
L21 io streamsL21 io streams
L21 io streams
ย 
Methods in java
Methods in javaMethods in java
Methods in java
ย 
Final keyword in java
Final keyword in javaFinal keyword in java
Final keyword in java
ย 
Wrapper class
Wrapper classWrapper class
Wrapper class
ย 
constructors in java ppt
constructors in java pptconstructors in java ppt
constructors in java ppt
ย 
Java Stack Data Structure.pptx
Java Stack Data Structure.pptxJava Stack Data Structure.pptx
Java Stack Data Structure.pptx
ย 
Two-dimensional array in java
Two-dimensional array in javaTwo-dimensional array in java
Two-dimensional array in java
ย 
Multiple inheritance possible in Java
Multiple inheritance possible in JavaMultiple inheritance possible in Java
Multiple inheritance possible in Java
ย 
Java Generics - by Example
Java Generics - by ExampleJava Generics - by Example
Java Generics - by Example
ย 
Method overloading
Method overloadingMethod overloading
Method overloading
ย 
Java conditional statements
Java conditional statementsJava conditional statements
Java conditional statements
ย 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
ย 
Packages in java
Packages in javaPackages in java
Packages in java
ย 
Abstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core JavaAbstract Class & Abstract Method in Core Java
Abstract Class & Abstract Method in Core Java
ย 
Constructor overloading & method overloading
Constructor overloading & method overloadingConstructor overloading & method overloading
Constructor overloading & method overloading
ย 
Core java complete ppt(note)
Core java  complete  ppt(note)Core java  complete  ppt(note)
Core java complete ppt(note)
ย 
Java string handling
Java string handlingJava string handling
Java string handling
ย 
STL in C++
STL in C++STL in C++
STL in C++
ย 

Viewers also liked

Java keywords
Java keywordsJava keywords
Java keywordsRavi_Kant_Sahu
ย 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keywordtanu_jaswal
ย 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiersSrinivas Reddy
ย 
03 objects and classes in java
03 objects and classes   in java03 objects and classes   in java
03 objects and classes in javaMrMazharJutt
ย 
Super keyword.23
Super keyword.23Super keyword.23
Super keyword.23myrajendra
ย 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in javaHitesh Kumar
ย 
Selenium ide material (2)
Selenium ide material (2)Selenium ide material (2)
Selenium ide material (2)Sriram Angajala
ย 
Fundamentals
FundamentalsFundamentals
Fundamentalsmyrajendra
ย 
Performance management system slide
Performance management system slidePerformance management system slide
Performance management system slideraizanamiza
ย 
William Bronchick Coaching
William Bronchick CoachingWilliam Bronchick Coaching
William Bronchick CoachingWilliamBronchick123
ย 
Abstract data types
Abstract data typesAbstract data types
Abstract data typesLuis Goldster
ย 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in javaHitesh Kumar
ย 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in javaHitesh Kumar
ย 
03 Java Language And OOP Part III
03 Java Language And OOP Part III03 Java Language And OOP Part III
03 Java Language And OOP Part IIIHari Christian
ย 
This keyword in java
This keyword in javaThis keyword in java
This keyword in javaHitesh Kumar
ย 
Presentation Portfolio
Presentation PortfolioPresentation Portfolio
Presentation PortfolioSteve Lee
ย 
Brown bag tfs best practices - slide share
Brown bag   tfs best practices - slide shareBrown bag   tfs best practices - slide share
Brown bag tfs best practices - slide shareJJ Bussert
ย 
Constructor in java
Constructor in javaConstructor in java
Constructor in javaPavith Gunasekara
ย 
Sermon Slide Deck: "The Best Present Ever" (John 3:16)
Sermon Slide Deck: "The Best Present Ever" (John 3:16)Sermon Slide Deck: "The Best Present Ever" (John 3:16)
Sermon Slide Deck: "The Best Present Ever" (John 3:16)New City Church
ย 

Viewers also liked (20)

Java keywords
Java keywordsJava keywords
Java keywords
ย 
Ppt on this and super keyword
Ppt on this and super keywordPpt on this and super keyword
Ppt on this and super keyword
ย 
Java Inner Classes
Java Inner ClassesJava Inner Classes
Java Inner Classes
ย 
Java access modifiers
Java access modifiersJava access modifiers
Java access modifiers
ย 
03 objects and classes in java
03 objects and classes   in java03 objects and classes   in java
03 objects and classes in java
ย 
Super keyword.23
Super keyword.23Super keyword.23
Super keyword.23
ย 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
ย 
Selenium ide material (2)
Selenium ide material (2)Selenium ide material (2)
Selenium ide material (2)
ย 
Fundamentals
FundamentalsFundamentals
Fundamentals
ย 
Performance management system slide
Performance management system slidePerformance management system slide
Performance management system slide
ย 
William Bronchick Coaching
William Bronchick CoachingWilliam Bronchick Coaching
William Bronchick Coaching
ย 
Abstract data types
Abstract data typesAbstract data types
Abstract data types
ย 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
ย 
Super keyword in java
Super keyword in javaSuper keyword in java
Super keyword in java
ย 
03 Java Language And OOP Part III
03 Java Language And OOP Part III03 Java Language And OOP Part III
03 Java Language And OOP Part III
ย 
This keyword in java
This keyword in javaThis keyword in java
This keyword in java
ย 
Presentation Portfolio
Presentation PortfolioPresentation Portfolio
Presentation Portfolio
ย 
Brown bag tfs best practices - slide share
Brown bag   tfs best practices - slide shareBrown bag   tfs best practices - slide share
Brown bag tfs best practices - slide share
ย 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
ย 
Sermon Slide Deck: "The Best Present Ever" (John 3:16)
Sermon Slide Deck: "The Best Present Ever" (John 3:16)Sermon Slide Deck: "The Best Present Ever" (John 3:16)
Sermon Slide Deck: "The Best Present Ever" (John 3:16)
ย 

Similar to Java static keyword

this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.pdfParvizMirzayev2
ย 
This and Static Keyword
This and Static KeywordThis and Static Keyword
This and Static KeywordDhrumil Panchal
ย 
25 java interview questions
25 java interview questions25 java interview questions
25 java interview questionsMehtaacademy
ย 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdfvenud11
ย 
Java Core
Java CoreJava Core
Java CoreGaurav Mehta
ย 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Sagar Verma
ย 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobGaruda Trainings
ย 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics PresentationOmid Sohrabi
ย 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core ParcticalGaurav Mehta
ย 
Unit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfUnit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfArpana Awasthi
ย 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interviewKuntal Bhowmick
ย 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in javaVishnu Suresh
ย 
Object oriented programming tutorial
Object oriented programming tutorialObject oriented programming tutorial
Object oriented programming tutorialGhulam Abbas Khan
ย 
Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptxAsifMulani17
ย 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardHari kiran G
ย 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDevLabs Alliance
ย 
Top 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETTop 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETDevLabs Alliance
ย 
Dev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetDev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetdevlabsalliance
ย 

Similar to Java static keyword (20)

this keyword in Java.pdf
this keyword in Java.pdfthis keyword in Java.pdf
this keyword in Java.pdf
ย 
This and Static Keyword
This and Static KeywordThis and Static Keyword
This and Static Keyword
ย 
1
11
1
ย 
25 java interview questions
25 java interview questions25 java interview questions
25 java interview questions
ย 
1669617800196.pdf
1669617800196.pdf1669617800196.pdf
1669617800196.pdf
ย 
Java Core
Java CoreJava Core
Java Core
ย 
Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3Statics in java | Constructors | Exceptions in Java | String in java| class 3
Statics in java | Constructors | Exceptions in Java | String in java| class 3
ย 
Basic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a jobBasic java important interview questions and answers to secure a job
Basic java important interview questions and answers to secure a job
ย 
Java Basics Presentation
Java Basics PresentationJava Basics Presentation
Java Basics Presentation
ย 
Chapter 8 java
Chapter 8 javaChapter 8 java
Chapter 8 java
ย 
Java Core Parctical
Java Core ParcticalJava Core Parctical
Java Core Parctical
ย 
Unit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdfUnit 2 Part 1 Constructors.pdf
Unit 2 Part 1 Constructors.pdf
ย 
Java questions for interview
Java questions for interviewJava questions for interview
Java questions for interview
ย 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in java
ย 
Object oriented programming tutorial
Object oriented programming tutorialObject oriented programming tutorial
Object oriented programming tutorial
ย 
Abstraction in java.pptx
Abstraction in java.pptxAbstraction in java.pptx
Abstraction in java.pptx
ย 
OCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference CardOCP Java (OCPJP) 8 Exam Quick Reference Card
OCP Java (OCPJP) 8 Exam Quick Reference Card
ย 
Dev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdetDev labs alliance top 20 basic java interview questions for sdet
Dev labs alliance top 20 basic java interview questions for sdet
ย 
Top 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDETTop 20 basic java interview questions for SDET
Top 20 basic java interview questions for SDET
ย 
Dev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdetDev labs alliance top 20 basic java interview question for sdet
Dev labs alliance top 20 basic java interview question for sdet
ย 

Recently uploaded

CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceanilsa9823
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
ย 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE9953056974 Low Rate Call Girls In Saket, Delhi NCR
ย 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
ย 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
ย 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธanilsa9823
ย 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
ย 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
ย 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
ย 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
ย 

Recently uploaded (20)

CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female serviceCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Badshah Nagar Lucknow best Female service
ย 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
ย 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
ย 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
ย 
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )๐Ÿ” 9953056974๐Ÿ”(=)/CALL GIRLS SERVICE
ย 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
ย 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
ย 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
ย 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
ย 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
ย 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
ย 
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธCALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online  โ˜‚๏ธ
CALL ON โžฅ8923113531 ๐Ÿ”Call Girls Kakori Lucknow best sexual service Online โ˜‚๏ธ
ย 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
ย 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
ย 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
ย 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
ย 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
ย 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
ย 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
ย 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
ย 

Java static keyword

  • 1. Java static keyword Object Oriented Programming
  • 2. Why main method (only) static in java?
  • 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. 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. 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. The static can be: static Variables Methods Class Blocks Constructor!
  • 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
  • 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. 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. 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. Static Constructors ๏‚ด they are not allowed in Java. Why ?? ๏Š Search.
  • 13. The End Thank You ๏Š

Editor's Notes

  1. //Program of static variable class Student8 { int rollno; String name; static String college ="ITS"; Student8(int r,String n) { rollno = r; name = n; } void display () { System.out.println(rollno+" "+name+" "+college); } public static void main(String args[]) { Student8 s1 = new Student8(111,"Karan"); Student8 s2 = new Student8(222,"Aryan"); System.out.println(college); s1.display(); s2.display(); } } ======================================= class Counter{ static int count=0;//will get memory when instance is created and try without static to see the difference Counter(){ count++; System.out.println(count); } public static void main(String args[]){ Counter c1=new Counter(); Counter c2=new Counter(); Counter c3=new Counter(); } }
  2. //Program of changing the common property of all objects(static field). class Student9{ int rollno; String name; static String college = "ITS"; static void change(){ college = "BBDIT"; } Student9(int r, String n){ rollno = r; name = n; } static void display (){System.out.println(rollno+" "+name+" "+college);} public static void main(String args[]){ change(); Student9 s1 = new Student9 (111,"Karan"); Student9 s2 = new Student9 (222,"Aryan"); Student9 s3 = new Student9 (333,"Sonoo"); s1.display(); s2.display(); s3.display(); } } ===================================== //Program to get cube of a given number by static method class Calculate{ static int cube(int x){ return x*x*x; } public static void main(String args[]){ int result=Calculate.cube(5); System.out.println(result); } }
  3. /*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.*/ class stClass{ //Static class class X{ String str ="Inside Class X"; } public static void main(String args[]) { stClass.X.str=โ€œahmed"; X.str="Inside Class Example1"; System.out.println("String stored in str is- "+ X.str); } }
  4. class Stblocks{ static int num=5; static String mystr; static{ num = 97; mystr = "Static keyword in Java"; } public static void main(String args[]) { System.out.println("Value of num="+num); System.out.println("Value of mystr="+mystr); } } =========================================== class Stblocks2{ static int num; static String mystr; //First Static block static{ System.out.println("Static Block 1"); num = 68; mystr = "Block1"; } //Second static block static{ System.out.println("Static Block 2"); num = 98; mystr = "Block2"; } public static void main(String args[]) { System.out.println("Value of num="+num); System.out.println("Value of mystr="+mystr); } }