Primitive 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

Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
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,
Java Syntax Part I Comments Identifiers Primitive Data Types Assignment.
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Data Types and Expressions
Variables Pepper. Variable A variable –box –holds a certain type of value –value inside the box can change Example –A = 2B+1 –Slope = change in y / change.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
CMT Programming Software Applications
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Fundamental data types Horstmann Chapter 4. Constants Variables change, constants don't final = ; final double PI = ; … areaOfCircle = radius *
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.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
C Tokens Identifiers Keywords Constants Operators Special symbols.
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.
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.
JAVA Tokens. Introduction A token is an individual element in a program. More than one token can appear in a single line separated by white spaces.
Outline Character Strings Variables and Assignment Primitive Data Types Expressions Data Conversion Interactive Programs Graphics Applets Drawing Shapes.
Data & Data Types & Simple Math Operation 1 Data and Data Type Standard I/O Simple Math operation.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
 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.
Java Overview. Comments in a Java Program Comments can be single line comments like C++ Example: //This is a Java Comment Comments can be spread over.
Assignment An assignment statement changes the value of a variable The assignment operator is the = sign total = 55; Copyright © 2012 Pearson Education,
PHY-102 SAPVariables and OperatorsSlide 1 Variables and Operators In this section we will learn how about variables in Java and basic operations one can.
Primitive Variables.
Copyright Curt Hill Variables What are they? Why do we need them?
Java Language Basics By Keywords Keywords of Java are given below – abstract continue for new switch assert *** default goto * package.
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.
Data Tonga Institute of Higher Education. Variables Programs need to remember values.  Example: A program that keeps track of sales needs to remember.
Variables and Constants Objectives F To understand Identifiers, Variables, and Constants.
CSI 3125, Preliminaries, page 1 Data Type, Variables.
1.2 Primitive Data Types and Variables
1 09/03/04CS150 Introduction to Computer Science 1 What Data Do We Have.
Values, Types, and Variables. Values Data Information Numbers Text Pretty much anything.
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.
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
MIT AITI Lecture 2 The of Java In the following lectures you will learn the basic structures that make up the Java programming language: »Variables.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
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.
JAVA Practical Unary operators 2. Using Reals 3. Conversions 4. Type Casting 5. Scope 6. Constants.
1 2. Program Construction in Java. 01 Java basics.
1 Identifiers: Names of variables, functions, classes (all user defined objects), Examples: a b gcd GCD A COSC1373 TAX Tax_Rate Tax Rate if else while.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Lecture 3: More Java Basics Michael Hsu CSULA. Recall From Lecture Two  Write a basic program in Java  The process of writing, compiling, and running.
Chapter 2 Variables and Constants. Objectives Explain the different integer variable types used in C++. Declare, name, and initialize variables. Use character.
Constants, Data Types and Variables
Copyright © Texas Education Agency, Computer Programming Variables and Data Types.
Fundamentals 2.
Topic 2 Elementary Programming
CIS3931 – Intro to JAVA Lecture Note Set 2 17-May-05.
Elementary Programming
Documentation Need to have documentation in all programs
Variables and Primative Types
Data Types The type states how much and what kind of data the variable can store. integers- whole numbers no fractional parts int, short, long floating.
IDENTIFIERS CSC 111.
Computers & Programming Languages
مساق: خوارزميات ومبادئ البرمجة الفصل الدراسي الثاني 2016/2015
Chapter 2 Variables.
Object-Oriented Programming
Chapter 2: Java Fundamentals
Storing Information Each memory cell stores a set number of bits (usually 8 bits, or one byte) (byte addressable)
Chapter 2: Java Fundamentals
Unit 3: Variables in Java
Names of variables, functions, classes
Chap 2. Identifiers, Keywords, and Types
C Programming Lecture-3 Keywords, Datatypes, Constants & Variables
Variables and Constants
Presentation transcript:

Primitive Variables

What’s a Variable? A quantity or function that may assume any given value or set of values (source – Dictionary.com) What types of values have we assigned to variables in mathematics and science? Integers and Real Numbers Temperature and Weight Names and Places

What’s a Primitive? Being the first or earliest of the kind or in existence Given just one group of binary digits, what types of things could we come up with? A Binary Value (True/False) Numbers (1, 4, 21) Characters (A, k, &)

JAVA’s Primitive Variables Binary Value (boolean) Numbers Integer (byte, short, int, long) Real Numbers (float, double) Character (char) Text (String) – not a regular primitive variable!

Why so many Integer names? Each one consists of a different number of bits. For example, a byte consists of 8 bits and holds a value from –128 to 127. Calculate 28 = 128 + 127 + 1 =

The other Integer Variables short Occupies 16 bits or 2 bytes int Occupies 32 bits or 4 bytes long Occupies 64 bits or 8 bytes Can you guess the range of values each one stores?

Why so many? It’s a tradeoff The greater number of bytes each one stores, the greater the range of values it can represent. But the larger number of bytes used put more demand on memory resources.

Real Numbers float double Occupies 32 bits or 4 bytes, with 6 or 7 significant digits. double Occupies 64 bits or 8 bytes, with 14 or 15 significant digits.

Characters & Booleans char boolean String Contains a standard ASCII character boolean Contains a TRUE/FALSE value String Contains a line of text

AP Exam The only ones that you need to be familiar with for the AP Exam are: int double boolean char String

Declaration variable_type variable_name; Example: int x; double temperature; char initial; boolean light; String sentence;

Naming Rules Must start with a letter, underscore(_), or dollar sign($) After 1st letter, you can use numbers Can NOT be a JAVA keyword White Space is not permitted (space). No Special Characters They are case sensitive so “BOX” is not the same name as “box”

JAVA keywords

Naming Convention The first letter of the variable is lower case. When using more than one word in the variable name, the first letter of each word after the first is capitalized. Be descriptive (to a limit)

Example If we wanted to have a double that stores the room’s temperature: The Good double roomTemperature; The Bad double ZED; double theTemperatureInOurComputerRoomOnSeptemberTheTenth; The Ugly (Illegal) double case; double room Temperature; double 9/10/07Temperature;

Initialization Variables can be initialized when they are declared: int butterbeerBottles = 99; double bodyTemperature = 98.6; char display = ‘a’; boolean light = false; String insult = “You Strink!”; A variable can be turned into a constant by adding the word final at the beginning of the declaration.