Download presentation
Presentation is loading. Please wait.
Published byLeonard Stanley Bradford Modified over 9 years ago
2
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
3
Primitives vs. References Primitive VariablesReference Variables Variables are copiers holding a value Assignment copies value Update variable being assigned only Aliased with assignments Now refer to same instance Both see updates to object Re-assigning variable does not update aliases
4
Opening Question Are array variables primitives or references?
5
Array Variables Arrays are special type of object Array variables are references in own right Like all variables, must be instantiated before use: int[] bob = new int[30]; Car[] parkingLot = new Car[300]; Array instances aliased by assignments Array variables like any reference variable
6
Memory Trace Example int[] data = new int[3]; int[] al = data; for (int i = 0; i < data.length; i++) { data[i] = i * 2; } al[0] = 5; al = new int[1]; al[0] = 7;
7
Entries Are Variables, Too! Within an array entries like individual variables int[] bob = new int[30]; Car[] parkingLot = new Car[300]; bob ’s entries would be primitive variables parkingLot ’s entries refer to instances Entries initialized like variable when array created bob ’s entries would all be set to 0 null stored in all entries within parkingLot
8
Memory Trace Example Car[] data = new Car[3]; Car[] al = data; for (int i = 0; i < data.length; i++) { data[i] = new Car(); } al[0] = new Car(); al = new Car[1]; al[0] = data[0];
9
Higher-Dimension Arrays Arrays instantiated with any dimension desired 2-d array is table
10
Higher-Dimension Arrays Arrays instantiated with any dimension desired 2-d array is table identifying entries by row & column int[][] pixels = new int[20][100]; pixels[1][45] = 32;
11
Higher-Dimension Arrays Arrays instantiated with any dimension desired 2-d array is table identifying entries by row & column int[][] pixels = new int[20][100]; pixels[1][45] = 32; Entries stored in virtual cube with 3-d array int[][][] bob = new Car[60][4][10]; bob[45][3][7] = new Car(); Rare to use higher dimensions, but are possible
12
Computer Professor MemoryHuge (> 250GB)Can’t remember 12 names Computing speed Fast (> 2 billion/second)Slow (needs fingers & toes) Takes direction Does exactly as toldLeaves toilet seat up Speed of updates Nearly instantaneousWears t-shirts from 1989 Ability to plan & reason Cannot make plans; No reasoning skills; Lacks common sense Makes (semi-)complicated plans; Good reasoning skills; Lacks common sense Computer vs. Professor
13
People are very good at reasoning & analyzing Slow computing outcome of each potential decision Considering every possible data combinations hard Trouble when lots of data available to be examined Computers can perform simple tasks quickly Maintain billions of data items within memory Very good when at performing simple operations Cannot create plan since lacks concept of future To do any task, must be given specific instructions People vs. Computers
14
Computers best processing huge data sets Perform specific tasks and output results: College’s students’ transcripts available Compute & print receipt for groceries Filter & provide few items for user to choose from Personalized recommendations from Amazon Google’s list of matching web pages Most of year examines how to organize data How data used determines structures selected Computers Use Collections
15
How Could We Do This? Know simple way to organize data: array Entries refer to another array to create matrices Many limitations arise when using arrays Must specify unchangeable size when created Pirate[] rum = new Pirate[1]; Pirate[] h2o = new Pirate[ variable ]; rum = new Pirate[60]; // old rum was lost! h2o = rum; // h20 now alias to rum’s instance Waste memory requiring maximum size for array /* Each Amazon.com customer uses 400+MB of RAM! */ Rating[] hertz = new Rating[100000000];
16
Often need to keep values ordered or organized Alphabetical list of names & phone numbers Keep list of job bids from smallest to largest Web pages ordered from most to least important Desired index’s not just assigned new value Lose current value stored at that index Instead, must first shift values within the array Inserting into an Array 12 n e 0
17
Still need to keep values ordered or organized Removing a value presents own set of problems Could simply assign null, but that creates a gap Finding start & end of data hard once gaps allowed Instead, must shift values to fill in all gaps that exist Removing From an Array 0 12 n
18
Your Turn Get into your groups and complete activity
19
For Next Lecture Reading from AF 7.1 – 7.10 for Friday What are fields and methods again? How do they get used? What is the point of a constructor? There is weekly assignment problem on Angel Due before Friday’s lecture (via e-mail) Get back into the swing of writing Java code
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.