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

COP 2510 Midterm Study Guide

by: Tara Copas

COP 2510 Midterm Study Guide COP 2510

Tara Copas

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

Escape Sequences Assignment Primitive Data Types Integer Divisions Increment/Decrement String, Random, Math, NumberFormat/DecimalFormat, Classes Logical Operators If Statements If-Else Stat...
Programming Concepts
Yan Albright and Dr. Schinnel Small
Study Guide
Java basics
50 ?




Popular in Programming Concepts

Popular in Computer Programming

This 10 page Study Guide was uploaded by Tara Copas on Monday October 10, 2016. The Study Guide belongs to COP 2510 at University of South Florida taught by Yan Albright and Dr. Schinnel Small in Fall 2016. Since its upload, it has received 3 views. For similar materials see Programming Concepts in Computer Programming at University of South Florida.


Reviews for COP 2510 Midterm Study Guide


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/10/16
COP 2510 Midterm Study Guide print method: System.out.print(“hi”); = hi there  System.out.print(“there); println method: System.out.println(“hi”); = hi there     System.out.println(“there”);  String concatenation: Used to attach some info to user input, the operator is “+”. It can also be  used to append a number to a string, + is also used for arithmetic addition.  If both operands are strings, or if one is a string and one is a number, it performs string  concatenation  If both operands are numeric, it adds them System.out.println(“24 and 45 concatenated: “ + 24 + 45); =24 and 25 concatenated : 2445 System.out.println(“24 and 45 added: “ + (24 + 45)); =24 and 45 added: 69 Java Program Structure:   A program is made up of one or more classes  A class contains one or more methods  A method contains program statements o Each statement is followed by a semicolon Key Concepts:  A Java application always contains a method called main  o Where to start an application  The name of the file always matches the name of the class Identifiers:  The words a programmer uses in a program: identifiers  An identifier can be made up of letters, digits, the underscore character (_), and the dollar sign  Identifiers CANNOT begin with a digit  Java is CASE SENSITIVE­ Total, total, TOTAL, are all different identifiers Use different case styles for different types of identifiers, such as   Class names – uppercase FIRST letter  Constants – uppercase ALL letters  Variables – camelCase o First word of abbreviation begins with a lowercase letter, any words or  abbreviations after it begin with a capital letter  Omits hyphens  ex. maxNum or minNum Identifiers reserved by Java   exists identifiers that are reserved by java have predetermined meanings in the language o public class  cannot be used in any other way Most Common Keywords  class  int  public  static  void  double, etc Escape Sequences: \b backspace \t tab \n newline \r carriage return \” double quote \’ single quote \\ backslash Variables:  A name for a location in memory used to hold a data value  Initialize variables before you use them o int, double, final int, char, etc Assignment Statement:  Assigns a value to a variable  Constants:  Constants are identifiers and are similar to variables except that they hold a particular  value for the duration of their existence, the value does not change Primitive Data Types: There are EIGHT primitive data types ­Four subsets of integers ­Two subsets of floating point numbers ­Character data type ­Boolean data type *Everything else is represented using objects*   Integers and Floating Points o Integers have no fractional part o Floating Points do  Four integer data types  int  byte  short  long  Two floating point data types  float  double  Characters o Individual characters can be treated as separate data items and can also be  combined to form character strings o A character literal is expressed in a Java program with single quotes  Booleans o A Boolean value has only two valid values, true and false o true and false are reserved as Boolean literals and cannot be used outside of this context Expressions A combination of one or more operators and operands that usually perform a calculation (doesn’t have to be a number!)  Arithmetic Operators o Defined for both integer and floating point  addition (+), subtraction (­), multiplication (*), and division (/) o The Remainder Operator (%)  Returns the remainder after dividing the second operand into the first  a.k.a. the modulus operator o Integer Division  If both operands are integers, the / operator performs integer division,  meaning that any fractional part of the result is discarded o Floating Point Division  When one or the other or both operands are floating point values, the  fractional part of the result is kept Operator Precedence: All expressions are evaluated according to an operator precedence hierarchy   Multiplication, division, and the remainder operator all have equal precedence and are  performed before addition and subtraction  Addition and subtraction have equal precedence  Any arithmetic operators at the same level of precedence are performed L to R  Any expression in parentheses is evaluated first Substring Method: String exampleStr = “I am learning Java”  In this statement there are 16 characters, starting at 0=I  String substring (int beginIndex, int endIndex) o THIS DOES NOT INCLUDE INT ENDiNDEX o Ex. String sub = exampleStr.substring(5,7);         “le” o Ex. String sub = exampleStr.substring(5);            “learning Java” Math Class The Math class is a part of the java.lang package The methods of the Math class are static methods (a.k.a. class methods) Static methods can be invoked through the class name – no object of the Math class is needed Methods of the Math Class  static int abs (int num) o returns the absolute value of num  static double sin (double angle) o returns the sine of angle measured in radians  static double ceil (double num) o returns the ceiling of num, which is the smallest whole number greater than or  equal to the num  static double pow (double num, double power) o returns the value raised to the specified power  Math.pow(3, 2);         =9  static double sqrt (double num) o returns the square root of num, which must be positive  Math.sqrt(4);              =2 Formatting Output NumberFormat Class  Provides generic formatting capabilities for numbers  Import with java.text.NumberFormat;  String format(double number) o Returns a string containing the specified number formatted according to this  object’s pattern  static NumberFormat getCurrencyInstance() o returns a NumberFormat object that represents a currency format for the current  locale  static NumberFormat getPercentInstance() o returns a NumberFormat object that represents a percentage format fir the current  locale DecimalFormat Class  Its constructor takes a string that represents the pattern that will guide the formatting  process  Import with java.text.DecimalFormat;  DecimalFormat(String pattern) o Constructor: creates a new DecimalFormat object with the specified pattern  void applyPattern(String pattern) o Applies the specified pattern to this DecimalFormat object  String format(double number) o Returns a string containing the specified number formatting according to the  current pattern Random Class  A pseudorandom number generator  Import with java.util.Random;  Random() o Constructor: creates a new pseudorandom number generator  float nextFloat() o returns a random number between 0.0 (inclusive) and 1.0 (exclusive)  int nextInt() o returns a random number that ranges over all possible int values (positive and  negative)  int nextInt(int num) o returns a random number in the range 0 to num­1 Assignment Operators: To simplify the process  num = num + count  += x += y x = x + y  ­= x ­= y x = x – y  *= x *= y x = x * y  /= x /= y x = x / y  %= x %= y x = x % y Increment and Decrement Operators: count++; count = count + 1; ++count; count­­; count = count – 1;  ­­count; Logical Operators: 3 logical operators that produce Boolean results ! Operator is used to perform the logical NOT operation (logical complement) && Operator is used to perform the logical AND operation    Operator is used to perform the logical OR operation OPERATOR     DESCRIPTION EXAMPLE              RESULT         !        logical NOT        ! a        true of a is false, false if a is true       &&                   logical AND    a && b true is both a and b are true, false otherwise                 logical OR     a   b true if a or b or both are true, false otherwise If Statement: Consists of the reserved word “if” followed by a Boolean expression Example: public class Age { public static void main(String[]args) { final int MINOR = 21; Scanner scan = new Scanner(; System.out.println(“Enter you age: “); int age = scan.nextInt(); System.out.println(“You entered: “ + age); If (age < MINOR) System.out.println(“Youth is a wonderful thing. Enjoy.”); System.out.println(“Age is a state of mind.”); } } If­Else Statement: We can add an else clause to an if statement, making it an if­else statement, to handle if we want  to do one thing if a condition is true and another if that condition is false Example: public class CoinFlip { public static void main(String[] args) { Coin myCoin = new Coin (); myCoin.flip(); System.out.println(myCoin); if (myCoin.isHeads()) System.out.println(“You win.”); else System.out.println(“Better luck next time.”); } } While Statement: A loop that evaluates a Boolean condition just as an if statement does and executes a statement if the condition is true Difference between if statement is it evaluates AGAIN and if condition is still true it runs again  until the condition is false Example:  import java.util.Scanner; public class WinPercentage { public static void main(String[]args) { final int NUM_GAMES = 12; int won; double ration; Scanner scan = next Scanner(; System.out.print(“Enter the number of games won (0 to “ + NUM_GAMES + “): “);  won = scan.nextInt(); while (won < 0   won > NUM_GAMES) { System.out.println(“Invalid input. Please reenter: “); won = scan.nextInt(); } ratio = (double)won / NUM_GAMES; System.out.println(“Winning percentage: “); } } Switch Statement: Causes the executing program to follow one of several paths based on a single value Similar logic could be constructed with multiple if statements, but in cases where it is warranted,  a switch statement usually makes the code easier to read Example:  import java.util.Scanner; public class GradeReport { public static void main(String[]args) { int grade, category; Scanner scan = new Scanner(; System.out.print(“Enter a numeric grade (0 to 100): “); grade = scan.nextInt(); category = grade / 10; System.out.print(“That grade is “); switch (category) { case 10: System.out.println(“a perfect score. Well done.”); break; case 9: System.out.println(“well above average. Excellent.”); break; case 8: System.out.println(“above average. Nice job.”); break; case 7: System.out.println(“averge.”); break; case 6: System.out.println(“below average. You should see the ”); System.out.println(“instructor to clarify the material presented in class.”); break; default: System.out.println(“not passing.”); } }


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

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

Janice Dongeun University of Washington

"I used the money I made selling my notes & study guides to pay for spring break in Olympia, Washington...which was Sweet!"

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.