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

Java Programming

by: Agustina Price

Java Programming COP 2250

Agustina Price
GPA 3.6

Erliang Zeng

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

Erliang Zeng
Study Guide
50 ?




Popular in Course

Popular in Computer Programming

This 8 page Study Guide was uploaded by Agustina Price on Monday October 12, 2015. The Study Guide belongs to COP 2250 at Florida International University taught by Erliang Zeng in Fall. Since its upload, it has received 52 views. For similar materials see /class/221726/cop-2250-florida-international-university in Computer Programming at Florida International University.

Popular in Computer Programming


Reviews for Java Programming


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/12/15
Materials for Exam One 1 Identi ers and reserved words An identi er can be made up of letters digits the underscore character 7 and the dollar sign and cannot begin with a digit By convention programmers use different case styles for different types of identi ers such as title case for class names String upper case for constants MAXIMUM Reserved words public class static void return int oat double oat short byte and so on 2 Data conversion In Java data conversions can occur in three ways 7 assignment conversion float f int i 5 fi fis5o 7 promotion float f 20f or 20F since 20 is a double constant float f 20 wrong inti5 f fi the value of i is promoted to float type and then the division between two float type data is performed 7 casting float f 2 int i 5 i intfi since the expression of fiquot will return a float type data which could not be automatically converted to integer and casting is required Casting a pair of parenthesis with casting type enclosed such as int float Widening conversions from small data type to a larger one short gt int gt long oat gt double int gt oat long gt double Of Reverse arrows correspond to narrowing conversions Widening conversions are safe and could be done automatically int i 5 oat f f i int gt oat Narrowing conversions need to be done through casting i f wrong assignment Correct one is i oatf and the value of i is the integer palt of variable 139 Try to understand int tot average average average average casting in al 20 count 7 float average total count 20 floattotal count 2857143 total floatcount 2857143 floattotal count 20 the last statement is redundant since int gtfloat is a widening conversion and could be converted automatically 3 Assignment Operator Operator 00 int i 10 String s s 6 6 value 5 i 5 2 Example Eguivalent T0 Hello 4 Expression Evaluation xy xxy x y xxy 3 3 xy xxy xy XXY value i 1 because i i5 2 HellolZ because 5 s 6 6 int x 4y 523 String s quotHelloquot Systemoutprintlnx Z s x 2 7Hello43 x z s x 2 consists of only operator and expression should be evaluated from left to right Step I X z are both integers and x z is 7 Step II For 7 s s is a String object and the means String concatenation 7 s is 7Hello Step III 7Hello 4 is 7Hello4 because of String concatenation Step IV 7Hello4 3 is 7Hello43 SystemoutprintlnZx X s ZX X 4HelloO4 zx x s zx x consists of and operators and has higher precedence than operator Step I The left zx is evaluated first and is 0 Step II The second zx is evaluated and is 0 Step III will be evaluated from left to right and 0 x should be 4 Step IV 4 s is 4Hello Step V 4Hello 0 is 4HelloO Step VI 4HelloO 4 is 4HelloO4 Systemoutprintlnyx X S X y t X 204He11094 y x x s x y x consists of and operators as well as paired parenthesis Expression enclosed within the parenthesis should be evaluated from innermost to outermost for many layered parenthesis Step I x s gt 4Hello Step II x y gt 5 Step III y x gt 20 Step IV 20 4Hello gt 204Hello Step V 204Hello 9 gt 204HelloQ Step VI 204HelloQ x gt 204Hello94 5 Class Objects and Methods Creating object reference variable A class name can be used as a type to declare an object reference variable String title String is a class name title is declared as String reference variable Creating object Generally we use the new operator to create an object title new String Java Programmingquot String Java Programmingquotis String constructor which is a special method that sets up the object To create a String object there is another way to do it title Java Programmingquot Invoking methods use the dot operator to invoke its methods count titlelength length is method of String object title 6 String Class Two ways to create String object with new String title new String Java Programmingquot 23 without new String title Java Programmingquot String methods The index begins at zero in each string In the string quotHelloquot the character 39H39 is at index 0 and the 39039 is at index 4 length 7 return the length of the string Each escape character corresponds to one character String s new String HellotWorld nquot System out println s length 13 substringsta1t end 7 return substring of the string object Start 7 inclusive end 7 exclusive String s new String HellotWorld nquot System out println s substring 2 5 llo 2 corresponds to first 1 and 5 to t String lt gt int get int from a string String s 375quot int sVal IntegerparseInts get string of characters from a int variable int i 345 String s quot i 7 Random Class Import util class import java util Random 2 use wildcard character import java util it is recommended to avoid using wildcard character Creating Random object Random generator new Random Generate a random number int randomNumber generate a random number of 0 1 2 3 4 5 randomeNumber generatornextInt6 generate a random number of 2 3 4 m 11 randomeNumber generatornextInt10 2 generate a random number of 6 4 2 m 24 randomeNumber 2 generatornextInt16 6 generate a random number of 13 11 9 m 57 randomeNumber 2 generatornextInt36 13 8h4mh ws Invoking methods The methods of the Math class are static methods Static methods can be invoked through the class name 7 no obj ect of the Math class is needed value Mathcos90 Mathsqrtdelta absarg absolute value of arg sqrtarg square root of arg exparg exponential value of arg POWX y x to y power 9 Formatting output NumberFormat import class import javatextNumberFormat create formatter object Currency Formatter object NumberFormat currencyFmt NumberFormatgetCurrencyInstance Percent Formatter object NumberFormat percentFmt NumberFormatgetPercentInstance Each formatter object has a method called format that returns a string with the specified information in the appropriate format double findal TAXRATE 006 Systemoutprintln Tax Rate quot percentFmtformatTAXRATE Tax Rate 6 DecimalFormat import class import javatextDecimalFormat create DecimalFormat object DecimalFormat fmt new DecimalFormat quot0quot 0 Digit Digit zero shows as absent Systemoutprintlnfmtformat38976 3898 Systemoutprintlnfmtformat38 3 8 1 What is the output of the following segment int i 0 int j 12 while i lt j i 1 j 1 Systemoutprint1ni quot quot end While 339 H4 11 10 9 cumgtme 8 7 6 2 Trace the execution of the following code fragments to determine their outputs E double x do 1 Systemoutprintx 10 x x 05 While X lt 10 10 05 00 05 10 for int r 1 r lt 4 r 1 for int c 1 c lt r c Systemoutprint Systemoutprint1n 39k 39k 39k 39k 39k Write a loop of any kind that will generate the following output 10 9876543210 for int k 10 k gt 0 Systemoutprint k k 4 Write ajava code to do the following Write a while loop to input Strings using methods from Scanner class Prompt the user whether to enter another String non stop Accumulate the Strings in a String variable outwith a space between the Strings and print out after the while loop import javautilScanner public class testl public static void mainString args Scanner scan new ScannerSystemin String output quotquot String temp quotyquot while tempequalsIgnoreCasequotyesquot temp equalsIgnoreCase quot yquot yesno quot Systemoutprintlnquot Please enter a string gtquot output scannext SystemoutprintquotDo you want to enter another one temp scannext System out println output 5 Write a loop to input numbers ints using methods from Scanner class until the user enter 1 Sum the numbers in an int variable sum Finally print out the sum value of all numbers except the last number 1 import javautilScanner public class testl public static void mainString args stop gt quot stop gt quot Scanner scan new ScannerSystemin int sum 0 Systemoutprintlnquot Please enter an integer 1 to int input scannextInt while input 1 sum input Systemoutprintlnquot Please enter an integer 1 to input scannextInt SystemoutprintlnquotSum is quot sum


Buy Material

Are you sure you want to buy this material for

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

Kyle Maynard Purdue

"When you're taking detailed notes and trying to help everyone else out in the class, it really helps you learn and understand the I made $280 on my first study guide!"

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

Parker Thompson 500 Startups

"It's a great way for students to improve their educational experience and it seemed like a product that everybody wants, so all the people participating are winning."

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.