1.2 Primitive Data Types and Variables

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

C# Language Report By Trevor Adams. Language History Developed by Microsoft Developed by Microsoft Principal Software Architect Principal Software Architect.
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.
Data Types in Java Data is the information that a program has to work with. Data is of different types. The type of a piece of data tells Java what can.
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
Data Types and Expressions
Types and Variables. Computer Programming 2 C++ in one page!
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Nyhoff, ADTs, Data Structures and Problem Solving with C++, Second Edition, © 2005 Pearson Education, Inc. All rights reserved Introduction.
Chapter 2 Data Types, Declarations, and Displays
Integer, Floating-Point, Text Data, Variables, Literals Svetlin Nakov Telerik Corporation
Performing Simple Calculations with C# Svetlin Nakov Telerik Corporation
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.
01- Intro-Java-part1 1 Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology June 2008.
.NET Data types. Introduction ٭ A "data type" is a class that is primarily used just to hold data. ٭ This is different from most other classes since they're.
Java Building Elements Lecture 2 Instructors: Fu-Chiung Cheng ( 鄭福炯 ) Associate Professor Computer Science & Engineering Tatung University
CSCI 1100/1202 January 16, Why do we need variables? To store intermediate results in a long computation. To store a value that is used more than.
Georgia Institute of Technology Introduction to Java, and DrJava Barb Ericson Georgia Institute of Technology Aug 2005.
Primitive Data Types and Variables Integer, Floating-Point, Text Data, Variables, Literals Angel Georgiev Part-time Trainer angeru.softuni-friends.org.
VARIABLES AND TYPES CITS1001. Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Scope.
Copyright © 2002 W. A. Tucker1 Chapter 7 Lecture Notes Bill Tucker Austin Community College COSC 1315.
1 Do you have a CS account? Primitive types –“ building blocks ” for more complicated types Java is strongly typed –All variables in a Java program must.
CPS120: Introduction to Computer Science Variables and Constants Lecture 8 - B.
Java Data Types. Primitive Data Types Java has 8 primitive data types: – char: used to store a single character eg. G – boolean: used to store true or.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
Chapter 2: Using Data.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
CPS120: Introduction to Computer Science
Lec 6 Data types. Variable: Its data object that is defined and named by the programmer explicitly in a program. Data Types: It’s a class of Dos together.
Lecture #5 Introduction to C++
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
Primitive Data Types and Variables Integer, Floating-Point, Text Data, Variables, Literals SoftUni Team Technical Trainers Software University
Primitive Variables.
 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.
Telerik Software Academy Telerik School Academy Integer, Floating-Point, Text Data, Variables,
Chapter 2 Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
ITEC 109 Lecture 7 Operations. Review Variables / Methods Functions Assignments –Purpose? –What provides the data? –What stores the data? –What type of.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
Performing Simple Calculations with C# Telerik Corporation
Chapter One Lesson Three DATA TYPES ©
Integer, Floating-Point, Text Data, Variables, Literals Telerik Corporation
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.
COP2800 – Computer Programming Using JAVA University of Florida Department of CISE Spring 2013 Lecture 06 – Java Datatypes Webpage:
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Computer Programs CS 1400 Dennis A. Fairclough Version 1.1 CS 1400 Dennis A. Fairclough Version 1.1.
Java Basics. Tokens: 1.Keywords int test12 = 10, i; int TEst12 = 20; Int keyword is used to declare integer variables All Key words are lower case java.
Sudeshna Sarkar, IIT Kharagpur 1 Programming and Data Structure Sudeshna Sarkar Lecture 3.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Introduction C# program is collection of classes Classes are collection of methods and some statements That statements contains tokens C# includes five.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
1Object-Oriented Program Development Using C++ Built-in Data Types Data type –Range of values –Set of operations on those values Literal: refers to acceptable.
Java Programming Language Lecture27- An Introduction.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Fundamentals 2.
Chapter 2 Variables.
Numeral Types and Type Conversion
Chapter 6: Data Types Lectures # 10.
Lecture 2 Data Types Richard Gesick.
Multiple variables can be created in one declaration
Understand Computer Storage and Data Types
.Net Programming with C#
Computers & Programming Languages
Chapter 2 Variables.
Data Types Imran Rashid CTO at ManiWeber Technologies.
B065: PROGRAMMING Variables 1.
Chapter 2 Variables.
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Presentation transcript:

1.2 Primitive Data Types and Variables academy.zariba.com

Lecture Content 1. Primitive Data Types Numbers Boolean Character String Object 2. Variables Identifiers Declaring and Using Literals 3. Nullable Types

How Variables Work? Computers process data. Data is stored in the computer’s memory as variables. Variables have data type, name and value.

What is a Data Type? A data type is a set of values with similar characteristics, e.g. numbers, characters, text etc. A data type is specified by its name, size, bounds and default value. E.g. Integers: Name: int Size: 32 bits (4 bytes) Bounds: -2,147,483,648 to 2,147,483,647 Default Value: 0

1. Integer Types sbyte (-128 to 127): signed 8-bit byte (0 to 255): unsigned 8-bit short (-32,768 to 32,767): signed 16-bit ushort (0 to 65,535): unsigned 16-bit int (-2,147,483,648 to 2,147,483,647): signed 32-bit uint (0 to 4,294,967,295): unsigned 32-bit long (-9,223,372,036,854,775,808 to 9,223,372,036,854,775,807): signed 64-bit ulong (0 to 18,446,744,073,709,551,615): unsigned 64-bit BigInteger (limit depends on RAM): limit depends on RAM

2. Floating-Point and Decimal Floating-Point Types float (±1.5 × 10−45 to ±3.4 × 1038): 32-bits, precision of 7 digits double (±5.0 × 10−324 to ±1.7 × 10308): 64-bits, precision of 15-16 digits decimal (±1,0 × 10-28 to ±7,9 × 1028): 128-bits, precision of 28-29 digits Default Values float: 0.0F double : 0.0D Decimal: 0.0M

3. Boolean Types The Boolean Type is the simplest. It is declared with the keyword bool and has two possible values: true or false.

4. Character Type The character type represents a symbol. It is declared with the keyword char, takes 16 bits of memory and has a default value of ‘\0’.

4. String Type The string type represents text. It is declared with the keyword string and takes variable amount of memory.

5. Object Type The object type can represent any type of data. It is declared with the object keyword.

6. Dynamic Type The dynamic type can hold anything. Operations are evaluated at runtime.

Homework Declare a variable for each of the data types in this lecture and assign an appropriate value. Read two floating point numbers from the console. Write a program to successfully compare these floating point number with precision of 0.00001. e.g. 3.0006 and 3.1 false, 3.000007 and 3.000008 true Assign an integer variable with the value of 107 in hexadecimal format. Hint: Use Windows Calculator. Create a character variable and assign it with the character with Unicode 90. Hint: Same as 3. Declare a boolean variable isItSunnyOutsideToday and give it an appropriate value. Declare two string variables and assign them with “Zariba” and “Academy”. Declare an object variable and assign it with the concatenation of the first two variables (mind adding an interval). Declare a third string variable and initialize it with the value of the object variable (you should perform type casting).

Homework 7. Declare a string variable with the following text: My favourite movie is “[insert film here]”. Draw on the console a 3 by 6 rectangle with the symbol ¿. Read two integer values from the console and exchange their values.

References

Zariba Academy Questions