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

Data Structures with JAVA

by: Trent Dare

Data Structures with JAVA CS 259L

Trent Dare
GPA 3.76

Joel Castellanos

Almost Ready


These notes were just uploaded, and will be ready to view shortly.

Purchase these notes here, or revisit this page.

Either way, we'll remind you when they're ready :)

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

Joel Castellanos
Class Notes
25 ?




Popular in Course

Popular in ComputerScienence

This 16 page Class Notes was uploaded by Trent Dare on Wednesday September 23, 2015. The Class Notes belongs to CS 259L at University of New Mexico taught by Joel Castellanos in Fall. Since its upload, it has received 36 views. For similar materials see /class/212201/cs-259l-university-of-new-mexico in ComputerScienence at University of New Mexico.


Reviews for Data Structures with JAVA


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/23/15
39l39HE UNIVERSI39I Yg quot 7 NEWMEXICO 08259 Data Structures with Java Welcome Instructor Joel Castellanos email 39oelunmedu W web httgcsunmedu39oe m Course website httpcsunmedu39oecs259 EZEZEIEIB Introductions I Your Name I Your Background in Computer Programming quiokBasio Visual Basic FORTRAN C C or hours and hours of WOW I UNM major intended major just taking one class I Why you are taking this class and what you expect to get from it ZOMQ Course Resources Class website httQcs unmed u39oecs259 u Syllabus COre Javaquot Volume l Fundamentals a Lecture Notes Hum inmmi I Supplemental readings Textbook Core Java Volume I Fn m ntal thEiti n I Cay S Horstmann and Gary Cornell WebCT httpvistaunmedu in Grades m Homework assignments Grades Midterm Exam 15 Final Exam 15 iclicker quizzes 10 Labs 30 Projects 30 I Attendance is required for both iclicker and lab grades k I We will use the igtclicker for quizzes every lecture I Your iclicker needs to be registered with your name and UNM NetID I If you have already registered your igtclicker last semester on the web for a different class then you do not need to register again I Register your name as it appears in your UNM NetID l One igtclicker can be registered by different people in different classes I If your igtclicker registration number has rubbed off see me after class iclicker Wei Registration I httpvwvwiclickercomregistration Tigtcickelr ha Dacia3r a Simpa Register Your igtcicker Fir Marne Lasiiiame Student iE39 R mnte iD Quiz Question 1 Do you have your iclicker a Yes I am ready to go b I bought one from the bookstore but forgot it 0 My dog ate it d No I did not get one yet e What is an iclicker anyway Who Should Take This Course l Someone who has studied Java in school on ajob or is selftaught but does not feel readyto skip 08152 and take 08251 l Someone who has solid programming experience but does not know anything about Java A person who knows C or FORTRAN well enough to write a program that calculates the rst 50 prime numbers w u probably be board in 08152 but without any Java experience would be lost on dayone of 08251 I An engineering science or math student with junior or senior standing who generally gets As or Bs Even if that student has never taken a programming class he or she would probably nd this class more interesting and appropriately challenging than the 08152 amp 08251 series I Calculus is not required or used in this class but a student straight out ofhigh school who found AP calculus and AP physics fairly easy would be much happier in this class than in 08152 amp 08251 Homework Due Wed Aug 26 Read Chapter 1 I Java as a Programming Platform I Java Buzzwords I Java Applets and the Internet I A Short History of Java WI Common Misconceptions about Java Wednesday igtcicker quiz on the reading 9 Java Rocks I Advantages for Large Programs I JUnit Testing I JavaDocs I ObjectOriented I Platformindependent I Secure I Robust emphasis on early checking for possible errors I Multithreaded I Well suited for Automated Optimization 10 Compilation A compiler translates human readable source code to machine instructions area 05 base height Load 05 Load OXOOOO17ABO Multiply Load OXOOOO42331 Multiply Store OX000112355 t JDK F f I Compiler quot V 39 Java Runtime Environment JRE u i g B ytecode Class Justln Verifier Loader Time g Compiler Java Performance Wikipedia Programs written in Java have had a reputation for being slower and requiring more memory than those written in natively compiled languages such as C or C However Java programs39 execution speed has improved significantly due to introduction of JustIn Time compilation in 19971998 for Java 11 language features supporting better code analysis and optimizations in the Java Virtual Machine itself such as HotSpot becoming the default for Sun JVM in 2000 Micro Benchmarks vs Production Code CC wins on small I Hand optimized Pointers are quick I Native floatingpoint operations I No error checking I Quick statup Java often wins on big I Cstyle pointers make optimization hard in languages that support them particularly ne grain parallelism I Adaptive optimization is impossible in fully compiled code I Auto Garbage Collection beats application programmer GC 14 Structured Programming Find Prime Factors while testNumber lt endTest if n testNumber 0 testNumber divides n SystemoutprintlntestNumber n n testNumber else testNumber does not divide n testNumber OOP ObjectOriented Programming Do not be afraid of GOP Small Java I rovrams are often not objectoriented GOP is a superset of structured programming Inside each method aka subroutine OOP uses structured programming style An objectoriented program may be viewed as a collection of cooperating objects In a conventional model a program is seen as a list of tasks subroutines to perform in some order 16 ObjectOriented Programming part 2 I In OOP each object is capable of receiving messages processing data and sending messages to other objects and can be viewed as an independent 39machine39 I The actions or quotoperatorsquot on these objects are often part ofthe object For example in an employee database there might be an Employee object with Fields such as rstName lastName salary c Methods actions such as alphabetize that looks at the lexicographical order ofthe last name and if they are the same then looks at the lexicographical order of the rst name Object Oriented Programming part 3 I GOP is a programming paradigm that uses quotobjectsquot and their interactions to design computer programs I As software became increasingly complex quality was often compromised and reuse became critical OOP was in part developed to address these common problems by strongly emphasizing discrete reusable units of programming logic I Information hiding I Data abstraction III Encapsulation r Modularity in Inheritance Class Ideas I What is Java lWhat is Computer Programming lWhat is ObjectOriented Programming CS 259 Data Structures with Java Prime Numbers and Prime Factors Instructor Joel Castellanos email 39oeunmedu web httpcsunmedu39oe Course website httpcsunmeduioecs259 8292009 Prime Numbers Can you Is n Prime Facts I If n is not divisible by any number smaller than n then n is prime I To prove n is not prime only one factor needs to be found I If n is not prime then there exists a pair of integers a and b such that naxb I If naxb then either a or b must be less than or equal to the square root of n I Therefore starting from 2 and counting up if no factors have been found from 2 through n then n must be prime Is n Prime The Algorithm 1 Given n calculate the largest possible first factor largestPossibleFirstPrime n Let testDivisor 2 9 If testDivisor is greater than largestPossibleFirstPrime then stop checking because n is prime A If testDivisor is a factor of n then n is not prime 01 lf testDivisor does not a factor of n then increment testDivisor and return to step 3 Is n Prime By for Loop public static void mainString args int n 64 int largestPossibleFirstPrime boolean foundDivisor false intMathsqrtn for int k2 k lt largestPossibleFirstPrime k Systemoutprintlnquotkquotk if n k k2 foundDivisor true k3 k4 k5 k6 if foundDiVisor k7 Systemoutprintln k8 n quot is NOT Primequot 64 is NOT Prime else Systemoutprintlnn quot is Prime quot Is n Prime By while Loop public static void mainString args int n 64 int largestPossibleFirstPrime boolean foundDivisor false int k2 whilek lt largestPossibleFirstPrime Systemoutprintlnquotkquotk if nk foundDivisor break true intMathsqrtn k is created and initialized outside the loop tested in thewhile statement and incremented inside the loop k if foundDivisor Systemoutprintlnn quot else Systemoutprintlnn quot is Prime is NOT Primequot quot for Loop verses while Loop public static void mainstring args for int i0 ilt12 ii3 Systemoutprintquotiquot i quot quot Systemoutprintln int k0 while klt12 Sstemoutrintquotkquot k quot quot kk3 Output for is more compact i0 i3 i6 i9 while is more general k0 k3 k6 k9 Prime Factors 9 33 100 1010 awcu 13 13 420 1042527652723 100 250 2225 92255 The above is a nonsystematic method Finding Prime Factors Algorithm 90 01 Let n be the number of which to find the prime factors Start with 2 as a test divisor lfthe test divisor is greater than the square root of n then the test divisor is either 1 or prime and we are done lfthe remainder of n divided by the test divisor is zero then a The test divisor is a prime factor of n Print it 1 Replace n with n divided by the test divisor c If the new n equals one then all the divisors have been found lfthe remainder of n divided by the test divisor not zero then a Increment the test divisor 6 Loop to step 3 Prime Factors Example n1OO I Start with n100 and testDivisor 2 I 2 divides 100 so print 2 an set n100250 I 2 divides 50 so print 2 and set n50225 I 2 does not divide 25 so increment testDivisor to 3 I 3 does not divide 25 so increment testDivisor to 4 I 4 does not divide 25 so increment testDivisor to 5 I 5 divides 25 so print 5 and set n2555 I 5 divides 5 so print 5 and set n551 I Since n is equal to 1 stop Lab 2 Prime Factors I Write a Java program that hardcodes a positive integer value final int ORIGINALNU39MBER and uses the given prime factor algorithm to correctly print that ORIGINALNU39MBER is prime or to print its prime factors I All repeated factors must be printed I The prime factors must be printed in order from smallest to largest I Your code must work for all positive integer values of ORIGINALNU39MBER from 1 through 2 billion I Your output must include the value of ORIGINALNU39MBER and must be clearly represented Lab 2 Grading Rubric I Total points 20 I Your code will be run with 12 test cases ofunknown legal values of ORIGINALNU39MBER You will receive one point for each correct that matches the specs result Proper adherence to the 08259 coding standard including comments is worth 5 points You start with those 5 points and each error levies a 1 up to the maximum of5 points 3 Points your code is ef cient ie does not retest many values and your code is easy to read 2 points for each compiler warning Due Date Midnight on Monday Aug 31


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

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."

Allison Fischer University of Alabama

"I signed up to be an Elite Notetaker with 2 of my sorority sisters this semester. We just posted our notes weekly and were each making over $600 per month. I LOVE StudySoup!"

Steve Martinelli UC Los Angeles

"There's no way I would have passed my Organic Chemistry class this semester without the notes and study guides I got from StudySoup."


"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.