Java Simple Types CSIS 3701: Advanced Object Oriented Programming.

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 and Arithmetic Operators
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,
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.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Introduction to Computers and Programming Lecture 7:
Constants Variables change, constants don't final = ; final double PI = ; … area = radius * radius * PI; see Liang, p. 32 for full code.
Working with the data type: char  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming.
Primitive Types Java supports two kinds of types of values – objects, and – values of primitive data types variables store – either references to objects.
Fundamental data types Horstmann Chapter 4. Constants Variables change, constants don't final = ; final double PI = ; … areaOfCircle = radius *
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
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.
Imperative Programming Part One. 2 Overview Outline the characteristics of imperative languages Discuss other features of imperative languages that are.
 Value, Variable and Data Type  Type Conversion  Arithmetic Expression Evaluation  Scope of variable.
Java Primitives The Smallest Building Blocks of the Language (corresponds with Chapter 2)
VARIABLES AND TYPES CITS1001. Types in Java the eight primitive types the unlimited number of object types Values and References The Golden Rule Scope.
1 Please switch off your mobile phones. 2 Data Representation Instructor: Mainak Chaudhuri
Introduction to Java CSIS 3701: Advanced Object Oriented Programming.
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 Data types, variable declaration, and initialization.
Operators Using Java operators An operator takes one or more arguments and produces a new value. All operators produce a value from their.
Lecture 2 Object Oriented Programming Basics of Java Language MBY.
CSE 1301 Lecture 2 Data Types Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
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.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
CISC105 – General Computer Science Class 9 – 07/03/2006.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
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.
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.
Chapter 2 Variables.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
COMP Primitive and Class Types Yi Hong May 14, 2015.
School of Computer Science & Information Technology G6DICP - Lecture 4 Variables, data types & decision making.
© A+ Computer Science - A reference variable stores the memory address of an object. Monster fred = new Monster(); Monster sally.
1.2 Primitive Data Types and Variables
Primitive Data Types 1 In PowerPoint, point at the speaker icon, then click the "Play" button.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
1 Primitive Types n Four integer types:  byte  short  int (most common)  long n Two floating-point types:  float  double (most common) n One character.
A data type in a programming language is a set of data with values having predefined characteristics.data The language usually specifies:  the range.
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.
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
CSE 110: Programming Language I Matin Saad Abdullah UB 1222.
Review by Mr. Maasz, Summary of Chapter 2: Starting Out with Java.
Primitive Types Four integer types: Two floating-point types:
Chapter 2 Variables.
Chapter 2 Basic Computation
Primitive/Reference Types and Value Semantics
Chapter 4 – Fundamental Data Types
Object Oriented Programming
EPSII 59:006 Spring 2004.
Type Conversion, Constants, and the String Object
Chapter 2.
Advanced Programming Behnam Hatami Fall 2017.
Unit-2 Objects and Classes
null, true, and false are also reserved.
An overview of Java, Data types and variables
Chapter 2 Variables.
C++ Data Types Data Type
Data Types Imran Rashid CTO at ManiWeber Technologies.
Java Programming Review 1
Primitive Types and Expressions
Type Conversion It is a procedure of converting one data type values into another data type In C programming language we are having two types of type conversion.
Chapter 2 Variables.
Presentation transcript:

Java Simple Types CSIS 3701: Advanced Object Oriented Programming

Basic Java Syntax Java syntax mostly same as C++ –Java developed by C++ programmers Examples –Lines/blocks: ; {} –Control structures: if else for while switch … –Operators: = + - * / = … == != > = <= && || … –Comments: /* */ //

Simple Types Numeric types: –int 32 bits –short 16 bits –byte 8 bits –long 64 bits –float 32 bits, ~7 digits after decimal –double 64 bits, ~13 digits after decimal Defined standard in Java language

Simple Types Boolean type –keywords true and false –Example: boolean b = true; Char type –16-bit Unicode for international purposes –Examples: char c1 = ‘A’; char c2 = ‘\u3218’ –Numeric representation of non-ASCII character Tradeoff: memory vs. internationalization

Type Conversion int x = 3.7; –What does this do? Weak typing (C/C++) –Language attempts to convert one type to another –3.7 truncated to 3 and stored in x Strong typing (Java) –Must be no possible ambiguity or information loss –Otherwise syntax error

Type Conversion Other examples: –if (1) {…} Condition must be true or false –long y; int x; Possible information loss x = y; Must explicitly cast to less precise type –int x = (int)3.7; Tradeoff: safety vs. convenience

Constants and Types What type is the number 3 ? The number 3.7 ? –Number without decimal is int. –Number with decimal is double. Possible type conversion problems Example: float y = 3.7; –Syntax error – trying to store double as float –Java hack: Follow constant with f float y = 3.7f;