0% found this document useful (0 votes)
35 views13 pages

Identifiers Data Types Literals Escape Sequence

This document provides an introduction to some key fundamentals of Java programming, including identifiers, data types, literals, and escape sequences. It discusses the rules for identifiers and the eight primitive data types in Java (byte, short, int, long, float, double, char, boolean). It also covers integer, floating-point, character, boolean, and string literals as well as escape sequences.

Uploaded by

manojabhole
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views13 pages

Identifiers Data Types Literals Escape Sequence

This document provides an introduction to some key fundamentals of Java programming, including identifiers, data types, literals, and escape sequences. It discusses the rules for identifiers and the eight primitive data types in Java (byte, short, int, long, float, double, char, boolean). It also covers integer, floating-point, character, boolean, and string literals as well as escape sequences.

Uploaded by

manojabhole
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 13

Fundamentals of Java

Programming
• Identifiers

• Data Types

• Literals

• Escape Sequence
Identifiers - Symbolic Names
• Identifier are used to name classes, variables
and methods.
• Identifier Rules:
• Must start with a "Java letter"

• A - Z, a - z, _, $, and Unicode letters


• Can contain essentially any number of Java

letters and digits, but no spaces


• Case sensitive!!

• Number1 and number1 are different!


• Cannot be keywords or reserved words
Data Types
• For all data, assign a name (identifier) and a data
type
• Data type tells compiler:
• How much memory to allocate

• Format in which to store data

• Types of operations you will perform on data

• Compiler monitors use of data


• Java is a "strongly typed" language

• Java "primitive data types"


byte, short, int, long, float, double, char,
boolean
Primitive Types
• There are exactly eight primitive data types in Java
• Four of them represent integers
• byte, short, int, long
• Two of them represent floating point numbers
• float, double
• One of them represents characters
• char
• And one of them represents boolean values
• boolean
Integer Types - Whole Numbers
Type Size Minimum Value Maximum Value
in Bytes
byte 1 -128 127
short 2 -32,768 32,767
int 4 -2, 147, 483, 648 2, 147, 483, 647
long 8 -9,223,372,036,854,775,808 9,223,372,036,854,775,807

Example declarations:
int numPlayers, highScore, diceRoll;
short xCoordinate, yCoordinate;
byte ageInYears;
long cityPopulation;
Floating-Point Data Types
Type Size Minimum Value Maximum Value
in Bytes
float 4 1.4E-45 3.4028235E38
double 8 4.9E-324 1.7976931348623157E308

Example declarations:
float salesTax;
double interestRate;
double paycheck, sumSalaries;
char Data Type
Type Size Minimum Value Maximum Value
in Bytes
char 2 character character
encoded as 0 encoded as FFFF

Example declarations:
char finalGrade;
char newline, tab, doubleQuotes;
boolean Data Type
• Two values only:
true
false
• Used for decision making or as "flag"
variables
• Example declarations:
boolean isEmpty;
boolean passed, failed;
Integer Literals
• int, short, byte
• Optional initial sign (+ or -) followed by digits 0
– 9 in any combination.
• long
• Optional initial sign (+ or -) followed by digits
0–9 in any combination, terminated with an L
or l.
Floating-Point Literals
• float
• Optional initial sign (+ or -) followed by a floating-point
number in fixed or scientific format, terminated by an F
or f.
• double
• Optional initial sign (+ or -) followed by a floating-point
number in fixed or scientific format.
• Commas, dollar signs, and percent signs (%)
cannot be used in integer or floating-point literals
char and boolean Literals
• char
• Any printable character enclosed in single
quotes
• A decimal value from 0 – 65535

• boolean
true or false
String Literals
• String is actually a class, not a basic data type;
String variables are objects
• String literal: text contained within double quotes.
• Example of String literals:
"Hello"
"Hello world"
"The value of x is “
Escape Sequences
• To include a special character in a String, use
an escape sequence
Character Escape Sequence
Newline \n
Tab \t
Double quotes \"
Single quote \'
Backslash \\
Backspace \b
Carriage return \r
Form feed \f

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy