SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

Slide 5 Class Diagram
Slide 5 Class DiagramSlide 5 Class Diagram
Slide 5 Class Diagram
Niloy Rocker
 

What's hot (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
 

Similar to Variable and Methods in Java (8)

JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx
JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptxJAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx
JAVA METHOD AND FUNCTION DIVIDE AND SHORT.pptx
 
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
 

More from jagriti srivastava

More from 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
 

Recently uploaded

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
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
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

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