# COMP6700/2140 Data and Types

Size: px
Start display at page:

Transcription

1 COMP6700/2140 Data and Types Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU February 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

2 Topics 1 Types and literals 2 Primitive types 3 Objects and references 4 Arrays 5 Strings Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

3 Types and Literals 1 Computer programs operate on values which are sequences of bits These values can be represented as symbols (variables or constants), or as literals Symbols must be declared with a type The type determines the number of bits representing a given symbol in memory and how these bits are interpreted (its value) Java has primitive types and references Each type has literals (set of constant values of this type) Java is a strongly typed language every symbol must have a declared type The eight primitive types: boolean (1-bit, true/false) byte (8-bit signed, range ) char (16-bit unicode, character symbols from Unicode Table) short (16-bit signed, range ) int (32-bit signed, range -2,147,483,648 +2,147,483,647) long (64-bit signed range -9,223,372,036,854,775,808 +9,223,372,036,854,775,807) float (32-bit floating-point number) double (64-bit floating-point number) Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

4 Range of Primitive Values Each primitive type can hold values within a certain range byte, short, integer and long are signed (their range includes negative values from -2 bitsize -1 to +2 bitsize -1-1 one bit is used for the sign, +/-) For instance, the int values change from -2,147,483,648 to +2,147,483,647 Floating point types (float and double) include subsets of approximations to real numbers from very small to very large (discussed in greater detail later) bit a single binary digit with one of two possible values, 0 and 1 byte the unit of data consisting of eight bits word the unit of data used by a particular processor design (handled as a unit in the processor instruction set); modern general purpose computers have either 32- or 64-bit words Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

5 Types and Literals 2 public class PrintNumber { // usage of the primitive type variables public static void main( String[] args ) { int i = 90000; short s = 20000; // one can have 2 statements on one line byte b = -100; double d = 15; // but normally it's not good for readability long l = L; // note the `L` here float f = 15f; // note the f here char c = 'a'; boolean bn = true; int i2; i2 = ; // delayed initialisation Systemoutprintln( "The value of s is " + s ); // display the value } } Java variables are statically typed: first declare a variable and then assign it a value Declaration and assignment can done in the same place, or assignment can be postponed L or l suffix for long integers, and F or f suffix for floats To avoid confusing the long type flag l and the literal value 1, use only the upper-case L Range of values is independent of platform, unlike, eg, for C/C++ Integer constants (literals of byte, short, integer and long) are strings of either decimal, octal (leading zero, 010) or hexadecimal (0xCAFE) digits Octal format isn t recommended (confusing syntax!): (decimal)13 = (hexadecimal) 0xD = (binary) 1101 The 2-byte hex literal 0xCAFE if treated as a 32-bit int is (binary) = (decimal), but if treated as a 16-bit short is (binary) = (decimal) Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

6 Floating Point Numbers In scientific notation, we commonly represent numbers in terms of a significand and an exponent: x = α 10 β, for example, mass(earth) = kg In a similar way, real numbers can be represented on a computer in terms of a binary significand and an exponent of base 2: x = α 2 β The decimal point floats left or right so that there is only one digit in front of the point For all non-zero numbers, the first digit is a one The exponent determines the magnitude of the number (binary) 1101 = (decimal) 13 = Floating point numbers of a fixed size (float = 32 bits; double = 64 bits) cannot represent all real numbers within their range Some numbers have an exact representation, but most numbers must be approximated Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

7 Floating Point Numbers (2) For FP literals either decimal or hexadecimal format is used: 18=18e1=18E2=1800e-1 decimal point is optional; e or E is optional, and if used is followed by optional signed integer 0x12p0=0x12p4=0x12P+8=0x120p-4 the binary exponent, p or P, is mandatory; it s followed by an optionally signed integer; the exponent represents scaling by two raised to a power (the shown number is decimal 180) float has ~7 decimal digits of precision, the trailing suffix f is mandatory double has ~16 decimals of precision, the trailing suffix d is optional Normally, use double unless you have a good reason FP literals include two zeros, 1d * 0 = 00 (positive) and -1d * 0 = -00 (negative); 00==-00 evaluates to true, but some expressions evaluate to different values: 1d/00=, yet 1d/(-00)= 64-bit IEEE 754 standard stipulates the number of bits used for significand and exponent: 52 and 11 (plus one bit for the sign +/-) There are special floating point values: 1 NEGATIVE_INFINITY, POSITIVE_INFINITY, MAX_VALUE, MIN_VALUE (to denote overflows and underflows) 2 NaN, Not a Number (examples: 0/0, 1), Float and Double classes provide a method isnan() to test a FP value NaN is the only value, for which x == y evaluates to false if both double s x and y are equal to NaN Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

8 Types and Literals 3 Numeric literals of difficult integer types can be (since Java SE 7) created using notations which are more readable for humans: Numeric constants (that is, one of the integer primitive types) may now be expressed as binary literals int x = 0b ; Underscores may be used in integer constants to improve readability: long anotherlong = 2_147_483_648L; int bitpattern = 0b0001_1100_0011_0111_0010_1011_1010_0011; Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

9 Type Compatibility A variable of one type may be assigned a value of a different type: long m; int n = 2; m = n; This is a type conversion: int long Java is a strongly typed language it checks for type compatibility at compile time in almost all cases all fishy assignments are forbidden To allow assignment of types with compatibility only known at run time, or to explicitly force conversion for primitive types that would otherwise lose range (double float), Java provides the cast operator: var1 = (type1)var2; A narrower type, represented by a fewer number of bits, is implicitly widened, cast is not required A wider type must be explicitly narrowed to control the change of value: ( high bits are chopped off) The explicit cast is also needed if two types use an equal number of bits, but their memory layout is different, eg conversion double long requires a translation from a 64-bit Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20 floating-point value to the 64-bit integer representation (depending on the run-time value,

10 Type Conversions and Casts 1 Hierarchy of widening and narrowing conversions a b means that a variable of the type b is assigned a value held by a variable of the type a; widening is an implicit type conversion, cast isn t needed since the doesn t change; narrowing needs the explicit cast (because the value can change of assignment) Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

11 Type Conversions and Casts 2 Casts (including the effect of losing the fractional parts of floats) are illustrated by the following code: public class ConversionTest { public static void main(string[] args) { int i1 = 10; float f1 = i1; double d1 = i1; double d2 = 15; float f2 = (float) d2; int i2 = (int) d2; // call print method to display the values } } Add printing statements for all the variables involved, compile and run this code to see the values generated by conversion What do you get when you print the value of i2? Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

12 Conversion, Rounding and Finite Precision What is the value of n below? double f = 435; int n = (int) ( 100 * f ); Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

13 Conversion, Rounding and Finite Precision What is the value of n below? double f = 435; int n = (int) ( 100 * f ); Systemoutprintln(n); // prints 434: Wrong! What s wrong? In the binary number system, there is no exact representation for the number 435, it is actually stored as so 100 * f = (etc) When cast to an integer, the fractional component is dropped (not rounded!), thus n = 434 The proper way to do rounding is to use a function call from the Math class: double f = 435; int n = (int)mathround( 100 * f ); Systemoutprintln( n ); // prints 435! (Good) Rounding errors are a fact of life with floating point numbers Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

14 Characters Characters are represented by primitive type char Strings are not characters strings are instances of the class String But it may help to think of them as sequences of characters (which is what they are in term of values) Character literals appear between single quotes: 'a', string literals appear between double quotes: "a" ('a' and "a" are literal values of different type!) The character literals can be expressed either by a single symbol, or by an escape sequence inside the pair of single quotes, including an octal character constant (\ddd, where each d is one of 0-7, but the code cannot exceed \377) Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

15 Unicode char literals are what you can find in the Unicode character table (used to be and still is for C the plain old ASCII with 128 entries; not for Java!): characters (Latin and other scripts), digits and many special symbols Any valid Unicode character can be represented using ASCII symbols only with an escape sequence \uxxxx, where x is a hexadecimal digit (0,,F) The number of u symbols can be more than one (BTW, the Unicode character mapping escape sequence can be used anywhere inside Java code as a part of an identifier, not only in char and String literals) Here is a portability problem for Java: despite you can manipulate all Unicode characters in your code, you may not be able display them because many terminal and other output devices are yet to adopt the Unicode standard Some special ASCII characters: \n = \u000a (new line) \t = \u0009 (tab) \\ = \u005c (backslash) Try printing \a (bell), what happens? (Hint there is no literal constant for it, one has to use its unicode value, \u0007) Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

16 Arithmetic on Chars Two chars can be added together careful! first they are converted to ints (ie, the characters are replaced by their code values) then the sum is calculated and the result value is also int to get the character back, this sum should be cast back to char: char c = (char)(a + b) This also works for other arithmetic operations try it! Study these programs: CharTestjava CharTest1java CharTest2java Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

17 Non-Primitive Data Types As well as primitive types, in an object-oriented language like Java, there are objects objects are composed of (potentially) several items of data called fields, which can be primitive values or references to other objects objects can also have operations associated with them called methods objects can be introduced into a program as literal values (eg literal strings like "Java has become trendy again"), but more commonly they are represented by references which are declared to have a particular type The objects (of any type/class) are collectively referred to as reference type data The literal null is a special reference literal; it represents an invalid or uninitialized object null does not have a type of its own, but it can be cast to any reference type Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

18 Arrays An array is special reference type, representing an ordered collection of data elements indexed by an integer from 0 (first element) up to length - 1 All elements have the same type The declaration and instantiations can be done differently: //standard instantiation with elements set to default values int[] ia = new int[3]; // creation of an array with initialisation of its element values (no new!) int[] ia = { 2, 3, 5, 7, 11, 13 }; // next C-like syntax is also legal, but don't do it! int ia[] = { 2, 3, 5, 7, 11, 13 }; // as above, but note absence of the array size! (array size is inferred) int[] ia = new int[] { 17, 19, 23, 29, 31, }; // last comma is optional Dimension of the array variables in the type declaration is omitted The symbol new is the creation operator (used when an object is created) When it s called, an array is instantiated (ie, an array object is created) and its dimension is set As every reference, ia can be later assigned to a different array of a different size (example ArrayTestjava ) arr[i] returns the i-th element in the array arr, and strcharat(i) returns the character at the i-th position An arrays has the length field which tells you how long it is (ie, how many elements it contains) Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

19 Strings String is another special reference type, representing a string of text A value of the String type a literal string is created inside the program as a sequence of characters enclosed in the matching pair of double quotes (the double quotes are NOT part of the string data) All string literals in Java programs, such as "abc", are objects of the class String, which is a part of the Java standard library (Java SE API) Strings are immutable (constant) their values cannot be changed after creation String str1 = "abc"; // using a literal string to initialise a variable char data[] = {'a', 'b', 'c'}; String str2 = new String(data); // using String class constructor Systemoutprintln(str1equals(str2)); // testing equality of two strings // should print "true", the objects str1 and str2 are identical // But, str1 and str1 references were independently assigned, therefore Systemoutprintln(str1 == str2); // should print "false" Characters which make up a string object can be read by using the method somestringcharat(i), where the index i is the position of the character inside the string (left-to-right, the first character has index 0!) Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

20 String Methods The operations we just saw performed on strings (str1equals(str2)) and (somestringcharat(i)) are methods which can be invoked on a string object Methods are operations which objects are programmed to perform Methods are characterised by a name followed by a pair of parentheses which may or may not include literal values or variable names in a form of a comma separated list these are method (actual) parameters, they are used in carrying out the computation which method represents The String class includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase, etc (string operations are important, and String is a large class) Systemoutprintln("abc"); String cde = "cde"; Systemoutprintln("abc" + cde); String c = "abc"substring(2,3); String d = cdesubstring(1, 2); char c1 = cdecharat(0); Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

21 Further Reading Cay Hortsmann Core Java for the Impatient Ch 12, 15 David Goldberg What Every Computer Scientist Should Know About Floating-Point Arithmetic Josh Haberman Floating Point Demystified Henry S Warren Hacker s Delight 2ed, Addison-Wesley, 2013, ISBN-13: Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Data and Types February / 20

### Full file at

Java Programming: From Problem Analysis to Program Design, 3 rd Edition 2-1 Chapter 2 Basic Elements of Java At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class

### Zheng-Liang Lu Java Programming 45 / 79

1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 45 / 79 Example Given a radius

### CMPT 125: Lecture 3 Data and Expressions

CMPT 125: Lecture 3 Data and Expressions Tamara Smyth, tamaras@cs.sfu.ca School of Computing Science, Simon Fraser University January 3, 2009 1 Character Strings A character string is an object in Java,

### COMP6700/2140 Operators, Expressions, Statements

COMP6700/2140 Operators, Expressions, Statements Alexei B Khorev and Josh Milthorpe Research School of Computer Science, ANU 3 March 2017 Alexei B Khorev and Josh Milthorpe (RSCS, ANU) COMP6700/2140 Operators,

### Java Basic Datatypees

Basic Datatypees Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in the memory. Based on the data type of a variable,

### 1 class Lecture2 { 2 3 "Elementray Programming" / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch.

1 class Lecture2 { 2 3 "Elementray Programming" 4 5 } 6 7 / References 8 [1] Ch. 2 in YDL 9 [2] Ch. 2 and 3 in Sharan 10 [3] Ch. 2 in HS 11 / Zheng-Liang Lu Java Programming 41 / 68 Example Given the radius

### Chapter 2 Elementary Programming

Chapter 2 Elementary Programming Part I 1 Motivations In the preceding chapter, you learned how to create, compile, and run a Java program. Starting from this chapter, you will learn how to solve practical

Lecture Notes 1. Comments a. /* */ b. // 2. Program Structures a. public class ComputeArea { public static void main(string[ ] args) { // input radius // compute area algorithm // output area Actions to

### Getting started with Java

Getting started with Java Magic Lines public class MagicLines { public static void main(string[] args) { } } Comments Comments are lines in your code that get ignored during execution. Good for leaving

### CSCI 2010 Principles of Computer Science. Data and Expressions 08/09/2013 CSCI

CSCI 2010 Principles of Computer Science Data and Expressions 08/09/2013 CSCI 2010 1 Data Types, Variables and Expressions in Java We look at the primitive data types, strings and expressions that are

### 3 The Building Blocks: Data Types, Literals, and Variables

chapter 3 The Building Blocks: Data Types, Literals, and Variables 3.1 Data Types A program can do many things, including calculations, sorting names, preparing phone lists, displaying images, validating

Visual C# 2005 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives s Quick Quizzes Class Discussion Topics Additional Projects Additional Resources Key Terms

### A variable is a name for a location in memory A variable must be declared

Variables A variable is a name for a location in memory A variable must be declared, specifying the variable's name and the type of information that will be held in it data type variable name int total;

### JAC444 - Lecture 1. Introduction to Java Programming Language Segment 4. Jordan Anastasiade Java Programming Language Course

JAC444 - Lecture 1 Introduction to Java Programming Language Segment 4 1 Overview of the Java Language In this segment you will be learning about: Numeric Operators in Java Type Conversion If, For, While,

### Data and Expressions. Outline. Data and Expressions 12/18/2010. Let's explore some other fundamental programming concepts. Chapter 2 focuses on:

Data and Expressions Data and Expressions Let's explore some other fundamental programming concepts Chapter 2 focuses on: Character Strings Primitive Data The Declaration And Use Of Variables Expressions

### Chapter 2 ELEMENTARY PROGRAMMING

Chapter 2 ELEMENTARY PROGRAMMING Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Objectives To write Java programs to perform simple

### Introduction To Java. Chapter 1. Origins of the Java Language. Origins of the Java Language. Objects and Methods. Origins of the Java Language

Chapter 1 Getting Started Introduction To Java Most people are familiar with Java as a language for Internet applications We will study Java as a general purpose programming language The syntax of expressions

### Programming in C++ 6. Floating point data types

Programming in C++ 6. Floating point data types! Introduction! Type double! Type float! Changing types! Type promotion & conversion! Casts! Initialization! Assignment operators! Summary 1 Introduction

### COMP2611: Computer Organization. Data Representation

COMP2611: Computer Organization Comp2611 Fall 2015 2 1. Binary numbers and 2 s Complement Numbers 3 Bits: are the basis for binary number representation in digital computers What you will learn here: How

### Java Notes. 10th ICSE. Saravanan Ganesh

Java Notes 10th ICSE Saravanan Ganesh 13 Java Character Set 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

### Operators and Expressions

Operators and Expressions Conversions. Widening and Narrowing Primitive Conversions Widening and Narrowing Reference Conversions Conversions up the type hierarchy are called widening reference conversions

### CEN 414 Java Programming

CEN 414 Java Programming Instructor: H. Esin ÜNAL SPRING 2017 Slides are modified from original slides of Y. Daniel Liang WEEK 2 ELEMENTARY PROGRAMMING 2 Computing the Area of a Circle public class ComputeArea

### Values and Variables 1 / 30

Values and Variables 1 / 30 Values 2 / 30 Computing Computing is any purposeful activity that marries the representation of some dynamic domain with the representation of some dynamic machine that provides

### Declaration and Memory

Declaration and Memory With the declaration int width; the compiler will set aside a 4-byte (32-bit) block of memory (see right) The compiler has a symbol table, which will have an entry such as Identifier

### CS 112 Introduction to Computing II. Wayne Snyder Computer Science Department Boston University

CS 112 Introduction to Computing II Wayne Snyder Department Boston University Today: Java basics: Compilation vs Interpretation Program structure Statements Values Variables Types Operators and Expressions

### Variables, Constants, and Data Types

Variables, Constants, and Data Types Strings and Escape Characters Primitive Data Types Variables, Initialization, and Assignment Constants Reading for this lecture: Dawson, Chapter 2 http://introcs.cs.princeton.edu/python/12types

### Exercise: Using Numbers

Exercise: Using Numbers Problem: You are a spy going into an evil party to find the super-secret code phrase (made up of letters and spaces), which you will immediately send via text message to your team

### Object oriented programming. Instructor: Masoud Asghari Web page: Ch: 3

Object oriented programming Instructor: Masoud Asghari Web page: http://www.masses.ir/lectures/oops2017sut Ch: 3 1 In this slide We follow: https://docs.oracle.com/javase/tutorial/index.html Trail: Learning

### Exercises Software Development I. 03 Data Representation. Data types, range of values, internal format, literals. October 22nd, 2014

Exercises Software Development I 03 Data Representation Data types, range of values, ernal format, literals October 22nd, 2014 Software Development I Wer term 2013/2014 Priv.-Doz. Dipl.-Ing. Dr. Andreas

### ECE 122 Engineering Problem Solving with Java

ECE 122 Engineering Problem Solving with Java Lecture 3 Expression Evaluation and Program Interaction Outline Problem: How do I input data and use it in complicated expressions Creating complicated expressions

### Chapter 2 Primitive Data Types and Operations. Objectives

Chapter 2 Primitive Data Types and Operations Prerequisites for Part I Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs,

### Language Basics. /* The NUMBER GAME - User tries to guess a number between 1 and 10 */ /* Generate a random number between 1 and 10 */

Overview Language Basics This chapter describes the basic elements of Rexx. It discusses the simple components that make up the language. These include script structure, elements of the language, operators,

### Objects and Types. COMS W1007 Introduction to Computer Science. Christopher Conway 29 May 2003

Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 Java Programs A Java program contains at least one class definition. public class Hello { public static void

### A Java program contains at least one class definition.

Java Programs Identifiers Objects and Types COMS W1007 Introduction to Computer Science Christopher Conway 29 May 2003 A Java program contains at least one class definition. public class Hello { public

### COMP2121: Microprocessors and Interfacing. Number Systems

COMP2121: Microprocessors and Interfacing Number Systems http://www.cse.unsw.edu.au/~cs2121 Lecturer: Hui Wu Session 2, 2017 1 1 Overview Positional notation Decimal, hexadecimal, octal and binary Converting

### Data Types, Variables and Arrays. OOC 4 th Sem, B Div Prof. Mouna M. Naravani

Data Types, Variables and Arrays OOC 4 th Sem, B Div 2016-17 Prof. Mouna M. Naravani Identifiers in Java Identifiers are the names of variables, methods, classes, packages and interfaces. Identifiers must

### Princeton University. Computer Science 217: Introduction to Programming Systems. Data Types in C

Princeton University Computer Science 217: Introduction to Programming Systems Data Types in C 1 Goals of C Designers wanted C to: Support system programming Be low-level Be easy for people to handle But

### false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

### Number Representation & Conversion

Number Representation & Conversion Chapter 4 Under the covers of numbers in Java 1 How (Unsigned) Integers Work Base 10 Decimal (People) Base 2 Binary (Computer) 10 2 10 1 10 0 2 3 4 2 7 2 6 2 5 2 4 2

### Basics of Java Programming

Basics of Java Programming Lecture 2 COP 3252 Summer 2017 May 16, 2017 Components of a Java Program statements - A statement is some action or sequence of actions, given as a command in code. A statement

### Chapter 2: Using Data

Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

### Data Types, Literals, Operators

Data Types, Literals, Operators Sisoft Technologies Pvt Ltd SRC E7, Shipra Riviera Bazar, Gyan Khand-3, Indirapuram, Ghaziabad Website: www.sisoft.in Email:info@sisoft.in Phone: +91-9999-283-283 Learning

### Features of C. Portable Procedural / Modular Structured Language Statically typed Middle level language

1 History C is a general-purpose, high-level language that was originally developed by Dennis M. Ritchie to develop the UNIX operating system at Bell Labs. C was originally first implemented on the DEC

### Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. Overview. Objectives. Teaching Tips. Quick Quizzes. Class Discussion Topics

Java Programming, Sixth Edition 2-1 Chapter 2 Using Data At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional Projects Additional

### Computer System and programming in C

1 Basic Data Types Integral Types Integers are stored in various sizes. They can be signed or unsigned. Example Suppose an integer is represented by a byte (8 bits). Leftmost bit is sign bit. If the sign

### Full file at

Java Programming, Fifth Edition 2-1 Chapter 2 Using Data within a Program At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics Additional

### Data and Variables. Data Types Expressions. String Concatenation Variables Declaration Assignment Shorthand operators. Operators Precedence

Data and Variables Data Types Expressions Operators Precedence String Concatenation Variables Declaration Assignment Shorthand operators Review class All code in a java file is written in a class public

### JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1)

Technology & Information Management Instructor: Michael Kremer, Ph.D. Class 1 Professional Program: Data Administration and Management JAVASCRIPT AND JQUERY: AN INTRODUCTION (WEB PROGRAMMING, X452.1) WHO

### Program Fundamentals

Program Fundamentals /* HelloWorld.java * The classic Hello, world! program */ class HelloWorld { public static void main (String[ ] args) { System.out.println( Hello, world! ); } } /* HelloWorld.java

### false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

### Computer Programming, I. Laboratory Manual. Experiment #3. Selections

Think Twice Code Once The Islamic University of Gaza Engineering Faculty Department of Computer Engineering Fall 2017 ECOM 2005 Khaleel I. Shaheen Computer Programming, I Laboratory Manual Experiment #3

### Chapter 2: Using Data

Chapter 2: Using Data TRUE/FALSE 1. A variable can hold more than one value at a time. F PTS: 1 REF: 52 2. The legal integer values are -2 31 through 2 31-1. These are the highest and lowest values that

### Reserved Words and Identifiers

1 Programming in C Reserved Words and Identifiers Reserved word Word that has a specific meaning in C Ex: int, return Identifier Word used to name and refer to a data element or object manipulated by the

### These are reserved words of the C language. For example int, float, if, else, for, while etc.

Tokens in C Keywords These are reserved words of the C language. For example int, float, if, else, for, while etc. Identifiers An Identifier is a sequence of letters and digits, but must start with a letter.

### false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 44

### COMP-202 Unit 2: Java Basics. CONTENTS: Using Expressions and Variables Types Strings Methods

COMP-202 Unit 2: Java Basics CONTENTS: Using Expressions and Variables Types Strings Methods Assignment 1 Assignment 1 posted on WebCt and course website. It is due May 18th st at 23:30 Worth 6% Part programming,

### FRAC: Language Reference Manual

FRAC: Language Reference Manual Justin Chiang jc4127 Kunal Kamath kak2211 Calvin Li ctl2124 Anne Zhang az2350 1. Introduction FRAC is a domain-specific programming language that enables the programmer

### CS5000: Foundations of Programming. Mingon Kang, PhD Computer Science, Kennesaw State University

CS5000: Foundations of Programming Mingon Kang, PhD Computer Science, Kennesaw State University Overview of Source Code Components Comments Library declaration Classes Functions Variables Comments Can

### Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal

Expressions and Data Types CSC 121 Spring 2015 Howard Rosenthal Lesson Goals Understand the basic constructs of a Java Program Understand how to use basic identifiers Understand simple Java data types

### CONTENTS: Compilation Data and Expressions COMP 202. More on Chapter 2

CONTENTS: Compilation Data and Expressions COMP 202 More on Chapter 2 Programming Language Levels There are many programming language levels: machine language assembly language high-level language Java,

### Differentiate Between Keywords and Identifiers

History of C? Why we use C programming language Martin Richards developed a high-level computer language called BCPL in the year 1967. The intention was to develop a language for writing an operating system(os)

### Chapter 2 Working with Data Types and Operators

JavaScript, Fourth Edition 2-1 Chapter 2 Working with Data Types and Operators At a Glance Instructor s Manual Table of Contents Overview Objectives Teaching Tips Quick Quizzes Class Discussion Topics

### CS2141 Software Development using C/C++ C++ Basics

CS2141 Software Development using C/C++ C++ Basics Integers Basic Types Can be short, long, or just plain int C++ does not define the size of them other than short

### IT 1204 Section 2.0. Data Representation and Arithmetic. 2009, University of Colombo School of Computing 1

IT 1204 Section 2.0 Data Representation and Arithmetic 2009, University of Colombo School of Computing 1 What is Analog and Digital The interpretation of an analog signal would correspond to a signal whose

### ARG! Language Reference Manual

ARG! Language Reference Manual Ryan Eagan, Mike Goldin, River Keefer, Shivangi Saxena 1. Introduction ARG is a language to be used to make programming a less frustrating experience. It is similar to C

### Basic data types. Building blocks of computation

Basic data types Building blocks of computation Goals By the end of this lesson you will be able to: Understand the commonly used basic data types of C++ including Characters Integers Floating-point values

### THE FUNDAMENTAL DATA TYPES

THE FUNDAMENTAL DATA TYPES Declarations, Expressions, and Assignments Variables and constants are the objects that a prog. manipulates. All variables must be declared before they can be used. #include

### Chapter 2 Using Data. Instructor s Manual Table of Contents. At a Glance. A Guide to this Instructor s Manual:

Java Programming, Eighth Edition 2-1 Chapter 2 Using Data A Guide to this Instructor s Manual: We have designed this Instructor s Manual to supplement and enhance your teaching experience through classroom

### VARIABLES AND CONSTANTS

UNIT 3 Structure VARIABLES AND CONSTANTS Variables and Constants 3.0 Introduction 3.1 Objectives 3.2 Character Set 3.3 Identifiers and Keywords 3.3.1 Rules for Forming Identifiers 3.3.2 Keywords 3.4 Data

### 3. Java - Language Constructs I

Educational Objectives 3. Java - Language Constructs I Names and Identifiers, Variables, Assignments, Constants, Datatypes, Operations, Evaluation of Expressions, Type Conversions You know the basic blocks

### Chapter 2: Data and Expressions

Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University January 15, 2015 Chapter 2: Data and Expressions CS 121 1 / 1 Chapter 2 Part 1: Data

### Tester vs. Controller. Elementary Programming. Learning Outcomes. Compile Time vs. Run Time

Tester vs. Controller Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG For effective illustrations, code examples will mostly be written in the form of a tester

### COMP Primitive and Class Types. Yi Hong May 14, 2015

COMP 110-001 Primitive and Class Types Yi Hong May 14, 2015 Review What are the two major parts of an object? What is the relationship between class and object? Design a simple class for Student How to

### JAVA Programming Fundamentals

Chapter 4 JAVA Programming Fundamentals By: Deepak Bhinde PGT Comp.Sc. JAVA character set Character set is a set of valid characters that a language can recognize. It may be any letter, digit or any symbol

### Unit 3. Constants and Expressions

1 Unit 3 Constants and Expressions 2 Review C Integer Data Types Integer Types (signed by default unsigned with optional leading keyword) C Type Bytes Bits Signed Range Unsigned Range [unsigned] char 1

### Elementary Programming

Elementary Programming EECS1022: Programming for Mobile Computing Winter 2018 CHEN-WEI WANG Learning Outcomes Learn ingredients of elementary programming: data types [numbers, characters, strings] literal

C How to Program, 6/e 1992-2010 by Pearson Education, Inc. An important part of the solution to any problem is the presentation of the results. In this chapter, we discuss in depth the formatting features

### Java enum, casts, and others (Select portions of Chapters 4 & 5)

Enum or enumerates types Java enum, casts, and others (Select portions of Chapters 4 & 5) Sharma Chakravarthy Information Technology Laboratory (IT Lab) Computer Science and Engineering Department The

### Language Fundamentals Summary

Language Fundamentals Summary Claudia Niederée, Joachim W. Schmidt, Michael Skusa Software Systems Institute Object-oriented Analysis and Design 1999/2000 c.niederee@tu-harburg.de http://www.sts.tu-harburg.de

### Standard 11. Lesson 9. Introduction to C++( Up to Operators) 2. List any two benefits of learning C++?(Any two points)

Standard 11 Lesson 9 Introduction to C++( Up to Operators) 2MARKS 1. Why C++ is called hybrid language? C++ supports both procedural and Object Oriented Programming paradigms. Thus, C++ is called as a

### Java Identifiers. Java Language Essentials. Java Keywords. Java Applications have Class. Slide Set 2: Java Essentials. Copyright 2012 R.M.

Java Language Essentials Java is Case Sensitive All Keywords are lower case White space characters are ignored Spaces, tabs, new lines Java statements must end with a semicolon ; Compound statements use

### Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word. Chapter 1 Introduction to Computers, Programs, and Java

Basic computer skills such as using Windows, Internet Explorer, and Microsoft Word Chapter 1 Introduction to Computers, Programs, and Java Chapter 2 Primitive Data Types and Operations Chapter 3 Selection

### BASIC COMPUTATION. public static void main(string [] args) Fundamentals of Computer Science I

BASIC COMPUTATION x public static void main(string [] args) Fundamentals of Computer Science I Outline Using Eclipse Data Types Variables Primitive and Class Data Types Expressions Declaration Assignment

### Entry Point of Execution: the main Method. Elementary Programming. Compile Time vs. Run Time. Learning Outcomes

Entry Point of Execution: the main Method Elementary Programming EECS2030: Advanced Object Oriented Programming Fall 2017 CHEN-WEI WANG For now, all your programming exercises will be defined within the

### Number Systems CHAPTER Positional Number Systems

CHAPTER 2 Number Systems Inside computers, information is encoded as patterns of bits because it is easy to construct electronic circuits that exhibit the two alternative states, 0 and 1. The meaning of

### Entry Point of Execution: the main Method. Elementary Programming. Learning Outcomes. Development Process

Entry Point of Execution: the main Method Elementary Programming EECS1021: Object Oriented Programming: from Sensors to Actuators Winter 2019 CHEN-WEI WANG For now, all your programming exercises will

### Chapter 2 Primitive Data Types and Operations

Chapter 2 Primitive Data Types and Operations 2.1 Introduction You will be introduced to Java primitive data types and related subjects, such as variables constants, data types, operators, and expressions.

### Chapter 2 Primitive Data Types and Operations

Chapter 2 Primitive Data Types and Operations 2.1 Introduction You will be introduced to Java primitive data types and related subjects, such as variables constants, data types, operators, and expressions.

### Basic Operations jgrasp debugger Writing Programs & Checkstyle

Basic Operations jgrasp debugger Writing Programs & Checkstyle Suppose you wanted to write a computer game to play "Rock, Paper, Scissors". How many combinations are there? Is there a tricky way to represent

### CSE 1001 Fundamentals of Software Development 1. Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018

CSE 1001 Fundamentals of Software Development 1 Identifiers, Variables, and Data Types Dr. H. Crawford Fall 2018 Identifiers, Variables and Data Types Reserved Words Identifiers in C Variables and Values

### INTRODUCTION 1 AND REVIEW

INTRODUTION 1 AND REVIEW hapter SYS-ED/ OMPUTER EDUATION TEHNIQUES, IN. Programming: Advanced Objectives You will learn: Program structure. Program statements. Datatypes. Pointers. Arrays. Structures.

### false, import, new 1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4

1 class Lecture2 { 2 3 "Data types, Variables, and Operators" 4 5 } 6 7 // Keywords: 8 byte, short, int, long, char, float, double, boolean, true, false, import, new Zheng-Liang Lu Java Programming 45

### The Java Language Rules And Tools 3

The Java Language Rules And Tools 3 Course Map This module presents the language and syntax rules of the Java programming language. You will learn more about the structure of the Java program, how to insert

### Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections

Introduction to Java Chapters 1 and 2 The Java Language Section 1.1 Data & Expressions Sections 2.1 2.5 Instructor: Scott Kristjanson CMPT 125/125 SFU Burnaby, Fall 2013 2 Scope Introduce the Java programming

### Chapter 3. Fundamental Data Types

Chapter 3. Fundamental Data Types Byoung-Tak Zhang TA: Hanock Kwak Biointelligence Laboratory School of Computer Science and Engineering Seoul National Univertisy http://bi.snu.ac.kr Variable Declaration

### Chapter 2: Data and Expressions

Chapter 2: Data and Expressions CS 121 Department of Computer Science College of Engineering Boise State University August 21, 2017 Chapter 2: Data and Expressions CS 121 1 / 51 Chapter 1 Terminology Review

### Data Types. 1 You cannot change the type of the variable after declaration. Zheng-Liang Lu Java Programming 52 / 87

Data Types Java is a strongly-typed 1 programming language. Every variable has a type. Also, every (mathematical) expression has a type. There are two categories of data types: primitive data types, and

### 1.1. Unit 1. Integer Representation

1.1 Unit 1 Integer Representation 1.2 Skills & Outcomes You should know and be able to apply the following skills with confidence Convert an unsigned binary number to and from decimal Understand the finite