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

CS12300 Week 7 Notes

by: Ashlin Gibson

CS12300 Week 7 Notes CS12300

Ashlin Gibson
Purdue University Calumet
GPA 3.89
View Full Document for 0 Karma

View Full Document


Unlock These Notes for FREE

Enter your email below and we will instantly email you these Notes for Programming I: Java

(Limited time offer)

Unlock Notes

Already have a StudySoup account? Login here

Unlock FREE Class Notes

Enter your email below to receive Programming I: Java notes

Everyone needs better class notes. Enter your email and we will send you notes for this class for free.

Unlock FREE notes

About this Document

General tips for exams (cannot post the exam itself) For Loops Very brief start on classes
Programming I: Java
Dr. Hairong Zhao
Class Notes
java, programming, CS12300, Math, for, Loop, class, classes, Object, objects, program




Popular in Programming I: Java

Popular in Computer science

This 6 page Class Notes was uploaded by Ashlin Gibson on Sunday October 9, 2016. The Class Notes belongs to CS12300 at Purdue University Calumet taught by Dr. Hairong Zhao in Fall 2016. Since its upload, it has received 17 views. For similar materials see Programming I: Java in Computer science at Purdue University Calumet.

Similar to CS12300 at Purdue University Calumet


Reviews for CS12300 Week 7 Notes


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: 10/09/16
CS12300-002 Java Programming Week 7 10/09/2016 Post-Exam 1 The exams in this class are cumulative, so make sure there is a concrete understanding of existing material. I am of course prohibited from posting the exam and its answer key, but I can give pointers on how to approach the types of questions. True/False: Try to learn the individual quirks of Java and its syntax. Know the data allocation of the basic types (variables like int and double etc.), definitions, and how Java handles code compilation and execution. Proving a statement false rather than true is much easier. Only 1 counter example must be found to prove falsehood. Always try and think of something that would make a statement definitely false. Proving truth unfortunately requires understanding of every possible case. Also there is of course a ~50% chance of guessing right anyway. Multiple Choice: ~20% or ~25% chance of guessing right. For multiple choice, always try and eliminate obviously wrong choices to increase that chance. Most traditional questions and their choices can be eliminated to 2 answers, a 50/50. The remaining 2 choices are usually related or seem both possibly correct, unfortunately. The rest is up to personal knowledge and studying. Double guessing has worked against me more than for. Evaluation: Work everything out step by step like a math problem without assumption or skipping steps. Remember also that programming is not written exactly like math. For large expressions, try and work in small sections and simplify. For code excerpts, computers run everything sequentially, step-by-step. Do the same to avoid mistakes and get through a problem. CS12300-002 Java Programming Week 7 10/09/2016 Writing Code: Memorize defining the main class and its name, and the main Java line (public static void main(String[] args)). Braces always come in pairs, and always choose to use braces rather than not. Figure out and write down what the problem is and what is supposed to be accomplished. If the method is not stated, logically work out a solution to the problem. The programming solutions to problems in basic classes like this are never hideously complex. If your method is therefore hideously complex, it is probably wrong, inefficient, or on purpose (don’t). After writing your solution, pretend you are computer and run through it step-by-step. This will essentially double check your work and catch any errors. Always try cases that can break your code. Syntax errors are not as important, but remember semicolons, braces and parentheses in pairs. When double checking your work, it may help to write down the state of variables/output of the code at that certain line on the side. You might be able to catch errors this way. Things that need to be concrete now or soon: Syntax so your program actually runs, the basic covered String methods, how to write an expression (such as for if/while blocks), how while loops work. I’ll have a study guide up on StudySoup before exam 2. For Loops For loops are just a shorthand way of writing a certain type of while loop. Syntax: CS12300-002 Java Programming Week 7 10/09/2016 for(initialize; condition; update) { statements; } Ex: for(int x = 0; x < 10; x++) { System.out.println(x); } This loop is equivalent to int x = 0; while(x < 10) { System.out.println(x); x++; } Parts: for - declaring the loop block initialize - initialize or assign the variable controlling the loop condition - run the loop if this is true update - run this part after the statements are executed. Best used to increment (++) the variable in the initialize part statements - what the loop runs if the condition is true There must be semicolons between the three parts inside the parentheses. Multiple statements inside any part is accomplished with commas, but writing like that is uncommon and best avoided. CS12300-002 Java Programming Week 7 10/09/2016 For loops are always the go-to way and faster to write when the number of iterations (times the loop runs) is known. Otherwise while loops will be used. For loops can be stacked, where loops are placed inside of loops, just like while loops. This allows easy iteration of a task, such as if you need to change 1000 variables for 1000 different classes. Make sure the variables used to control each for loop have a different name. Ex: for(int a = 0; a < 1000; a++) { for(int b = 0; b < 1000; b++) { System.out.println(a + “ “ + b); } } If a variable is intialized in a for loop, it will only exist in that for loop (its scope). You cannot access that variable outside of that loop. If you want to avoid this, define the variable outside of the loop like you would for a while loop, and just assign it (rather than initialize) it in the loop. Error Checking: For loops are just like while loops, and thus share the same errors that humans are prone to make. Make sure you always check your code for errors while writing. Use System.out.println() to help print debug CS12300-002 Java Programming Week 7 10/09/2016 messages so you know where the code is at in execution and what is happening. Common errors: Off-By-One - When a loop does not execute the last step. To avoid this, follow one of two methods. 1. initialize at 0, condition uses < or > for the # of steps 2. initialize at 1, condition uses <= or >= for the # of steps Method #2 is easier to read and understand. for(int a = 1; a <= 1234; a++) will execute exactly 1234 times. Logical Errors - When the code does not do what you want because you wrote it wrong. Obviously fixed by never writing mistakes, but if you do (we are all human), this is solved by debugging (checking for mistakes). Litter your code with System.out.println() checks to figure out where the code is at in execution and print out variable values. This will help you find out where the logic goes wrong, and then you can fix that part of the code. Infinite Loops - Harder to write in a proper for loop than a while loop. Look at the code and verify that the variable will eventually increment past the condition. Make sure you write the right sign in the condition. Miscellaneous: CS12300-002 Java Programming Week 7 10/09/2016  You can initialize at any value, but 0 or 1 will suffice mostly everything.  Conditions can of course use ==. Don’t use == for floating point variables, instead check with absolute value subtraction.  The update step can use -- instead of ++. It can also do other operations or have multiple statements, but this is uncommon.  You can update the main variable in the statements section, but there less point in writing a for loop that way rather than while. Classes Up to this point, the only classes written have been the main class for the code to execute in. Java can handle more than 1 class in total. Classes are just big (or small) structures that hold variables and methods. We’ve seen this clearly with System.out.println(). Class.method(). Objects are instances of a class, created during when the code is running (runtime). Objects are referenced to by reference variables, seen before as ex: Scanner refvar = new Scanner( These variables refer to where the object is stored in the memory of the computer. That’s all for this week’s notes. More will be expanded on the details of classes and objects next week.


Buy Material

Are you sure you want to buy this material for

0 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

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

Anthony Lee UC Santa Barbara

"I bought an awesome study guide, which helped me get an A in my Math 34B class this quarter!"

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.