New User Special Price Expires in

Let's log you in.

Sign in with Facebook


Don't have a StudySoup account? Create one here!


Create a StudySoup account

Be part of our community, it's free to join!

Sign up with Facebook


Create your account
By creating an account you agree to StudySoup's terms and conditions and privacy policy

Already have a StudySoup account? Login here

CS 2420 Class notes week 2

by: Nick

CS 2420 Class notes week 2 CS 2420

Marketplace > University of Utah > Computer science > CS 2420 > CS 2420 Class notes week 2
The U
GPA 3.78

Preview These Notes for FREE

Get a free preview of these Notes, just enter your email below.

Unlock Preview
Unlock Preview

Preview these materials now for free

Why put in your email? Get access to more of this material and other relevant free materials for your school

View Preview

About this Document

Java basics, inheritance, polymorphism, object oriented programming, function objects, ArrayList, Arrays, Comparator, Comparable, generics
Intro Algorithms and Data Structures
Miriah Meyer
Class Notes
Computer Science, Java basics
25 ?




Popular in Intro Algorithms and Data Structures

Popular in Computer science

This 4 page Class Notes was uploaded by Nick on Monday September 5, 2016. The Class Notes belongs to CS 2420 at University of Utah taught by Miriah Meyer in Fall 2016. Since its upload, it has received 55 views. For similar materials see Intro Algorithms and Data Structures in Computer science at University of Utah.

Similar to CS 2420 at The U

Popular in Computer science


Reviews for CS 2420 Class notes week 2


Report this Material


What is Karma?


Karma is the currency of StudySoup.

You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!

Date Created: 09/05/16
CS 2420 This should all be a review Primitive types are different than reference types.  When pass a variable to a function it gets copied into that function so if try to use the passed  variable after passing it, then if it is a primitive then it will not be changed, but if it is a reference  type then it will be changed.  Be familiar with Arrays and ArrayLists, they are your friends in java.  Object oriented programming Data is treated as encapsulated in objects. Objects are instantiations of classes.  Not talking about the specific Object class (big O) Inheritance prevents the need for duplication of code when creating similar things.  The keyword for inheritance is extends Override changes the implementation of an inherited method only in the inherited class. So can  use the same name for both and get specific use of code.  We can partially override to use the base class and add to it directly.  Polymorphism A derived class is compatible with a base class Java will use the most specific class possible.  Every class inherits from the Object class in the Java language.  Abstract classes are a kind of class Uses the keyword abstract This means that this class cannot be used to make an object.  If Shape is an abstract method then cannot do this: Shape s = new Shape (); Interface is a kind of class that is thought of as the ultimate abstract class.  This means that this class cannot be used to make an object and no methods in it have bodies.  Uses the keyword implements  Provide a contract that guarantees objects of a certain type can do certain things.  All abstract methods must be implemented in subclasses.  Subclasses can only implement multiple interfaces but can only extend one base class.  We will use the Comparable interface a lot Inheriting Comparable means that can use the compareTo method.  Read Ch. 3 & 4 Assignment 1 is due Wed ­­ 8­31­16 Generic types T is a variable name. But T is the convention expected by programmers.  Can have more than one generic  Assignment 2 uses generics Cannot use an instantiated generic type as one of its parents. Where us generics, it must be  exactly the same type. Cannot pass in a Triangle to a function parameter generic asking for a  Shape.  Can use the question mark '?' as a wildcard. < ? extends Shape> will allow Triangle which extends from Shape <?> allows anything After using < ? extends Shape> it only knows Shapes. It does not know if anything extends  shape. After using generic as a parameter, the generic data structure used cannot be changed.  Now illegal to modify shapes in a method that uses this.  Not a good idea to work with inherited type after importing a parent type into the function  parameter. This is how you use generics.  If find yourself needing to ‘break’ java to get around it’s failsafe’s, then probably doing it wrong  and should talk to a TA.  Generics allow checking at compile time not runtime.  Compile time errors are better than runtime errors Generics only work with reference types, so use wrapper classes for primitives: Integer, Double  … Static methods can have their ow generic types <T> Can refer to T as a type inside that method only.  Function objects Object that contains a single method Every sorting function wants to sort any type.  To do this, need to compare and determine which is larger.  Comparable interface defines a natural ordering.  So can write a sorting function that takes a Comparator.  The compare method needs to return an integer Comparator is different than CompareTo Collection interface A generic data structure. Doesn’t say how the items are held.  Specifies the methods that such a class should have.  Will use this for Assign 3 Will use an array not ArrayList.  Items must be sorted as they are entered and should not allow duplicates.  When fill up the data structure underneath then need to grow it.  Good to double the size instead of adding one element. And, then copy over to new array. And  set the reference to the new array.  To prevent holes in the data in the underlying array you need to shift everything over.  Collection is like an array but can have more complex behaviors.  Iterators Not all data structures allow looping over an array with a for loop because there is no array in it. The iterator knows how to traverse through all elements of the data structure.  hasNext: determines f iteration is complete next: gets the next item … To use remove need to have called next () at least once.  Enhanced for loop  for(Thing  t : things) Do something with t It doesn’t care how you visit each item Read Ch. 5 & 6 No Class on Monday Next class will cover a lot of material. 


Buy Material

Are you sure you want to buy this material for

25 Karma

Buy Material

BOOM! Enjoy Your Free Notes!

We've added these Notes to your profile, click here to view them now.


You're already Subscribed!

Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'

Why people love StudySoup

Bentley McCaw University of Florida

"I was shooting for a perfect 4.0 GPA this semester. Having StudySoup as a study aid was critical to helping me achieve my goal...and I nailed it!"

Amaris Trozzo George Washington University

"I made $350 in just two days after posting my first study guide."

Jim McGreen Ohio University

"Knowing I can count on the Elite Notetaker in my class allows me to focus on what the professor is saying instead of just scribbling notes the whole time and falling behind."


"Their 'Elite Notetakers' are making over $1,200/month in sales by creating high quality content that helps their classmates in a time of need."

Become an Elite Notetaker and start selling your notes online!

Refund Policy


All subscriptions to StudySoup are paid in full at the time of subscribing. To change your credit card information or to cancel your subscription, go to "Edit Settings". All credit card information will be available there. If you should decide to cancel your subscription, it will continue to be valid until the next payment period, as all payments for the current period were made in advance. For special circumstances, please email


StudySoup has more than 1 million course-specific study resources to help students study smarter. If you’re having trouble finding what you’re looking for, our customer support team can help you find what you need! Feel free to contact them here:

Recurring Subscriptions: If you have canceled your recurring subscription on the day of renewal and have not downloaded any documents, you may request a refund by submitting an email to

Satisfaction Guarantee: If you’re not satisfied with your subscription, you can contact us for further help. Contact must be made within 3 business days of your subscription purchase and your refund request will be subject for review.

Please Note: Refunds can never be provided more than 30 days after the initial purchase date regardless of your activity on the site.