1 / 8

Overview

Primitive Data Types Expressions Literals Arithmetic Operators Precedence Mixing Types & Casting. Overview. Introduction. Programs are built to manipulate information Java is strongly typed language – it requires you to be explicit about what kind of information you intend to manipulate

xarles
Download Presentation

Overview

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Primitive Data Types Expressions Literals Arithmetic Operators Precedence Mixing Types & Casting Overview

  2. Introduction • Programs are built to manipulate information • Java is strongly typed language – it requires you to be explicit about what kind of information you intend to manipulate • e.g. James vs. Jomes, web vs. Web, Pat vs. pat • Java supports 2 different kinds of data • Primitive data • Objects

  3. Primitive Types • 8 primitive data types – 4 of which are fundamental (other 4 are variations) • Yes integers are a subset of real numbers – but they are fundamentally different types of numbers, e.g. depending on the type of number we expect we ask: • “how many siblings?” or “how much siblings?” • “how many does it weigh” or “how much does it weigh?” • In programming the distinction is more important because integers and real numbers are represented in a different way in the computer’s memory

  4. Expressions • Expressions: value or set of operations that produce a value e.g. • (2 * 8) + (5 +6) -1 • Operators and operands • Many things to do with expressions • One of the simplest: System.out.println(42); 42 System.out.println(2+8); 10

  5. Literals • Literals: the simplest form of expression: • 0, -2349, +567, 4, 93 • A floating-point literals is a type double: • -2349.0 -.82 0.982 64.2 23. • Literals of type double can also be expressed in scientific notation: • 2.3e6 1e-5 4.523e34 • Character literals (of type char) are enclosed in single quotation marks and can include just one character: • ‘f’ ‘C’ ‘!’ ‘3’ ‘\\’ ‘\’’ • Primitive type boolean sores logical information – • the 2 Java keywords that are literal values of type boolean are: true false

  6. Arithmetic Operators • Why do we care for mod values • Testing to see if a number is odd or even (number % 2 = ____ will give us even and = ____ will give us odd • Finding individual digits of a long number (e.g. number % 10 is always the _____ digit) • Finding the last 4 digits of a social security number (number % 10000) – try it!

  7. Precedence

  8. Mixing Types & Casting • Suppose you have some books that are 0.15 ft wide and you want to know how many will fit in a shelf that is 2.5 ft wide – what you want is the ______

More Related