Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

Study Note on Java - Constants, Variables and Data Types

Rating
-
Sold
-
Pages
5
Uploaded on
28-02-2022
Written in
2021/2022

Study Note on Java - Constants, Variables and Data Types

Institution
Course

Content preview

Chapter 4: Constants, Variables, and Data Types

4.1 Constants
Constants refer to fixed values that do not change during the execution of program.

JAVA CONSTANTS




Numeric Constants Character Constants



Integer Real Character String
Constants Constants Constants Constants

4.1.1 Integer Constants
 An integer constant refers to a sequence of digits.
 3 types: Decimal Integer, Octal Integer and Hexadecimal Integer
 Decimal Integer
o Consist of a set of digits, 0 through 9, preceded by an optional minus sign. Eg: 123, -321,
0, 654321
o Embedded spaces, commas, and non-digit characters are not permitted between digits.
Eg: 15 750; 20,000 ; $1000
 Octal Integer Constants
o Consists of any combination of digits from the set 0 through 7, with a leading O
Eg: O37, O551
 Hexadecimal Integer
o A sequence of digits preceded by Ox or OX
o Also include alphabets A through F or a through f
o Letter A through F represents the numbers 10 through 15
Eg: OX2, OX9F
4.1.2 Real Constants
 The quantities represented by numbers containing fractional parts are called Real constants.
Eg: 0.0083 , -0.75
 Are shown in decimal notation, having a whole number followed by a decimal point and the
fractional part.
 Possible that the number may not have digits before the decimal point or digits after the
decimal point.
Eg: .95 , -.71
 May also be expressed in exponential notation.
 General form is:
Mantissa e exponent
o Mantissa is either a real number expressed in decimal notation or an integer
o Exponent is an integer with an optional plus or minus sign

, o The letter ‘e’ separating the mantissa and the exponent and can be written either in
lowercase or uppercase.

4.1.3 Single Character Constants
 Contains a single character enclosed within a pair of single quote marks.
Eg: ‘K’

4.1.4 String Constants
 Is a sequence of characters enclosed between double quotes.
Eg: “Hello Java”

4.2 Variables
 A variable is an identifier that denotes a storage location used to store a data value.
 Unlike constants that remain unchanged during the execution of a program, a variable may take
different values at different times during the execution of the program.
 A variable name can be chosen by the programmer in a meaningful way to reflect what it
represents in the program.
 Variable names may consist of alphabets, digits, the underscore, and dollar characters
o Must not begin with a digit
o Uppercase and lowercase are distinct.
o Should not be a keyword.
o White space is not allowed.
o Variable names can be of any length

4.3 Data Types




4.3.1 Integer Types
 Can hold only whole numbers
 Supports 4 types: byte, short, int and long
 Size and range of Integer Types

Connected book

Written for

Institution
Course

Document information

Uploaded on
February 28, 2022
Number of pages
5
Written in
2021/2022
Type
Class notes
Professor(s)
Mrs. prabitha
Contains
All classes

Subjects

$7.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
sinithomas

Also available in package deal

Get to know the seller

Seller avatar
sinithomas Study Notes
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
4 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions