SlideShare a Scribd company logo
Primitive Data Types Represent single values Practically unlimited access Integers types: 2010 -40 Floating point (decimals) numbers types: Big integers Decimals:  3.14159 Scientific notation:  6.03e23 Boolean type:  true  or  false Character type:  ‘c’ Strings : “Vote for Pedro”
Variables To store or remember data Java uses  variables .  Variables contain primitive values or object references. To be used, variables have to be  declared  and  set Declaring a variable: Announces is existence to the rest of the block Sets aside a section of memory big enough to store the value Determines what kind of value can be stored in the variable Determines how the number is to be interpreted
Variables Variable names should be describe the value they hold Names with multiple words: Lower case first word, capitalize subsequent words Separate words with underscore. Declaring a variable: Type name followed by the name and optional initialization int studentAge = 18; double pi = 3.14159; boolean isValid = false; char marks_the_spot = ‘x’; String vote4 = “Pedro”;
Variable Scope Variables are known inside the block in which they are declared. class Foo { int x = 0; void someMethod() { int y; y = x + 1; } void anotherMethod() { x = y + 1; } }
Integers Integers are 32 bits long -2,147,483,648 <=  int  <= 2,147,483,647 Example   declarations and values int m; m = 0; int n = 23; int o = -40;
Floating Point The type is called  double 64 bits long Some bits used for the exponent, some for the mantissa +/- 1.7 x 10 ± 308  with 15 significant digits double pi; pi = 3.14159; double x = 10.0; double y = 6.02e23; double z = -40;
Boolean A  boolean  value represents  true  or  false A  boolean  also can be used to represent any value with two states, such as a light bulb being on or off. The reserved words  true  and  false  are the only valid values for a boolean type boolean done = false; boolean isMale = true;
Characters A  char  variable stores the numeric representation of a character The  Unicode character set  lists the characters and their corresponding numeric representation The Unicode character set uses sixteen bits per character, allowing for 65,536 unique symbols and characters from many world languages Character literals are delimited by single quotes: 'a'  'X'  '7'  '$'  ','  '\n‘ char marksTheSpot = ‘X';
Escape Sequences The unicode set recognizes ‘characters’ that are not printable These unprintable characters are referred to with escape sequences Escape Sequence \b \t \n \r Unprintable character backspace tab newline carriage return
Escape sequences Printing unprintable characters moves the terminal window cursor Printing a backspace character moves the cursor backwards on the same line Printing a carriage return moves the cursor to the front of the current line Printing a new line drops the cursor to the beginning of the next line Print a tab moves the cursor to ahead to the next tab stop
Escape sequences Special characters must be escaped when using them as just a character char singleQuote = ‘\’’; char doubleQuote = ‘\”’; char backslash = ‘\\’; In other words, the back-slash tells Java to ignore the normal meaning of the very next character
Character Strings A  character string  is a sequence of characters delimited by double-quotes: “ To be, or not to be” (Actually, character strings  are  not  a primitive data type, but an  object .) String eagles; eagles = “Hell, no!!”; String ssn = “147431904”;
Escape Sequences What if we wanted to print a double quote character? System.out.println (&quot;I said &quot;Hello&quot;.&quot;); An  escape sequence  is a series of characters that represents a special character An escape sequence begins with a backslash character ( \ ), which indicates that the character(s) that follow should be treated in a special way: System.out.println (&quot;I said \&quot;Hello\&quot;.&quot;);
Constants A constant is a variable that can only be assigned a value once. The  final  modifier to declares a constant final int MIN_HEIGHT = 60; final int MAX_HEIGHT; … MAX_HEIGHT = 74; Constants: give names to otherwise unclear literal values facilitate updates of values used throughout a program prevent inadvertent attempts to change a value
Assignment An  assignment statement  changes the value of a variable The assignment operator is the  =  sign total = 55; The expression on the right is evaluated and the result is stored in the variable on the left The value that was in  total  is overwritten (and lost) You can only assign a value to a variable that is consistent with the variable's declared type
Keyboard input Reads typing from the console Terminal window or DOS window Based on the concept of  the token Tokens are  string or printable characters separated by delimiters E.g., “Vote for Pedro” has three tokens separated by a white-space delimiter. E.g., “09/15/2010” has three tokens separated by a slash delimiter
Reading Streams The scanner object extracts tokens from the input stream. Input stream can be the keyboard, a file, or a socket. For example, creating the scanner // Create a variable of type Scanner // Connect the scanner to the keyboard Scanner scan = new Scanner(System.in); Read the scanner String data = scan.nextLine();
Reading Streams Read the scanner, again // get the next token, hope it’s an integer int i = scan.nextInt();

More Related Content

PPTX
Character set of c
PPTX
What is identifier c programming
PDF
Lecture02(constants, variable & data types)
PPTX
Constant, variables, data types
PPTX
JAVA Literals
PPTX
Operators in C Programming
PPT
Data types and Operators
PDF
Variables and data types IN SWIFT
Character set of c
What is identifier c programming
Lecture02(constants, variable & data types)
Constant, variables, data types
JAVA Literals
Operators in C Programming
Data types and Operators
Variables and data types IN SWIFT

What's hot (20)

PPTX
Data Types and Variables In C Programming
PPT
constants, variables and datatypes in C
PPTX
Variables and data types in C++
PPTX
Btech i pic u-2 datatypes and variables in c language
PPTX
Mca i pic u-2 datatypes and variables in c language
PPT
3 data-types-in-c
PPTX
Bsc cs i pic u-2 datatypes and variables in c language
PPTX
Diploma ii cfpc u-2 datatypes and variables in c language
PPTX
Variables in C++, data types in c++
PPTX
C data types, arrays and structs
PPTX
Constants variables data_types
PPTX
C language (more)
PPTX
1.getting started with c
PPTX
Data types
PPTX
Data types
PPTX
Programming fundamental
PPTX
C introduction
PPT
Lect 9(pointers) Zaheer Abbas
PPTX
Data Type in C Programming
PPTX
Numeric Data Types & Strings
Data Types and Variables In C Programming
constants, variables and datatypes in C
Variables and data types in C++
Btech i pic u-2 datatypes and variables in c language
Mca i pic u-2 datatypes and variables in c language
3 data-types-in-c
Bsc cs i pic u-2 datatypes and variables in c language
Diploma ii cfpc u-2 datatypes and variables in c language
Variables in C++, data types in c++
C data types, arrays and structs
Constants variables data_types
C language (more)
1.getting started with c
Data types
Data types
Programming fundamental
C introduction
Lect 9(pointers) Zaheer Abbas
Data Type in C Programming
Numeric Data Types & Strings
Ad

Viewers also liked (7)

KEY
Introducing Amplify
PPT
Programming model
PPT
R:\ap java\class slides\chapter 1\1 2 java development
PPT
2 1 expressions
PPT
1 2 java development
PPT
1 4 where do we get the data
PPT
2 4 measures of center
Introducing Amplify
Programming model
R:\ap java\class slides\chapter 1\1 2 java development
2 1 expressions
1 2 java development
1 4 where do we get the data
2 4 measures of center
Ad

Similar to 2 1 data (20)

PPT
Chapter 2 java
PPTX
OOP-java-variables.pptx
PDF
Lecture 2 java.pdf
PPT
Introduction to-programming
PPTX
Chapter i(introduction to java)
PPT
Ap Power Point Chpt2
PPT
Java: Primitive Data Types
PPTX
Java fundamentals
PPTX
Class 8 - Java.pptx
PPT
demo1 java of demo 1 java with demo 1 java.ppt
PDF
Week02
PDF
ITFT-Constants, variables and data types in java
PPTX
Introduction to java Programming Language
PPTX
Pi j1.2 variable-assignment
PPT
skill lab-java interview preparation questions.ppt
PDF
Acquiring a solid foundation in java
PPTX
Introduction to Java Programming
PPTX
UNIT 1 : object oriented programming.pptx
PPTX
JAVA LESSON-01.pptx
PPT
M C6java2
Chapter 2 java
OOP-java-variables.pptx
Lecture 2 java.pdf
Introduction to-programming
Chapter i(introduction to java)
Ap Power Point Chpt2
Java: Primitive Data Types
Java fundamentals
Class 8 - Java.pptx
demo1 java of demo 1 java with demo 1 java.ppt
Week02
ITFT-Constants, variables and data types in java
Introduction to java Programming Language
Pi j1.2 variable-assignment
skill lab-java interview preparation questions.ppt
Acquiring a solid foundation in java
Introduction to Java Programming
UNIT 1 : object oriented programming.pptx
JAVA LESSON-01.pptx
M C6java2

More from Ken Kretsch (9)

PPT
Classical probability
PPT
2 7 exploratory data analysis
PPT
2 6 measure of position
PPT
2 5 standard deviation
PPT
2 1 frequency table
PPT
2 3 depicting frequency tables
PPT
\\Dc hss2\staff\kretsch k\prob and stat\class materials\chapter 1\1-4 where d...
PPT
Science, invention, and engineering
PPT
1 1 data
Classical probability
2 7 exploratory data analysis
2 6 measure of position
2 5 standard deviation
2 1 frequency table
2 3 depicting frequency tables
\\Dc hss2\staff\kretsch k\prob and stat\class materials\chapter 1\1-4 where d...
Science, invention, and engineering
1 1 data

Recently uploaded (20)

PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
Encapsulation theory and applications.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
August Patch Tuesday
PPTX
A Presentation on Touch Screen Technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
A comparative study of natural language inference in Swahili using monolingua...
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Getting Started with Data Integration: FME Form 101
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
NewMind AI Weekly Chronicles - August'25-Week II
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Hybrid model detection and classification of lung cancer
Encapsulation theory and applications.pdf
Programs and apps: productivity, graphics, security and other tools
August Patch Tuesday
A Presentation on Touch Screen Technology
MIND Revenue Release Quarter 2 2025 Press Release
Heart disease approach using modified random forest and particle swarm optimi...
1 - Historical Antecedents, Social Consideration.pdf
Zenith AI: Advanced Artificial Intelligence
A comparative study of natural language inference in Swahili using monolingua...
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
A comparative analysis of optical character recognition models for extracting...
Getting Started with Data Integration: FME Form 101
gpt5_lecture_notes_comprehensive_20250812015547.pdf
WOOl fibre morphology and structure.pdf for textiles
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
Accuracy of neural networks in brain wave diagnosis of schizophrenia

2 1 data

  • 1. Primitive Data Types Represent single values Practically unlimited access Integers types: 2010 -40 Floating point (decimals) numbers types: Big integers Decimals: 3.14159 Scientific notation: 6.03e23 Boolean type: true or false Character type: ‘c’ Strings : “Vote for Pedro”
  • 2. Variables To store or remember data Java uses variables . Variables contain primitive values or object references. To be used, variables have to be declared and set Declaring a variable: Announces is existence to the rest of the block Sets aside a section of memory big enough to store the value Determines what kind of value can be stored in the variable Determines how the number is to be interpreted
  • 3. Variables Variable names should be describe the value they hold Names with multiple words: Lower case first word, capitalize subsequent words Separate words with underscore. Declaring a variable: Type name followed by the name and optional initialization int studentAge = 18; double pi = 3.14159; boolean isValid = false; char marks_the_spot = ‘x’; String vote4 = “Pedro”;
  • 4. Variable Scope Variables are known inside the block in which they are declared. class Foo { int x = 0; void someMethod() { int y; y = x + 1; } void anotherMethod() { x = y + 1; } }
  • 5. Integers Integers are 32 bits long -2,147,483,648 <= int <= 2,147,483,647 Example declarations and values int m; m = 0; int n = 23; int o = -40;
  • 6. Floating Point The type is called double 64 bits long Some bits used for the exponent, some for the mantissa +/- 1.7 x 10 ± 308 with 15 significant digits double pi; pi = 3.14159; double x = 10.0; double y = 6.02e23; double z = -40;
  • 7. Boolean A boolean value represents true or false A boolean also can be used to represent any value with two states, such as a light bulb being on or off. The reserved words true and false are the only valid values for a boolean type boolean done = false; boolean isMale = true;
  • 8. Characters A char variable stores the numeric representation of a character The Unicode character set lists the characters and their corresponding numeric representation The Unicode character set uses sixteen bits per character, allowing for 65,536 unique symbols and characters from many world languages Character literals are delimited by single quotes: 'a' 'X' '7' '$' ',' '\n‘ char marksTheSpot = ‘X';
  • 9. Escape Sequences The unicode set recognizes ‘characters’ that are not printable These unprintable characters are referred to with escape sequences Escape Sequence \b \t \n \r Unprintable character backspace tab newline carriage return
  • 10. Escape sequences Printing unprintable characters moves the terminal window cursor Printing a backspace character moves the cursor backwards on the same line Printing a carriage return moves the cursor to the front of the current line Printing a new line drops the cursor to the beginning of the next line Print a tab moves the cursor to ahead to the next tab stop
  • 11. Escape sequences Special characters must be escaped when using them as just a character char singleQuote = ‘\’’; char doubleQuote = ‘\”’; char backslash = ‘\\’; In other words, the back-slash tells Java to ignore the normal meaning of the very next character
  • 12. Character Strings A character string is a sequence of characters delimited by double-quotes: “ To be, or not to be” (Actually, character strings are not a primitive data type, but an object .) String eagles; eagles = “Hell, no!!”; String ssn = “147431904”;
  • 13. Escape Sequences What if we wanted to print a double quote character? System.out.println (&quot;I said &quot;Hello&quot;.&quot;); An escape sequence is a series of characters that represents a special character An escape sequence begins with a backslash character ( \ ), which indicates that the character(s) that follow should be treated in a special way: System.out.println (&quot;I said \&quot;Hello\&quot;.&quot;);
  • 14. Constants A constant is a variable that can only be assigned a value once. The final modifier to declares a constant final int MIN_HEIGHT = 60; final int MAX_HEIGHT; … MAX_HEIGHT = 74; Constants: give names to otherwise unclear literal values facilitate updates of values used throughout a program prevent inadvertent attempts to change a value
  • 15. Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; The expression on the right is evaluated and the result is stored in the variable on the left The value that was in total is overwritten (and lost) You can only assign a value to a variable that is consistent with the variable's declared type
  • 16. Keyboard input Reads typing from the console Terminal window or DOS window Based on the concept of the token Tokens are string or printable characters separated by delimiters E.g., “Vote for Pedro” has three tokens separated by a white-space delimiter. E.g., “09/15/2010” has three tokens separated by a slash delimiter
  • 17. Reading Streams The scanner object extracts tokens from the input stream. Input stream can be the keyboard, a file, or a socket. For example, creating the scanner // Create a variable of type Scanner // Connect the scanner to the keyboard Scanner scan = new Scanner(System.in); Read the scanner String data = scan.nextLine();
  • 18. Reading Streams Read the scanner, again // get the next token, hope it’s an integer int i = scan.nextInt();