DOC PREVIEW
TRINITY CSCI 1311 - Reference Types
Pages 9

This preview shows page 1-2-3 out of 9 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 9 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1Reference Types10/24/20072Opening Discussion■Let's look at solutions to the interclass problem.■What people want to learn in Java.How to use it.Making a football or stats program.Pretty pictures (graphics).A scheduling/organizing program.Formal logic.Tracking spending.Flash movies.■Difference between theseScanner sc=new Scanner(System.in);Scanner kdb=new Scanner(System.in);■Difference between Java, C, and C++. What is windows written in?3Reference Types■The “built in” primitive types are not the only types in Java. Classes define types as well. These are called reference types.■We declare variables for reference types just like we would for primitive types.■Reference types can either refer to an object of the proper type, or they can be null.■Trying to use a null reference causes an exception.■You have already used a reference type variable when you use Scanner. Scanner is a class in the Java libraries.4What is a Reference?■Reference variables are called that for a reason. Instead of being an object, they refer to an object.■This is in contrast to a primitive variable which actually is the thing you declare it to be.■Because of this, a single reference variable could refer to several different objects over it's life.5Instantiating Objects■To make a new object we use the new keyword. The syntax for making an object is as follows:new Type(argumentList)■You will often see this on the right side of an assignment.■This tells Java to go out and get memory and set up an object of the specified type using that values that are passed in.■You have seen this already when working with a Scanner object to read values.6Calling Methods/Sending Messages■Once you have a reference variable that refers to a real object you can use the dot notation to call methods on that object.■This is what you have been doing with the Scanner object when you call methods like nextDouble().7The String Type■One of the most fundamental classes in Java is the String class. It represents any set of characters that you need to work with.■Let's look at String in the API.■The + operator is overloaded for String. Operators only work on primitives and, in this one instance, Strings.■Difference between null and empty Strings.■String literals are put in double quotes.■String objects are immutable. They don't change. Instead you build new String objects.■Checking equality.Use the equals method, not ==.8Wrapper Classes■There are some other classes that are very fundamental to Java that your book doesn't mention.■These are the wrapper classes in Java that have names like primitives, but start with capital letters.■For our purposes, the main use of these classes are the helpful methods they in them. These include things like converting strings to numbers.9Minute Essay■Write a little segment of code that has th user input a word and prints out how many letters are in the word.■Interclass Problem – Do problem 8.8. Warning: this isn't hard to program, but will take some


View Full Document

TRINITY CSCI 1311 - Reference Types

Course: Csci 1311-
Pages: 9
Documents in this Course
Arrays

Arrays

12 pages

Arrays

Arrays

10 pages

Applets

Applets

5 pages

Arrays

Arrays

8 pages

Methods

Methods

12 pages

Drawing

Drawing

8 pages

Load more
Download Reference Types
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Reference Types and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Reference Types 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?