SlideShare a Scribd company logo
DECLARING AND USING
IDENTIFIERS, VARIABLES AND
CONSTANT
Chapter 3.1:
 Name of things such as variables,
constants, name of classes and
methods, that appears in programs.
 Example:
 Variable: num1
 Constant: PIE
 Method: countNum()
Identifiers
Java’s Rules for Identifiers
 Can be made of ONLY letters, digits, (_)
and $.
 Cannot start with a digit.
 Spaces are not permitted inside identifiers.
 Cannot use reserved words.
 e.g: int,public, throws,return
 An identifier cannot be true, false, or
null.
 They are case sensitive.
 An identifier can be of any length.
Variables
 A variable is a name for a location in memory that
holds a value.
 Is used to store data input, data output, or
intermediate data
 Representing data of a certain type
 Content may change during program execution.
 Must be declared before it can be used.
 May not be automatically initialized.
 If new value is assigned, old one is destroyed.
 Value can only be changed by an assignment
statement or an input (read) statement.
Java Keywords
 abstract
 assert
 boolean
 break
 byte
 case
 catch
 char
 class
 continue
 default
 do
 super
 switch
 synchronized
 this
 throws
 transient
 try
 void
 volatile
 while
• double
• else
• enum
• extends
• for
• final
• finally
• float
• if
• implements
• import
• instanceof
• int
• interface
• long
• native
• new
• package
• private
• protected
• public
• return
• short
• static
• strictfp*
Declaring Variables
Syntax: datatype variableName
Example:
int i,j; //Declare i and j to
//be an integer variable;
double sale; //Declare sale to
// be a double variable;
char first; // Declare first to be a
// character variable;
String str; // Declare str to be a
//String variable;
Declaring Variables
 A variable declaration specifies the variable's
name and the type of information that it will hold
int total;
int count, temp, result;
Multiple variables can be created in one declaration
data type variable name
Variable Initialization
 A variable can be given an initial value in the
declaration
int sum = 0;
int base = 32, max = 149;
 When a variable is referenced in a program, its
current value is used
 See PianoKeys.java
Variable Initialization
//********************************************************************
// PianoKeys.java Author: Lewis/Loftus
//
// Demonstrates the declaration, initialization, and use of an
// integer variable.
//********************************************************************
public class PianoKeys
{
//-----------------------------------------------------------------
// Prints the number of keys on a piano.
//-----------------------------------------------------------------
public static void main (String[] args)
{
int keys = 88;
System.out.println ("A piano has " + keys + " keys.");
}
}
Variable Initialization
//********************************************************************
// PianoKeys.java Author: Lewis/Loftus
//
// Demonstrates the declaration, initialization, and use of an
// integer variable.
//********************************************************************
public class PianoKeys
{
//-----------------------------------------------------------------
// Prints the number of keys on a piano.
//-----------------------------------------------------------------
public static void main (String[] args)
{
int keys = 88;
System.out.println ("A piano has " + keys + " keys.");
}
}
Output
A piano has 88 keys.

More Related Content

PPT
Generic programming in java
anshu_atri
 
PPTX
Module 3 : using value type variables
Prem Kumar Badri
 
PDF
C Sharp: Basic to Intermediate Part 01
Zafor Iqbal
 
PDF
Doppl development iteration #4
Diego Perini
 
PDF
Ma3696 Lecture 3
Brunel University
 
PDF
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
PPT
Md04 flow control
Rakesh Madugula
 
PPTX
.Net F# Generic class
DrRajeshreeKhande
 
Generic programming in java
anshu_atri
 
Module 3 : using value type variables
Prem Kumar Badri
 
C Sharp: Basic to Intermediate Part 01
Zafor Iqbal
 
Doppl development iteration #4
Diego Perini
 
Ma3696 Lecture 3
Brunel University
 
Lesson 02 python keywords and identifiers
Nilimesh Halder
 
Md04 flow control
Rakesh Madugula
 
.Net F# Generic class
DrRajeshreeKhande
 

What's hot (19)

PPTX
#OOP_D_ITS - 8th - Class Diagram
Hadziq Fabroyir
 
PPTX
PL/SQL Introduction
Phanindra Oruganti
 
DOCX
C# language basics (Visual studio)
rnkhan
 
PPTX
Variable and constants in Vb.NET
Jaya Kumari
 
PPTX
Scalar expressions and control structures in perl
sana mateen
 
PPTX
Keywords, identifiers and data type of vb.net
Jaya Kumari
 
PPTX
Swift Generics
Haunshila Prasad Yadav
 
PPTX
Vb decision making statements
pragya ratan
 
PDF
Javapolymorphism
karthikenlume
 
PPTX
Inheritance
Jaya Kumari
 
PPTX
Polymorphism
Prof .Pragati Khade
 
PPTX
Decisions
nicky_walters
 
PPSX
Control Structures in Visual Basic
Tushar Jain
 
PPSX
Conditional statement
Maxie Santos
 
PPTX
Std 12 computer chapter 8 classes and object in java (part 2)
Nuzhat Memon
 
PPT
If-else and switch-case
Manash Kumar Mondal
 
PPTX
Advanced Python : Static and Class Methods
Bhanwar Singh Meena
 
PPT
Codings Standards
Philip Johnson
 
PPTX
Basic concept of class, method , command line-argument
Suresh Mohta
 
#OOP_D_ITS - 8th - Class Diagram
Hadziq Fabroyir
 
PL/SQL Introduction
Phanindra Oruganti
 
C# language basics (Visual studio)
rnkhan
 
Variable and constants in Vb.NET
Jaya Kumari
 
Scalar expressions and control structures in perl
sana mateen
 
Keywords, identifiers and data type of vb.net
Jaya Kumari
 
Swift Generics
Haunshila Prasad Yadav
 
Vb decision making statements
pragya ratan
 
Javapolymorphism
karthikenlume
 
Inheritance
Jaya Kumari
 
Polymorphism
Prof .Pragati Khade
 
Decisions
nicky_walters
 
Control Structures in Visual Basic
Tushar Jain
 
Conditional statement
Maxie Santos
 
Std 12 computer chapter 8 classes and object in java (part 2)
Nuzhat Memon
 
If-else and switch-case
Manash Kumar Mondal
 
Advanced Python : Static and Class Methods
Bhanwar Singh Meena
 
Codings Standards
Philip Johnson
 
Basic concept of class, method , command line-argument
Suresh Mohta
 
Ad

Similar to Chapter 3.1 (20)

PPTX
Learning Java 2 - Variables, Data Types and Operators
MinhNguyen1493
 
PPT
Md03 - part3
Rakesh Madugula
 
PDF
Annotations in Java with Example.pdf
SudhanshiBakre1
 
PPTX
Structured Languages
Mufaddal Nullwala
 
PPTX
C PROGRAMMING LANGUAGE
PRASANYA K
 
PPTX
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
PPTX
C Programming and Data structure C Programming and Data structures
UdhayaSankar13
 
PPTX
cs3362 c programming and data structures
UdhayaSankar13
 
PDF
Lecture 2 keyword of C Programming Language
SURAJ KUMAR
 
PDF
POLITEKNIK MALAYSIA
Aiman Hud
 
PPT
Introduction to-programming
BG Java EE Course
 
PPT
Java: Primitive Data Types
Tareq Hasan
 
PDF
2.Types_Variables_Functions.pdf
TrnThBnhDng
 
PPTX
Data Types, Variables, and Constants in C# Programming
Sherwin Banaag Sapin
 
PPTX
Chapter 3.4
sotlsoc
 
PDF
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
dinesh620610
 
DOCX
Programming in c plus plus3
AA Coaching Academy
 
PPT
Unit 1: Primitive Types - Variables and Datatypes
agautham211
 
PDF
2.Lesson Plan - Java Variables and Data types.pdf.pdf
AbhishekSingh757567
 
Learning Java 2 - Variables, Data Types and Operators
MinhNguyen1493
 
Md03 - part3
Rakesh Madugula
 
Annotations in Java with Example.pdf
SudhanshiBakre1
 
Structured Languages
Mufaddal Nullwala
 
C PROGRAMMING LANGUAGE
PRASANYA K
 
Topic-5_-Programming-Fundamentals-Part-2.pptx
HaroldOmega1
 
C Programming and Data structure C Programming and Data structures
UdhayaSankar13
 
cs3362 c programming and data structures
UdhayaSankar13
 
Lecture 2 keyword of C Programming Language
SURAJ KUMAR
 
POLITEKNIK MALAYSIA
Aiman Hud
 
Introduction to-programming
BG Java EE Course
 
Java: Primitive Data Types
Tareq Hasan
 
2.Types_Variables_Functions.pdf
TrnThBnhDng
 
Data Types, Variables, and Constants in C# Programming
Sherwin Banaag Sapin
 
Chapter 3.4
sotlsoc
 
PROGRAMMING IN C UNIT II.pdfFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF
dinesh620610
 
Programming in c plus plus3
AA Coaching Academy
 
Unit 1: Primitive Types - Variables and Datatypes
agautham211
 
2.Lesson Plan - Java Variables and Data types.pdf.pdf
AbhishekSingh757567
 
Ad

More from sotlsoc (20)

PPTX
Chapter 2.0 new
sotlsoc
 
PPTX
Chapter 1.0 new
sotlsoc
 
PPTX
Chapter 3.0 new
sotlsoc
 
PPTX
Chapter 6.5 new
sotlsoc
 
PPTX
Chapter 11.1
sotlsoc
 
PPTX
Chapter 10.3
sotlsoc
 
PPTX
Chapter 11.4
sotlsoc
 
PPTX
Chapter 11.3
sotlsoc
 
PPTX
Chapter 11.5
sotlsoc
 
PPTX
Chapter 11.2
sotlsoc
 
PPTX
Chapter 11.0
sotlsoc
 
PPTX
Chapter 10.2
sotlsoc
 
PPTX
Chapter 10.1
sotlsoc
 
PPTX
Chapter 8.0
sotlsoc
 
PPTX
Chapter 10.0
sotlsoc
 
PPTX
Chapter 9.3
sotlsoc
 
PPTX
Chapter 9.4
sotlsoc
 
PPTX
Chapter 9.1
sotlsoc
 
PPTX
Chapter 8.1
sotlsoc
 
PPTX
Chapter 9.0
sotlsoc
 
Chapter 2.0 new
sotlsoc
 
Chapter 1.0 new
sotlsoc
 
Chapter 3.0 new
sotlsoc
 
Chapter 6.5 new
sotlsoc
 
Chapter 11.1
sotlsoc
 
Chapter 10.3
sotlsoc
 
Chapter 11.4
sotlsoc
 
Chapter 11.3
sotlsoc
 
Chapter 11.5
sotlsoc
 
Chapter 11.2
sotlsoc
 
Chapter 11.0
sotlsoc
 
Chapter 10.2
sotlsoc
 
Chapter 10.1
sotlsoc
 
Chapter 8.0
sotlsoc
 
Chapter 10.0
sotlsoc
 
Chapter 9.3
sotlsoc
 
Chapter 9.4
sotlsoc
 
Chapter 9.1
sotlsoc
 
Chapter 8.1
sotlsoc
 
Chapter 9.0
sotlsoc
 

Recently uploaded (20)

PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PDF
Virat Kohli- the Pride of Indian cricket
kushpar147
 
PDF
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
PPTX
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
DOCX
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
PPTX
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PDF
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
PPTX
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PPTX
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
PPTX
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
PPTX
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Virat Kohli- the Pride of Indian cricket
kushpar147
 
Antianginal agents, Definition, Classification, MOA.pdf
Prerana Jadhav
 
Artificial-Intelligence-in-Drug-Discovery by R D Jawarkar.pptx
Rahul Jawarkar
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
Modul Ajar Deep Learning Bahasa Inggris Kelas 11 Terbaru 2025
wahyurestu63
 
An introduction to Prepositions for beginners.pptx
drsiddhantnagine
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Review of Related Literature & Studies.pdf
Thelma Villaflores
 
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
Python-Application-in-Drug-Design by R D Jawarkar.pptx
Rahul Jawarkar
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 
20250924 Navigating the Future: How to tell the difference between an emergen...
McGuinness Institute
 
CARE OF UNCONSCIOUS PATIENTS .pptx
AneetaSharma15
 

Chapter 3.1

  • 1. DECLARING AND USING IDENTIFIERS, VARIABLES AND CONSTANT Chapter 3.1:
  • 2.  Name of things such as variables, constants, name of classes and methods, that appears in programs.  Example:  Variable: num1  Constant: PIE  Method: countNum() Identifiers
  • 3. Java’s Rules for Identifiers  Can be made of ONLY letters, digits, (_) and $.  Cannot start with a digit.  Spaces are not permitted inside identifiers.  Cannot use reserved words.  e.g: int,public, throws,return  An identifier cannot be true, false, or null.  They are case sensitive.  An identifier can be of any length.
  • 4. Variables  A variable is a name for a location in memory that holds a value.  Is used to store data input, data output, or intermediate data  Representing data of a certain type  Content may change during program execution.  Must be declared before it can be used.  May not be automatically initialized.  If new value is assigned, old one is destroyed.  Value can only be changed by an assignment statement or an input (read) statement.
  • 5. Java Keywords  abstract  assert  boolean  break  byte  case  catch  char  class  continue  default  do  super  switch  synchronized  this  throws  transient  try  void  volatile  while • double • else • enum • extends • for • final • finally • float • if • implements • import • instanceof • int • interface • long • native • new • package • private • protected • public • return • short • static • strictfp*
  • 6. Declaring Variables Syntax: datatype variableName Example: int i,j; //Declare i and j to //be an integer variable; double sale; //Declare sale to // be a double variable; char first; // Declare first to be a // character variable; String str; // Declare str to be a //String variable;
  • 7. Declaring Variables  A variable declaration specifies the variable's name and the type of information that it will hold int total; int count, temp, result; Multiple variables can be created in one declaration data type variable name
  • 8. Variable Initialization  A variable can be given an initial value in the declaration int sum = 0; int base = 32, max = 149;  When a variable is referenced in a program, its current value is used  See PianoKeys.java
  • 9. Variable Initialization //******************************************************************** // PianoKeys.java Author: Lewis/Loftus // // Demonstrates the declaration, initialization, and use of an // integer variable. //******************************************************************** public class PianoKeys { //----------------------------------------------------------------- // Prints the number of keys on a piano. //----------------------------------------------------------------- public static void main (String[] args) { int keys = 88; System.out.println ("A piano has " + keys + " keys."); } }
  • 10. Variable Initialization //******************************************************************** // PianoKeys.java Author: Lewis/Loftus // // Demonstrates the declaration, initialization, and use of an // integer variable. //******************************************************************** public class PianoKeys { //----------------------------------------------------------------- // Prints the number of keys on a piano. //----------------------------------------------------------------- public static void main (String[] args) { int keys = 88; System.out.println ("A piano has " + keys + " keys."); } } Output A piano has 88 keys.