lecture02

lecture02 - 1.00/1.001 - Session 2 Fall 2005 Basic Java...

Info iconThis preview shows pages 1–5. Sign up to view the full content.

View Full Document Right Arrow Icon
1.00/1.001 - Session 2 Fall 2005 Basic Java Data Types, Control Structures Java Data Types 8 primitive or built-in data types 4 integer types (byte, short, int, long) 2 floating point types (float, double) Boolean (boolean) Character (char) These are not objects 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Java Data Types These are defined (almost) identically on every machine on which Java runs, unlike other programming languages Java is a strongly typed language: Every variable must have a declared type Java Data Types Type Size (bits) Range byte 8 -128 to 127 short 16 -32,768 to 32,767 int 32 -2,147,483,648 to 2,147,483,647 long 64 -9,223,372,036,854,775,808L to 9,223,372,036,854,775,807L float 32 +/- 3.4E+38F (6-7 significant digits) double 64 +/- 1.8E+308 (15 significant digits) char 16 ISO Unicode character set boolean 1 true or false 2
Background image of page 2
What data type would you use? What would you use to store: Speed of light Your grade in this course Your grade point average this term Number of refrigerators in a room Location of a point on a screen 2 65 $234.77 Half of $234.77 Bits per second transmitted by modem What data type would you use? What would you use to store: Speed of light double Your grade in this course char Your grade point average this term double/float Number of refrigerators in a room int Location of a point on a screen float/int 2 65 BigInteger $234.77 double/int Half of $234.77 double/int Bits per second transmitted by modem int/float 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Using Java Data Types public class DataTypes { public static void main(String[] args) { boolean isReal=true; // Names are case sensitive, // start w/letter, have nos,_,$ byte d= 122; // Must be less than 127 short e= -29000; // Must be less than 32767 int f= 100000; // Must be less than 2.1 billion long g= 999999999999L; // Must put L on end float h= 234.99F; // Must be < 3E38; F on end double i= 55E100; char cvalue= '4'; // char '4' is not integer 4 // Strings are objects, not primitives. Example: String name= “Claudius”; } } Arithmetic Operators Table in precedence order, highest precedence at top Operators Meaning Associativity ++ + (unary) - (unary) increment decrement unary + ( x = +a)
Background image of page 4
Image of page 5
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/29/2011 for the course CIVIL 1.00 taught by Professor Georgekocur during the Spring '05 term at MIT.

Page1 / 13

lecture02 - 1.00/1.001 - Session 2 Fall 2005 Basic Java...

This preview shows document pages 1 - 5. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online