Java Basics (Data Types, Variables, Literals)

0.0(0)
studied byStudied by 0 people
full-widthCall with Kai
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/21

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

22 Terms

1
New cards

Data Types

Describe possible operations on the data and the storage method. In Java, they are classified into primitive (standard) and abstract (derived) data types.

2
New cards

Primitive Data Types

Built into the Java language, not objects, and have no methods. Includes byte, short, int, long, float, double, char, boolean.

3
New cards

Byte

Smallest integer type, stores values from -128 to 127, size 8-bit.

4
New cards

Short

Integer type, range -32,768 to 32,767, size 16-bit.

5
New cards

Int

Most commonly used integer type, range -2,147,483,648 to 2,147,483,647, size 32-bit.

6
New cards

Long

Large integer type, suffix L must be added, size 64-bit.

7
New cards

Float

Single precision floating-point, used for fractional numbers, suffix f required, size 32-bit.

8
New cards

Double

Double precision floating-point, default for decimals in Java, size 64-bit.

9
New cards

Char

Stores a single character (Unicode), size 16-bit, range 0 to 65,535.

10
New cards

Boolean

Logical type with only true or false values, size 1-bit.

11
New cards

Abstract Data Types

Based on primitive types but with more functionality. Example: String, used to store characters, symbols, and words.

12
New cards

Variable

A named memory location that stores data, which can change during program execution.

13
New cards

Constant

Similar to variables but values cannot be changed once assigned.

14
New cards

Variable Naming Rules

Must be meaningful, unique, start with a letter, dollar sign, or underscore, cannot use keywords, and avoid symbols/spaces.

15
New cards

Variable Naming Conventions

Use meaningful names, start with lowercase, use camelCase for multi-word names (e.g., empGender).

16
New cards

Default Values of Variables

Primitive types have defaults (e.g., int = 0, float = 0.0, boolean = false, char = '\u0000'). Objects (like Strings) default to null.

17
New cards

Literals

Constant values directly assigned to variables.

18
New cards

Boolean Literals

Types of Literals

true, false

19
New cards

Integer Literals

Types of Literals

Decimal, octal (0 prefix), hexadecimal (0x prefix), binary (0b prefix)

20
New cards

Floating-point Literals

Types of Literals

Numbers with decimal, require F/f suffix for floats

21
New cards

Character Literals

Types of Literals

Single characters in ' ', can use Unicode or escape sequences ('\n', '\t')

22
New cards

String Literals

Types of Literals

Sequence of characters in " "