Introduction to Primitive Data types

Slides:



Advertisements
Similar presentations
STRING AN EXAMPLE OF REFERENCE DATA TYPE. 2 Primitive Data Types  The eight Java primitive data types are:  byte  short  int  long  float  double.
Advertisements

CS0007: Introduction to Computer Programming Console Output, Variables, Literals, and Introduction to Type.
Primitive Data Types There are a number of common objects we encounter and are treated specially by almost any programming language These are called basic.
Constants and Data Types Constants Data Types Reading for this class: L&L,
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Bellevue University CIS 205: Introduction to Programming Using C++ Lecture 3: Primitive Data Types.
1 Chapter 4 Language Fundamentals. 2 Identifiers Program parts such as packages, classes, and class members have names, which are formally known as identifiers.
Data types and variables
Chapter 2 Data Types, Declarations, and Displays
String Escape Sequences
Chapter 3: Introduction to C Programming Language C development environment A simple program example Characters and tokens Structure of a C program –comment.
1 Chapter Two Using Data. 2 Objectives Learn about variable types and how to declare variables Learn how to display variable values Learn about the integral.
Chapter 2 Data Types, Declarations, and Displays.
Objectives You should be able to describe: Data Types
Introduction to Programming Prof. Rommel Anthony Palomino Department of Computer Science and Information Technology Spring 2011.
1 Variables, Constants, and Data Types Primitive Data Types Variables, Initialization, and Assignment Constants Characters Strings Reading for this class:
Input & Output: Console
System development with Java Lecture 2. Rina Errors A program can have three types of errors: Syntax and semantic errors – called.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
Chapter 3: Data Types and Operators JavaScript - Introductory.
 JAVA Compilation and Interpretation  JAVA Platform Independence  Building First JAVA Program  Escapes Sequences  Display text with printf  Data.
Lecture #5 Introduction to C++
Knowledge Base C++ #include using std namespace; int main(){} return 0 ; cout
Programming for Beginners Martin Nelson Elizabeth FitzGerald Lecture 2: Variables & Data Types.
 Character set is a set of valid characters that a language can recognise.  A character represents any letter, digit or any other sign  Java uses the.
Data TypestMyn1 Data Types The type of a variable is not set by the programmer; rather, it is decided at runtime by PHP depending on the context in which.
Introduction to Java Java Translation Program Structure
SE-1010 Dr. Mark L. Hornick 1 Variables & Datatypes.
1 Chapter 3 Syntax, Errors, and Debugging Fundamentals of Java: AP Computer Science Essentials, 4th Edition Lambert / Osborne.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
CSCI 3133 Programming with C Instructor: Bindra Shrestha University of Houston – Clear Lake.
Chapter 2 Variables.
C++ Basics Tutorial 5 Constants. Topics Covered Literal Constants Defined Constants Declared Constants.
Chapter 4 Literals, Variables and Constants. #Page2 4.1 Literals Any numeric literal starting with 0x specifies that the following is a hexadecimal value.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
CHAPTER 2 PROBLEM SOLVING USING C++ 1 C++ Programming PEG200/Saidatul Rahah.
© 2007 Pearson Addison-Wesley. All rights reserved2-1 Character Strings A string of characters can be represented as a string literal by putting double.
Types Chapter 2. C++ An Introduction to Computing, 3rd ed. 2 Objectives Observe types provided by C++ Literals of these types Explain syntax rules for.
Chapter 2: Data and Expressions. Variable Declaration In Java when you declare a variable, you must also declare the type of information it will hold.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CS0007: Introduction to Computer Programming Primitive Data Types and Arithmetic Operations.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
1 ENERGY 211 / CME 211 Lecture 3 September 26, 2008.
April 13, 1998CS102-02Lecture 3-1 Data Types in Java CS Lecture 3-1 Java’s Central Casting.
© 2004 Pearson Addison-Wesley. All rights reserved August 27, 2007 Primitive Data Types ComS 207: Programming I (in Java) Iowa State University, FALL 2007.
28 Formatted Output.
C++ Lesson 1.
C Formatted Input/Output
C++ First Steps.
Chapter 1.2 Introduction to C++ Programming
Week 2 - Wednesday CS 121.
Chapter 2 Variables.
CS0007: Introduction to Computer Programming
Chapter 1.2 Introduction to C++ Programming
Primitive Data Types August 28, 2006 ComS 207: Programming I (in Java)
Variables and Primative Types
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2.
IDENTIFIERS CSC 111.
Introduction to C++ Programming
An overview of Java, Data types and variables
Chapter 2 Variables.
Introduction to Primitive Data types
C++ Data Types Data Type
Chapter 2: Introduction to C++.
Java Programming Review 1
Unit 3: Variables in Java
Chapter 2 Variables.
Introduction to C Programming
Presentation transcript:

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.

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.

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

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 1.2345 is a double literal 1.2345F is a float (more precise) literal Read page 4

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

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.

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

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

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.

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