 Base “primitive” types: TypeDescriptionSize intThe integer type, with range -2,147,483,648... 2,147,483,647 4 bytes byteThe type describing a single.

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

COMP 14 Introduction to Programming
Chapter 2: Java Fundamentals cont’d
Air Force Institute of Technology Electrical and Computer Engineering
Question from the last class What happens if we cast “too large” float/double to an int? int has range float a=1e10f; int b=(int)
Self Check 1.Which are the most commonly used number types in Java? 2.Suppose x is a double. When does the cast (long) x yield a different result from.
Introduction to Computing Concepts Note Set 7. Overview Variables Data Types Basic Arithmetic Expressions ▫ Arithmetic.
Types, Variables and Operators Computer Engineering Department Java Course Asst. Prof. Dr. Ahmet Sayar Kocaeli University - Fall 2013.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 2 1 Chapter 2 Primitive.
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.
Chapter 2 Primitive Data Types and Operations F Introduce Programming with an Example F Identifiers, Variables, and Constants F Primitive Data Types –byte,
IntroductionIntroduction  Computer program: an ordered sequence of statements whose objective is to accomplish a task.  Programming: process of planning.
Chapter 2: Using Data.
©2004 Brooks/Cole Chapter 2 Variables, Values and Operations.
Primitive Data Types and Operations. Introducing Programming with an Example public class ComputeArea { /** Main method */ public static void main(String[]
CIS 234: Using Data in Java Thanks to Dr. Ralph D. Westfall.
Mathematical Operators  2000 Prentice Hall, Inc. All rights reserved. Modified for use with this course. Introduction to Computers and Programming in.
1 Chapter 3 Arithmetic Expressions. 2 Chapter 3 Topics l Overview of Java Data Types l Numeric Data Types l Declarations for Numeric Expressions l Simple.
Datalogi A 3: 26/9. Java Concepts chapter 4 Fundamental Data Types int (long and short) double (and float) boolean char String.
Introduction to Computers and Programming Lecture 4: Mathematical and Relational Operators.
Computer Science A 2: 6/2. Course plan Introduction to programming Basic concepts of typical programming languages. Tools: compiler, editor, integrated.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie June 27, 2005.
Fundamental Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
Fundamental data types Horstmann Chapter 4. Constants Variables change, constants don't final = ; final double PI = ; … areaOfCircle = radius *
Fundamental concepts in Java. Lesson plan Variable declaration, assign statement & practice Design document & practice.
1 Number Types  Every value in Java is either: 1.a reference to an object or 2.one of the eight primitive types  eight primitive types: a.four integer.
Chapter 2: Basic Elements of Java J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Chapter 4 Numeric types & arithmetic Strings: reading & writing.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter Four: Fundamental Data Types.
Chapter 2 Basic Elements of Java. Chapter Objectives Become familiar with the basic components of a Java program, including methods, special symbols,
Simple Data Types and Statements. Namespaces namespace MyNamespace { // …. { MyNamespace::func1() using namespace OtherNamespace; Comments: // /* xxxx.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter 4 – Fundamental Data Types.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter Four: Fundamental Data Types.
Chapter 2: Using Data.
Week 5 Introduction to Computer Science and Object-Oriented Programming COMP 111 George Basham.
BUILDING JAVA PROGRAMS CHAPTER 2 PRIMITIVE DATA TYPES AND OPERATIONS.
Java Programming: From Problem Analysis to Program Design, 4e Chapter 2 Basic Elements of Java.
Java Programming: From Problem Analysis to Program Design, 5e Chapter 2 Basic Elements of Java.
Types CS 21a: Introduction to Computing I Department of Information Systems and Computer Science Ateneo de Manila University (Chapter 4, Horstmann text)
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. int: integers, no fractional part: 1, -4, 0 double : floating-point.
Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Chapter Four: Fundamental Data Types.
Programming Process Programming in Java is an exercise in using pre-defined classes and writing new classes to fill in the gaps A procedure for determining.
Primitive Variables.
Chapter 2 Variables.
Copyright © – Curt Hill Types What they do.
Java Programming, Second Edition Chapter Two Using Data Within a Program.
COMP Primitive and Class Types Yi Hong May 14, 2015.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 2A Reading, Processing and Displaying Data (Concepts)
“Great leaders are never satisfied with current levels of performance. They are restlessly driven by possibilities and potential achievements.” – Donna.
C++ for Everyone by Cay Horstmann Copyright © 2012 by John Wiley & Sons. All rights reserved Chapter Two: Fundamental Data Types Slides by Evan Gallagher.
CompSci Primitive Types  Primitive Types (base types)  Built-in data types; native to most hardware  Note: not objects (will use mostly first.
CSM-Java Programming-I Spring,2005 Fundamental Data Types Lesson - 2.
Chapter One Lesson Three DATA TYPES ©
FUNADAMENTAL DATA TYPES LEARNING OBJECTIVES: TO UNDERSTAND INTEGEr AND FLOATING POINT NUMBERS TO RECOGNIZE THE LIMITATIONS OF THE NUMERIC TYPES TO UNDERSTAND.
Java Programming: From Problem Analysis to Program Design, Second Edition 1 Lecture 1 Objectives  Become familiar with the basic components of a Java.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. A string is a sequence of characters Strings are objects of the String.
Primitive Data Types and Operations F Introduce Programming with an Example F Identifiers, Variables, and Constants F Primitive Data Types –byte, short,
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.
Chapter 4 – Fundamental Data Types
2.5 Another Java Application: Adding Integers
Multiple variables can be created in one declaration
Java Programming: From Problem Analysis to Program Design, 4e
Chapter 2: Basic Elements of Java
Chapter 2 Variables.
Chapter 2: Java Fundamentals
Fundamental OOP Programming Structures in Java: Comments, Data Types, Variables, Assignments, Operators.
In this class, we will cover:
Chapter 2 Variables.
Presentation transcript:

 Base “primitive” types:

TypeDescriptionSize intThe integer type, with range -2,147,483, ,147,483,647 4 bytes byteThe type describing a single byte, with range byte shortThe short integer type, with range bytes long The long integer type, with range -9,223,372,036,854,775, ,223,372,036,854,775,807 8 bytes doub le The double-precision floating-point type, with a range of about ± and about 15 significant decimal digits 8 bytes Primitive Types float The single-precision floating-point type, with a range of about ±10 38 and about 7 significant decimal digits 4 bytes char The character type, representing code units in the Unicode encoding scheme 2 bytes bool ean The type with the two truth values false and true1 bit

Constants

Create Examples 1.Create a constant for number of inches in an foot (FOOT_VALUE) 2.Create a constant for number of feet in a yard (YARD_VALUE). 3.Write code to find out how many yards given n feet. Constants: final

Precedence OperatorDescription Higher ( )Parentheses +Positive - Negative * Multiplication / Division % Modulus (remainder) +Addition Lower - Subtraction =

 Sample Arithmetic Expressions: 2 2 * * / 2 10 % 3 (2 + 3) * (11 / 12)

 May mix types  Two variables only at a time!  Mod (%) operator:

We can also do this using shorthand = a += 5; a = a + 5; a -= 5; a = a - 5; a *= 5; a = a * 5; a /= 5; a = a / 5; a %= 5; a = a % 5; a++; a = a + 1; a--; a = a - 1;

 Variable increment operators: i++ ++I

A String: String constants String variables: String length: Empty string Strings

String sub = greeting.substring(0, 5); // sub is "Hello“ Substrings

Dialog Boxes

static String showInputDialog (object msg) number = JOptionPane.showInputDialog (“Enter a number: “); Enter an Integer: ? OK Cancel 24 Input

static int showConfirmDialog (component parent, object msg) ans = JOptionPane.ConfirmDialog (“Try Again? “); Try Again? ? NoCancel Select an Option Yes

static void showMessageDialog (component parent,object msg) JOptionPane.showMessageDialog (“The Number is an Integer “); The Number is an Integer i OK Message

parseInt parseLong, parseFloat parseDouble

double _y1; int _y2; String _number; number = JOptionPane.showInputDialog (“Enter a number: “); y1=Double.parseDouble(_number); y2= Integer.parseInt (_number);

Big Java by Cay Horstmann Copyright © 2008 by John Wiley & Sons. All rights reserved. Math Class: sqrt pow round Plus others