Presentation is loading. Please wait.

Presentation is loading. Please wait.

Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values.

Similar presentations


Presentation on theme: "Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values."— Presentation transcript:

1 Java 2 More Java Then Starbucks ;-)

2 Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values and the things that can be done to them Operators – Used to perform operations on primitive data types. Object Class

3 Objects An object is an instance of a class. They have properties. They can be acted upon by invoking methods. Encapsulation – “Each object protects & manages its own information”…Your car keeps track of its mileage/fuel gauge and only its mileage/fuel gauge.

4 What’s a Class? Used to define the data type of an object. If you prefer, think of a class as defining a concept for something. A method is used to define what operations we can perform on an object. Auto Objects Auto Class

5 Inheritance One class can extend another class (parent/child) Cars & trucks share many common elements so we just inherit the auto class properties & methods and add or modify what is needed to create a truck. Truck Objects Auto Class Truck Class

6 Escape Characters String literals are defined by placing them between “” quotes. Some characters have special meaning to Java and can’t be used between quotes or are ignored as “white space.” \t = tab \n = newline \” = “ P. 71 in book for more

7 The + Operator Works on Text and Numbers! Concatenation – Sticking on string onto the end of another. “Hello” + “World” = “Hello World” All operators listed in Appendix D of the Java book! Arithmetic operators are “right to left” associative. See p. 82 in book too.

8 Variables Named location in memory used to hold a value. Must be declared so memory can be reserved. They type of data to store in the memory space must be defined. May or may not be initialized when reserved. = operator is “Assigned” not “Equals”

9 Primitives byte – 8 bits short – 16 bits int – 32 bits long – 64 bits float – 32 bits double – 64 bits Ranges on p. 77 in Java book

10 Conversions Narrowing or Widening Assignment this = that Arithmetic promotion this = a / b Casting this = (int) that

11 Literals Integer literals are assumed to be of type “int” unless an l or L is appended to it. Floating point literals are assumed to be of type “double” unless an f or F is appended to it. Character literals are defined between single quotes ‘ String literals between double quotes “

12 Creating Objects Variables hold either primitive data or a reference to an object. Instantiation is the “fancy” term for creating objects with the new operator. String first = new String(“Bob”) “.” operator used to access object methods.

13 The String Class Strings are objects instantiated from the string class. String objects are “immutable” See string sample code.

14 Libraries & Packages Java standard class library is composed of useful classes that help us to achieve our programming goals but are not a part of the Java language Java packages are groups of classes that we can call by a single name…the String class is part of the java.lang package. Some packages are listed on p. 94

15 Importing Classes Java.lang packages are automatically available to every program we write. To access other packages we must use a fully qualified reference to the package or import it. import java.util.*; import cs1.Keyboard;

16 Basic Conditional Statements if (this > that) { this++; } else { that++; }

17 Basic Conditional Statements Equality Operators… == equal to !=not equal to greater than >=greater than or equal to


Download ppt "Java 2 More Java Then Starbucks ;-). Important Terms Primitive Data – Basic, built-in values (characters & numbers) Data Type – Used to talk about values."

Similar presentations


Ads by Google