MODULE 4: DATA TYPES

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

1/16

flashcard set

Earn XP

Description and Tags

Data Types

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

17 Terms

1
New cards

Data Types

  • set of values together with a set of operations

  • A type of data that can be stored

  • How much memory an item occupies

  • What types of operations can be performed on data

2
New cards

Java Data Types

Primitive data types & Reference data types

3
New cards

Primitive data types

A simple data type

4
New cards

Reference data types

Also known as Non-Primitive Data Type

More complex data types

5
New cards

Primitive Data Types

Integral, Floating, Textual, Logical

6
New cards

Integral Primitive Data Type

.byte, short, int, long

7
New cards

Floating Primitive Data Type

.float, double

8
New cards

Textual Primitive Data Type

.char

9
New cards

Logical Primitive Data Type

.boolean

10
New cards

String

  • The String data type is used to store a sequence of characters (text). 

  • String values must be surrounded by double quotes


11
New cards

Concatenation

  • A numeric variable is concatenated to a String using the plus sign ( + )

  • The entire expression becomes a String

  • The println() method can accept a number or String

12
New cards

Main difference between primitive and non-primitive data types are:

  • Primitive types are predefined (already defined) in Java. Non-primitive types are created by the programmer and is not defined by Java (except for String).

  • Non-primitive types can be used to call methods to perform certain operations, while primitive types cannot.

  • A primitive type has always a value, while non-primitive types can be null.

  • A primitive type starts with a lowercase letter, while non-primitive types starts with an uppercase letter.

  • The size of a primitive type depends on the data type, while non-primitive types have all the same size.

13
New cards

Type Conversion (Casting)

  • when you assign a value of one primitive data type to another type.

  • Used to avoid implicit type coercion

  • Expression evaluated first, then type converted to dataTypeName

  • Convert String to int or double

    Use methods from the built-in Java classes Integer and Double

14
New cards

Widening Casting (automatically), Narrowing Casting (manually)

two types of casting:

15
New cards

Widening Casting (automatically)

  • converting a smaller type to a larger type size

  • byte -> short -> char -> int -> long -> float -> double


16
New cards

Narrowing Casting (manually)

  • converting a larger type to a smaller size type

  • double -> float -> long -> int -> char -> short -> byte

17
New cards

Type-wrapper classes

  • Each primitive type has a corresponding class contained in the java.lang package

  • Include methods to process primitive type values

Integer.parseInt()

Double.parseDouble()