Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Primitive Data types

Similar presentations


Presentation on theme: "Introduction to Primitive Data types"— Presentation transcript:

1 Introduction to Primitive Data types
We are going to start with an overview of object-oriented principles in order to show you the big picture. The information we manage in a Java program is either represented as primitive data or as objects. We’ve already introduced you to objects so now lets let to know primitive data types. Programming languages like Java deal with many kinds of information: text, numbers, pictures, audio, video, and so on. Some of these are complex and change from time to time. No programming language can accommodate every type. Java’s designers kept its basic types simple so the language can stay as simple as possible. For the complex types likes images, java provides libraries of classes rather than trying to make those data types part of the language itself. But every type in Java, no matter how complex, comes from a few basic types that are in the language itself.

2 Building Blocks of java
byte short int long float double char boolean What’s a primitive data type? It’s a simple information format included in the Java language and Java has eight of them. You might hear programmers call these “built-in data types” or “basic data types” but the formal term is primitive data types. Every other data type in Java has one or more primitive types as its basis. The primitive data types indicated in red will be used frequently in this course. int, double, and Boolean are all a part of the AP subset and you will need to know them for the AP test. While char is not a part of the AP subset, we will still work with it frequently.

3 Literals Java Literals are syntactic representations of boolean, character, numeric, or string data. Literals provide a means of expressing specific values in your program.

4 Integers: Most whole number literals are type int by default
Numeric Literals Integers: Most whole number literals are type int by default Any whole number between -2,147,483,648 and 2,147,483,647 Floating-Point Numbers: Any number with a decimal point They are treated as double values unless you add an “F” to make them a float is a double literal 1.2345F is a float (more precise) literal Read page 4

5 A single character inside single quotation marks
Character literal A single character inside single quotation marks Ex. ‘a’, ‘B’ Bottom of page 4

6 Booleans: Only two Boolean literals exist
Logical literal Booleans: Only two Boolean literals exist true false A Boolean value, defined in java using the reserved word Boolean, has only two values: true and false. A Boolean variable usually tells us whether a condition is true, but it can also represent any situation that has two states, such as a lightbulb being on or off. A Boolean value cannot be changed to any other data types, nor can any other data type be changed to a Boolean value. The words true and false are called Boolean literals ad cannot be used for anything else. Boolean values are named after Charles Boole, a 19th-century mathematician who developed an algebra system of two values programmers often use this type in formal logic systems, where statements are either true or false. In Java, we’ll use Boolean values in comparisons and in making decisions, such as asking the user if they have more input or if they would like to play again.

7 Using Primitive Data Types
Literal: a fixed value in Java Ex: 3.14, ‘a’, “pancakes” Named Value: a data field that is given a name Variable: value that can change (placeholder) Constant: value can’t change (fixed) Ex: Math.PI Read bottom of page 5

8 String literals – not a primitive data style
"This is a character string." String literals consist of the double quote character ("), zero or more characters, followed by a terminating double quote character (")  Read page 7

9 Escape sequence A character preceded by a backslash; has special meaning to the compiler We know that the quotation mark indicates the beginning and ending of a string literal but what if you needed to actually print out a quotation mark? We need a special way to print a quotation mark and well as some other characters like the backslash that already have special meaning to Java. The newline, double quote, and backslash escape sequences are a part of the AP subset and you should be most familiar with them.

10 Example code This is how the double quotation escape sequence is used in code and its corresponding output.


Download ppt "Introduction to Primitive Data types"

Similar presentations


Ads by Google