SlideShare uma empresa Scribd logo
1 de 7
Variables and Methods Tips and Tricks
Jagriti Srivastava
Tips and Tricks
 Follow the naming Convention Rule
 Meaning full name
 Different variable different name in same scope
 Variables based on scopes
 No keyword no reserve word(remember the color)
 Don’t start with digit
 Single name is variable
 Verb or action is method followed by ()
 Small case with underscore and camel case are methods and variables
 Word with Capital letter at start is Class name
 All small letter in word is package
Tips and Tricks
 String firstName → variable to hold first name
 void saveName() → method
 Person → Class
Variable
 Class or instance variable
 Inside class with the scope within class
 Static variable
 Whose value doesn’t change
 Local variable
 Inside method with the scope within method
Methods
Static Method Non Static Method
Method with
Return type and
Argument
Method with no
Return type and
No Argument
Method with no
Return type and
Argument
Method with
Return type and
No Argument
Code Example
public class TestOne {
int n2 = 20; //class variable or instance variable
static int n3 = 30; //static variable
static char c1 ;
String str2;
public static void main(String[] args) {
int n1 = 10; //local variable
System.out.println("the value of a is : "+n1);
//System.out.println(n2);cant be called here because non static field cant be called inside static method
System.out.println(n3);
showValue(); //since this is static method
TestOne tOne = new TestOne();
tOne.display();
c1 = 'J';
System.out.println(c1);
}
public static void showValue(){//static method with no return type and no argument
System.out.println(n3);
//System.out.println(n1);cant be called here because local variable at main method
}
public void display(){//non static method with no return type and no argument
System.out.println(n2);
System.out.println(n3);
String str1 = "hello world";
System.out.println(str1);
str2 = "Hello test";
}
}
Output
 the value of a is : 10
 30
 30
 20
 30
 hello world
 J

Mais conteúdo relacionado

Mais procurados

Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract ClassOUM SAOKOSAL
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classesAnup Burange
 
OOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsOOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsBhathiya Nuwan
 
Slide 5 Class Diagram
Slide 5 Class DiagramSlide 5 Class Diagram
Slide 5 Class DiagramNiloy Rocker
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methodsShubham Dwivedi
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 eehomeworkping9
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variablessasi saseenthiran
 
Is Java seen as a pure object-oriented language or not?
Is Java seen as a pure object-oriented language or not?Is Java seen as a pure object-oriented language or not?
Is Java seen as a pure object-oriented language or not?NexSoftsys
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAhmed Nobi
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceOum Saokosal
 
Why Java is not a purely object oriented language?
Why Java is not a purely object oriented language?Why Java is not a purely object oriented language?
Why Java is not a purely object oriented language?NexSoftsys
 
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
 

Mais procurados (19)

Chapter 9 Abstract Class
Chapter 9 Abstract ClassChapter 9 Abstract Class
Chapter 9 Abstract Class
 
Class diagrams
Class diagramsClass diagrams
Class diagrams
 
Inner classes in java
Inner classes in javaInner classes in java
Inner classes in java
 
06 abstract-classes
06 abstract-classes06 abstract-classes
06 abstract-classes
 
OOP Concepets and UML Class Diagrams
OOP Concepets and UML Class DiagramsOOP Concepets and UML Class Diagrams
OOP Concepets and UML Class Diagrams
 
Slide 5 Class Diagram
Slide 5 Class DiagramSlide 5 Class Diagram
Slide 5 Class Diagram
 
5.1[1]
5.1[1]5.1[1]
5.1[1]
 
Java abstract class & abstract methods
Java abstract class & abstract methodsJava abstract class & abstract methods
Java abstract class & abstract methods
 
ITFT - Java
ITFT - JavaITFT - Java
ITFT - Java
 
116824015 java-j2 ee
116824015 java-j2 ee116824015 java-j2 ee
116824015 java-j2 ee
 
Abstract classes
Abstract classesAbstract classes
Abstract classes
 
Java Data Types and Variables
Java Data Types and VariablesJava Data Types and Variables
Java Data Types and Variables
 
Is Java seen as a pure object-oriented language or not?
Is Java seen as a pure object-oriented language or not?Is Java seen as a pure object-oriented language or not?
Is Java seen as a pure object-oriented language or not?
 
Differential equations intro
Differential equations introDifferential equations intro
Differential equations intro
 
Abstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and InterfacesAbstraction in java [abstract classes and Interfaces
Abstraction in java [abstract classes and Interfaces
 
Java Programming - Abstract Class and Interface
Java Programming - Abstract Class and InterfaceJava Programming - Abstract Class and Interface
Java Programming - Abstract Class and Interface
 
Why Java is not a purely object oriented language?
Why Java is not a purely object oriented language?Why Java is not a purely object oriented language?
Why Java is not a purely object oriented language?
 
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
 
Interfaces
InterfacesInterfaces
Interfaces
 

Semelhante a Variable and Methods in Java

Semelhante a Variable and Methods in Java (7)

03_Objects and Classes in java.pdf
03_Objects and Classes in java.pdf03_Objects and Classes in java.pdf
03_Objects and Classes in java.pdf
 
3.Classes&Objects.pptx
3.Classes&Objects.pptx3.Classes&Objects.pptx
3.Classes&Objects.pptx
 
CIS160 final review
CIS160 final reviewCIS160 final review
CIS160 final review
 
Concept of Classes in c++.ist mse16.pptx
Concept of Classes in c++.ist mse16.pptxConcept of Classes in c++.ist mse16.pptx
Concept of Classes in c++.ist mse16.pptx
 
Oop in kotlin
Oop in kotlinOop in kotlin
Oop in kotlin
 
OOP concepts
OOP conceptsOOP concepts
OOP concepts
 
Object Oriented Principles
Object Oriented PrinciplesObject Oriented Principles
Object Oriented Principles
 

Mais de jagriti srivastava

Mais de jagriti srivastava (15)

Map reduce with big data
Map reduce with big dataMap reduce with big data
Map reduce with big data
 
Oyo rooms
Oyo roomsOyo rooms
Oyo rooms
 
Information system of amazon
Information system of amazonInformation system of amazon
Information system of amazon
 
JavaScript Canvas
JavaScript CanvasJavaScript Canvas
JavaScript Canvas
 
Component diagram and Deployment Diagram
Component diagram and Deployment DiagramComponent diagram and Deployment Diagram
Component diagram and Deployment Diagram
 
Basic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time APIBasic java, java collection Framework and Date Time API
Basic java, java collection Framework and Date Time API
 
Form validation and animation
Form validation and animationForm validation and animation
Form validation and animation
 
Custom directive and scopes
Custom directive and scopesCustom directive and scopes
Custom directive and scopes
 
Angular directive filter and routing
Angular directive filter and routingAngular directive filter and routing
Angular directive filter and routing
 
Starting with angular js
Starting with angular js Starting with angular js
Starting with angular js
 
Angular introduction basic
Angular introduction basicAngular introduction basic
Angular introduction basic
 
Scannerclass
ScannerclassScannerclass
Scannerclass
 
Programming Workshop
Programming WorkshopProgramming Workshop
Programming Workshop
 
Java Nested class Concept
Java Nested class ConceptJava Nested class Concept
Java Nested class Concept
 
Java , A brief Introduction
Java , A brief Introduction Java , A brief Introduction
Java , A brief Introduction
 

Último

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slidevu2urc
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 

Último (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 

Variable and Methods in Java

  • 1. Variables and Methods Tips and Tricks Jagriti Srivastava
  • 2. Tips and Tricks  Follow the naming Convention Rule  Meaning full name  Different variable different name in same scope  Variables based on scopes  No keyword no reserve word(remember the color)  Don’t start with digit  Single name is variable  Verb or action is method followed by ()  Small case with underscore and camel case are methods and variables  Word with Capital letter at start is Class name  All small letter in word is package
  • 3. Tips and Tricks  String firstName → variable to hold first name  void saveName() → method  Person → Class
  • 4. Variable  Class or instance variable  Inside class with the scope within class  Static variable  Whose value doesn’t change  Local variable  Inside method with the scope within method
  • 5. Methods Static Method Non Static Method Method with Return type and Argument Method with no Return type and No Argument Method with no Return type and Argument Method with Return type and No Argument
  • 6. Code Example public class TestOne { int n2 = 20; //class variable or instance variable static int n3 = 30; //static variable static char c1 ; String str2; public static void main(String[] args) { int n1 = 10; //local variable System.out.println("the value of a is : "+n1); //System.out.println(n2);cant be called here because non static field cant be called inside static method System.out.println(n3); showValue(); //since this is static method TestOne tOne = new TestOne(); tOne.display(); c1 = 'J'; System.out.println(c1); } public static void showValue(){//static method with no return type and no argument System.out.println(n3); //System.out.println(n1);cant be called here because local variable at main method } public void display(){//non static method with no return type and no argument System.out.println(n2); System.out.println(n3); String str1 = "hello world"; System.out.println(str1); str2 = "Hello test"; } }
  • 7. Output  the value of a is : 10  30  30  20  30  hello world  J