Se ha denunciado esta presentación.
Utilizamos tu perfil de LinkedIn y tus datos de actividad para personalizar los anuncios y mostrarte publicidad más relevante. Puedes cambiar tus preferencias de publicidad en cualquier momento.
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:
 Variabl...
Java’s Rules for Identifiers
 Can be made of ONLY letters, digits, (_)
and $.
 Cannot start with a digit.
 Spaces are n...
Variables
 A variable is a name for a location in memory that
holds a value.
 Is used to store data input, data output, ...
Java Keywords
 abstract
 assert
 boolean
 break
 byte
 case
 catch
 char
 class
 continue
 default
 do
 super...
Declaring Variables
Syntax: datatype variableName
Example:
int i,j; //Declare i and j to
//be an integer variable;
double ...
Declaring Variables
 A variable declaration specifies the variable's
name and the type of information that it will hold
i...
Variable Initialization
 A variable can be given an initial value in the
declaration
int sum = 0;
int base = 32, max = 14...
Variable Initialization
//********************************************************************
// PianoKeys.java Author: L...
Variable Initialization
//********************************************************************
// PianoKeys.java Author: L...
Próxima SlideShare
Cargando en…5
×

Chapter 3.1

  • Inicia sesión para ver los comentarios

  • Sé el primero en recomendar esto

Chapter 3.1

  1. 1. DECLARING AND USING IDENTIFIERS, VARIABLES AND CONSTANT Chapter 3.1:
  2. 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. 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. 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. 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. 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. 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. 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. 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. 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.

×