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
Other

Quick revision during exams

Rating
-
Sold
-
Pages
14
Uploaded on
25-02-2026
Written in
2025/2026

This is a JAVA notes

Institution
Course

Content preview

Object Oriented Programming with JAVA BCS306A


CHAPTER 2
Data Types, Variables and Arrays
Java Is a Strongly Typed Language
➢ It is important to state at the outset that Java is a strongly typed language. Indeed, part of
Java’s safety and robustness comes from this fact
➢ First, every variable has a type, every expression has a type, and every type is strictly
defined. Second, all assignments, whether explicit or via parameter passing in method calls,
are checked for type compatibility.
➢ There are no automatic coercions or conversions of conflicting types as in some languages. The
Java compiler checks all expressions and parameters to ensure that the types are compatible. Any
type mismatches are errors that must be corrected before the compiler will finish compiling the
class.

2.1 The Primitive Types
➢ Java defines eight primitive types of data: byte, short, int, long, char, float, double, and
boolean. These can be put in four groups:
• Integers: This group includes byte, short, int, and long, which are for whole-valued signed
numbers.
• Floating-point numbers: This group includes float and double, which represent numbers with
fractional precision.
• Characters: This group includes char, which represents symbols in a character set, like letters
and numbers.
• Boolean: This group includes boolean, which is a special type for representing true/false
values.

1. Integer
➢ Java defines four integer types: byte, short, int, and long.
➢ All of these are signed, positive and negative values.
➢ Java does not support unsigned, positive-only integers.
➢ The width and ranges of these integer types vary widely, as shown in this table:




Byte
➢ The smallest integer type is byte.
➢ This is a signed 8-bit type that has a range from–128 to127.
➢ Variables of type byte are especially useful when you’re working with a stream of data from a
network or Binary data file.
➢ Byte variables are declared by use of the byte keyword. For example, the following declares two
byte variables called b and c:
byte b, c;
1

, Object Oriented Programming with JAVA BCS306A

Short
➢ short is a signed16-bit type.
➢ It has a range from–32,768 to 32,767.
➢ It is probably the least-used Java type.
➢ Here are some examples of short variable declarations:
short s, t;

Int
➢ The most commonly used integer type is int.
➢ It is a signed 32-bit type that has a range from –2,147,483,648 to 2,147,483,647.
➢ In addition to other uses, variables of type int are commonly employed to control loops and to
index arrays.
➢ Here are some examples of int variable declarations:
int a,b,c;

Long
➢ Long is a signed 64-bit type and is useful for those occasions where an int type is not large
enough to hold the desired value. This makes it useful when big, whole numbers are needed.


2. Floating-Point Types
➢ Floating-point numbers, also known as real numbers, are used when evaluating expressions that
require fractional precision.
➢ For example, calculations such as square root, or transcendental such as sine and cosine, result
in a value whose precision requires a floating-point type.
➢ Java implements the standard (IEEE–754) set of floating-point types and operators. There are
two kinds of floating-point types, float and double, which represent single-and double-precision
numbers, respectively.




Float
➢ The type float specifies a single-precision value that uses 32 bits of storage.
➢ Single precision is faster on some processors and takes half as much space as double precision,
but will become imprecise when the values are either very large or very small.
➢ Variables of type float are useful when you need a fractional component, but don’t require a
large degree of precision. For example,
float hightemp, lowtemp;

Double
➢ Double precision, as denoted by the double keyword, uses 64 bits to store a value.
➢ Double precision is actually faster than single precision on some modern processors that have
been optimized for high-speed mathematical calculations.




2

Written for

Institution
Course

Document information

Uploaded on
February 25, 2026
Number of pages
14
Written in
2025/2026
Type
OTHER
Person
Unknown

Subjects

$10.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
yashaswinir

Get to know the seller

Seller avatar
yashaswinir
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
2 months
Number of followers
0
Documents
4
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

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