Other primitives and Strings

Introduzione a Java

Jim White

Java Developer

Primitives continued

char and boolean data types

Introduzione a Java

booleans

boolean values are true and false

Introduzione a Java

booleans - how they work?

Is the item on sale? Yes = true, No = false

Introduzione a Java

booleans - naming convention

Boolean variable names should start with is, such as isOnSale

Introduzione a Java

char

  • Stores single character
  • Wrapped in single quotes
// Examples
char initial = 'J';

char size = 'M';

char ampersand = '&';
Introduzione a Java

char versus String

char

  • Single quotes

    char initial = 'J';
    
  • Primitive data type

  • Stores one character

String

  • Double quotes

    String name = "Jim";
    
  • Not a primitive, collection of characters

  • Stores text
Introduzione a Java

Strings

  • Collection of characters inside double quotes
  • Any number of characters
    • Single character in double quotes is String
    • Single character in single quotes is char
  • Not primitives
    • Come with built-in functionality

Primitives are like ingredients, while a String is a meal made from those ingredients

Introduzione a Java

Storing Strings

String variableName = "Text to store";
//Example
String myName = "Jim White";

Remember to use double quotes

Introduzione a Java

Summary of primitives

Table of primitive types

Introduzione a Java

Summary of Strings

Strings are a collection of characters using double quotes

Introduzione a Java

Let's practice!

Introduzione a Java

Preparing Video For Download...