Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.

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

Lecture 9: More on objects, classes, strings discuss hw3 assign hw4 default values for variables scope of variables and shadowing null reference and NullPointerException.
CS0007: Introduction to Computer Programming Introduction to Classes and Objects.
Defining classes and methods Recitation – 09/(25,26)/2008 CS 180 Department of Computer Science, Purdue University.
Week 10: Objects and Classes 1.  There are two classifications of types in Java  Primitive types:  int  double  boolean  char  Object types: 
CSC Programming for Science Lecture 30: Pointers.
Java Syntax Primitive data types Operators Control statements.
What is a class? a class definition is a blueprint to build objects its like you use the blueprint for a house to build many houses in the same way you.
Object References. Objects An array is a collection of values, all of the same type An object is a collection of values, which may be of different types.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
Programming Principles Data types and Variables. Data types Variables are nothing but reserved memory locations to store values. This means that when.
Question of the Day  What card(s) must you flip to verify the following statement: Cards with a vowel on one side, have an even number on the other side.
Introduction to Java Appendix A. Appendix A: Introduction to Java2 Chapter Objectives To understand the essentials of object-oriented programming in Java.
Moving from C to Java. The Java Syntax We Know Java Types Some of the types we know and love are still there  Integer: byte, short, char, int, long.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
CSC 212 – Data Structures Lecture 12: Java Review.
Question of the Day  What card(s) must you flip to verify the following statement: Cards with a vowel on one side, have an even number on the other side.
CSC 212 Object-Oriented Programming and Java Part 1.
Polymorphism, Inheritance Pt. 1 COMP 401, Fall 2014 Lecture 7 9/9/2014.
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage.
English Conundrum s  In English, add “s” to end of word to make plural s  But for 1 special word, adding an “s” at the end:  Makes word go from plural.
CS 11 java track: lecture 4 This week: arrays interfaces listener classes inner classes GUI callbacks.
Chapter 8: Arrays.
C# D1 CSC 298 Elements of C# code (part 2). C# D2 Writing a class (or a struct)  Similarly to Java or C++  Fields: to hold the class data  Methods:
Problem of the Day  Why are manhole covers round?
CIT 590 Intro to Programming First lecture on Java.
Problem of the Day  Why are manhole covers round?
Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments.
College Board A.P. Computer Science A Topics Program Design - Read and understand a problem's description, purpose, and goals. Procedural Constructs.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Generic Programming  Object Type  Autoboxing  Bag of Objects  JCL Collections  Nodes of Objects  Iterators.
Chapter 10 Defining Classes. The Internal Structure of Classes and Objects Object – collection of data and operations, in which the data can be accessed.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Chapter 6 Introduction to Defining Classes. Objectives: Design and implement a simple class from user requirements. Organize a program in terms of a view.
Copyright Curt Hill Variables What are they? Why do we need them?
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Classes and Objects CS177 Rec 10. Announcements Project 4 is posted ◦ Milestone due on Nov. 12. ◦ Final submission due on Nov. 19. Exam 2 on Nov. 4 ◦
CSC 212 – Data Structures Lecture 2: Primitives, References, & Classes.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Java Classes Chapter 1. 2 Chapter Contents Objects and Classes Using Methods in a Java Class References and Aliases Arguments and Parameters Defining.
Object Oriented Software Development 4. C# data types, objects and references.
Spring 2009 Programming Fundamentals I Java Programming XuanTung Hoang Lecture No. 8.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Question of the Day You overhear a boy & his mother talking: Mom:What is ? Boy: That's easy, 33. Mom: Good. What's ? Boy:Simple. It's 40. Mom:Excellent!
Week 10 - Wednesday.  What did we talk about last time?  Method example  Roulette simulation  Types in Java.
 Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory. 
Today’s lecture Review chapter 5 go over exercises.
CSE 332: C++ pointers, arrays, and references Overview of Pointers and References Often need to refer to another object –Without making a copy of the object.
Week 10 - Monday.  What did we talk about last time?  Method overloading  Lab 9.
1 Enums (Chapter 4) To enumerate is: to name things one after another in a list Java has a type, called an enum, where a programmer specifies a finite.
LECTURE 21: RECURSION & LINKED LIST REVIEW CSC 212 – Data Structures.
Question of the Day  What three letter word completes the first word and starts the second one: DON???CAR.
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
JAVA Programming (Session 2) “When you are willing to make sacrifices for a great cause, you will never be alone.” Instructor: รัฐภูมิ เถื่อนถนอม
Basic Data Types อ. ยืนยง กันทะเนตร คณะเทคโนโลยีสารสนเทศและการสื่อสาร มหาวิทยาลัยพะเยา Chapter 4.
Apache Avro CMSC 491 Hadoop-Based Distributed Computing Spring 2016 Adam Shook.
Problem of the Day  Why are manhole covers round?
Java and C# - Some Commonalities Compile into machine-independent, language- independent code which runs in a managed execution environment Garbage Collection.
Question of the Day  How do you add 5 matches to these 6 & make 9?
Objects as a programming concept
Lecture 2: Primitives & References
CSE 116/504 – Intro. To Computer Science for Majors II
Selenium WebDriver Web Test Tool Training
Grouped Data Arrays, and Array Lists.
More About Objects and Methods
Chap 1 Chap 2 Chap 3 Chap 5 Surprise Me
Object Oriented Programming in java
Java Programming Language
Chap 2. Identifiers, Keywords, and Types
Presentation transcript:

Announcements  If you need more review of Java…  I have lots of good resources – talk to me  Use “Additional Help” link on webpage  Weekly assignments problems due before class  Remove rust from summer and get back into coding  Problems designed to help learn new material, too

Data Types  8+1 primitive data types  Examples: boolean, byte, char, int, double, String *  Only types that work with Java operators  Operators include: +, -, %, &&, ||, >=, <, !  Primitives used natively by computers  Means that using them is very quick  Implies greater support within the language

Primitive Types  Primitive variables are simple to use  Each variable is a “xerox” holding a value  Assignment copies value  Update variable being assigned only

Java Enumerations  enum a fancy type of Java class  Includes fields, methods & constructors like any class  But constructors must be private …  … so cannot create new instances of an enum  Specifies predefined list of instances  Instances declared at start of enum  Instances accessed as EnumName.instanceName  Represent known, finite data with an enum  3 Musketeers, 7 Dwarfs, Card Suits, …

Enumeration Methods  enum instances always include these methods  public String name() Returns String equal to actual instances' name  public int ordinal() Position in listing where instance was declared  Can also find all enumerated instances  public static EnumName[] values() Returns array of values enumerated by EnumName

Java Enumerations  Must be written in file EnumName.java public enum EnumName { Instance0, Instance1, Instance2; }  Can be used in methods elsewhere: EnumName var = EnumName.Instance0; System.err.println(var.name()); if (var.ordinal() > 1) { System.err.println(“Got Instance2!”); } EnumName[] arr = EnumName.values();

Quick Quiz  Should you be taking notes? Let’s see… 1. What are the 3 methods defined by each enum ? 2. What do each of these methods do? 3. Can you use ever compare an enum using “ > ”?

Classes  Real world needs more than primitives  Additional types defined by classes in Java  Classes usually begin with: public class ClassNameGoesHere {  By convention, name starts with capital letter  Use interior capitals to highlight words in name  Should be in file named ClassNameGoesHere.java  ClassNameGoesHere becomes type to use

Creating Instances  Use instances of a class  Keyword new creates instances: public class Kitty {... } new Kitty(...);

Reference Variables  Variables of class type are references  Must assign variable to instance before use  Variable is null when not referring to any instance  Work similar to a remote control  Reference is not object, but refers to object TV telly = new TV(...);

Reference Variables  Variables of class type are references  Must assign variable to instance before use  Variable is null when not referring to any instance  Work similar to a remote control  Reference is not object, but refers to object TV telly = new TV(...); telly

Reference Variables  Variables of class type are references  Must assign variable to instance before use  Variable is null when not referring to any instance  Work similar to a remote control  Reference is not object, but refers to object TV telly = new TV(...); telly

Reference Variables  Variables of class type are references  Must assign variable to instance before use  Variable is null when not referring to any instance  Work similar to a remote control  Reference is not object, but refers to object TV telly = new TV(...); telly

Using Instances  Use instances of a class  Each instance is unique  Each instance is unique Kitty cat = new Kitty(...); cat

Using Instances  Use instances of a class  Each instance is unique  Each instance is unique Kitty cat = new Kitty(...); Kitty tiger = new Kitty(...); cattiger

Using Instances  Use instances of a class  Each instance is unique  Each instance is unique Kitty cat = new Kitty(...); Kitty tiger = new Kitty(...); cat = new Kitty(...); cattiger

Using Instances  Use instances of a class  Each instance is unique  Each instance is unique Kitty cat = new Kitty(...); Kitty tiger = new Kitty(...); cat = new Kitty(...); cattiger

Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased

Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased Kitty cat, tiger; cat tiger

Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased Kitty cat, tiger; cat = new Kitty(...); cat tiger

Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased Kitty cat, tiger; cat = new Kitty(...); tiger = new Kitty(...); cat tiger

Working With References  Assignments alias references  Only way to create instance using new  Refer to same instance when aliased Kitty cat, tiger; cat = new Kitty(...); tiger = new Kitty(...); tiger = cat; cat tiger

 Aliased variables refer to same instance  Single instance get changes to aliased variables  Aliased variables see all changes that are made  But, assignments only affect the one variable Kitty cat, tiger, kat; cat = new Kitty(...); tiger = new Kitty(...); kat = tiger; tiger = cat; cat = kat; tiger = null; Aliasing cat tiger kat

Your Turn  Get into your groups and complete activity

For Next Lecture  Reading from AF Chapters 8 & 9 for Wednesday  What is the advantages of using arrays?  When and why sucks to use arrays?  Are arrays like primitives or references?  There is weekly assignment problem on Angel  Due before Wednesday’s lecture (via )  Get back into the swing of writing Java code