Save
Busy. Please wait.
Log in with Clever
or

show password
Forgot Password?

Don't have an account?  Sign up 
Sign up using Clever
or

Username is available taken
show password


Make sure to remember your password. If you forget it there is no way for StudyStack to send you a reset link. You would need to create a new account.
Your email address is only used to allow you to reset your password. See our Privacy Policy and Terms of Service.


Already a StudyStack user? Log In

Reset Password
Enter the associated with your account, and we'll email you a link to reset your password.
focusNode
Didn't know it?
click below
 
Knew it?
click below
Don't Know
Remaining cards (0)
Know
0:00
Embed Code - If you would like this activity on your web page, copy the script below and paste it into your web page.

  Normal Size     Small Size show me how

Java Exam 1

QuestionAnswer
Elements of Java Program: keywords These are words that have a special meaning in the programming language (reserved words)
Elements of Java Program: operators Symbols or words that preform operation on one or more operands (data)
Elements of Java Program: Punctuation characters serve specific purpose such as marking beginning or ending of a statement
Elements of Java Program: programmer defined names words or names that are defined by the programmer used to identify storage locations in memory and parts of the program that are created by the programmer (identifiers)
Elements of Java Program: Syntax rules that must be followed when writing a program
Program Line a single line as it appears in the body of a program
Program Statement a complete instruction that causes the computer to perform some action (System.out.println("Your gross pay is $" = grossPay); Can be a combination of keywords, operators and programmer defined names.
Variables a named storage location in the computer's memory. Data stored in a variable may change while program is running. Symbolic names made up by the programmer that represent locations in the computer's random-access memory (RAM)
Source code programming statements written by programmer (source file = .java)
Compiler program that translates source code into an executable form
Executable files translated source code into files that contain machine language
Java Virtual Machine reads Java byte code instructions and executes them as they are read ( interpreter )
Portability program may be written on one type of computer and then run on a wide variety of computers with little or no modification necessary.
Programming Process 1 1. Clearly define what the program is to do. Purpose: to calculate the user's gross pay Input:number hours worked, hourly pay rate Process: multiply number of hours worked by hourly rate Output: display a message indicating the user's gross pay
Programming Process 2 2. Visualize the program running on the computer.
Programming Process 3 3. Use design tools to create a model of the program. PSEUDOCODE
Programming Process 4 4. Check the model for logical errors.
Programming Process 5 5. Enter the code and compile it.
Programming Process 6 6. Correct any errors found during compilation (Repeat 5-6 as many times as necessary)
Programming Process 7 7. Run the program with text data for input
Programming Process 8 8. Correct any runtime errors while running the program RUNTIME ERROR: occurs while the program is running (usually logical errors such as mathematical mistakes.
Programming Process 9 9. Validate the results of the program
Object Oriented Programming a method of software development that has its own practices, concepts and vocabulary. Focused on creating objects (software entity that contains data AND procedures)
Procedural program was made of one or more procedures (a set of programming statements that perform a specific task. (Earliest languages)Procedures typically operate on data items that are separate from the procedures. Data are passed from one procedure to another
Attributes OOP, data contained in an object
Methods OOP, procedures, behaviors that an object performs
Object OOP, a self contained unit consisting of data and procedures
Encapsulation Combining of data and code into a single object
Dada Hiding object's ability to hid its data from code that is outside the object, Protected from accidental corruption.
Class Headers public class Simple (marks the beginning of a class definition. Serve as a container for an application.
public Java keyword; lowercase letters; access specifier; controls where the class my be accessed from; unrestricted
class lowercase; Java keyword; indicates the beginning of a class definition
Simple class name; name made up by the programmer; programmer defined names may be written in lowercase, uppercase, mixture
{} associated with the beginnin of the lass definition. Everythin between the two braces is the body of the class
Method Header public static vid main(String[] args); beginning of a method, group of one or more programming statements that collectively has a name
// marks the beginning of a comment
() used in a method header
{} encloses a group of statements such as the contents of a class or a method
"" Encloses a string of characters, such as a message that is to be printed on the screen
; Marks the end of a complete programming statement
print and println methods used to display text output
System.out.println("Programming is great fun!"); print a message on the screen. System: class out: object println: method argument: value inside the parentheses
\n Newline - advances the cursor to the next line for subsequent printing
\t Horizontal tab - causes the cursor to skip over to the next tab stop
\b Backspace - causes the cursor to back up, or move left, one position
\r Return - causes the cursor to go to the beginning of the current line, not the next line
\\ Backslash - causes a backslash to be printed
\' Single quote - causes a single quotation mark to be printed
\" Double quote - causes a double quotation mark to be printed
Variable is a named storage location in the computer's memory
Literal value that is written into the code of a program
Variable declaration Tells the compiler the variables name and the type of data it will hold
+ operator used with strings... it is known as the string concatenation operator (appends one string to another.)
Identifier programmer defined name that represents some element of a program (variable names and class names )
Class names capitalize first letter and first letter of each subsequent word
byte Primitive data: Integers in the range of -128 to +127
short Primitive data: Integers in the range of -32,768 to +32,767
int Primitive data: Integers in the range of -2147483648 to +2147483647
long Primitive data: integers in the range of -GIANT NUMBER to +GIANT NUMBER
float Primitive data: floating point numbers in the range of -KIND OF BIG NUMBER to +KIND OF BIG NUMBER
double Primitive data: floating point numbers in the range of -GIANT NUMBER to +GIANT NUMBER
Scientific Notation floating point literals can be represented as such. Move decimal to the left, count number of places
E notation replaces x10
Boolean Data Type allows you to create variables that may hold one of two possible values: true or false
Char Data Type used to store characters. Hold one character at a time. Literals are enclosed in single quotation marks NOT the same as string literals (enclosed in double quotation marks)
Unicode characters are internally represented by numbers. Each char is assigned a unique number.
Variable Assignment value is put into a variable with...
Initialization assign values to variables as part of the declaration statement int month = 2, days = 28;
Unary Operators require only a single operand (-5 or -number)
Binary operators work with two operands +,-,*,/,%
Ternary Operators require three operands (only one in Java)
Modulus operator returns the reminder of a division operation involving two integers
Combined Assignment Operators combine the assignment operator with the arithmetic operators x = x + 1; x+=1; balance= balance + deposit; balance+= deposit; or += -= *= /= %=
Conversion between Primitive Data Types before a value can be stored in a variable, the value's data type must be compatible with the variable's data type. Java performs some conversion between data types automatically, but does not automat perform any conversion tht can result in loss of data
Strongly Typed Language before a value is assigned to a variable, Java checks the data types of the variable and the value to see if they are compatible
Ranks of Primitive Data Types Highest double float long int short byte lowest
Widening conversion automatically converts the lower ranked data to the higher ranked data
Narrowing conversion converting higher ranked data to lower ranked data...could cause loss of data!
Cast Operator allows you to manually convert a value, even if it means narowing conversion unary operators that appear as a data type name enclosed in a set of parenthese x=(int)number;
Mixed Integer Operations the result of an arithmetic operation using only a mixture of byte , short or int values will always be an int
Other Mixed Math mathematical expression has one or more values of the double, float or long data types, Java tries to convert all of the operands in the expression to the same data type
Constants the final key word can be used in a variable a named constant. They are initialized with a value, and that value cannot change during the execution of the program final double INTEREST_RATE = 0.069;
String Class allows you to create objects for holding strings. It also has various methods that allow you to work with strings
Creating a String Object String greeting = "Good morning, ";
stringSize = name.length; stores the length of its string in the variable stringSize
String upper = message.toUpperCase(); capitalizes the string message
String lower = message.toLowerCase(); lower cases the string message
char letter = message.charAt(2); displays the second character in the string message
int stringSize = message.length(); displays length of string message
Scope the part of the program where the variable may be accessed by its name. A variable is visible only to statements inside the variable's scope.
Local Variables variables that re declared inside a method. variable must be declared before it is used, cannot have two local variables with the same name
Comments notes of explanation that document lines or sections of a program. Compiler ignores them.
// single line comments
/* */ multi line comments
Documentation Comments can be read and processed by a program named javadoc, create attractively formatted HTML files that document the source code /** */
Scanner class used to read input from the keyboard. Designed to read input from a source (such as System.in), and it provides methods that ou can use to retrieve the input formatted as primitive values or strings
Scanner keyboard = new Scanner(System.in); Declares variable named keyboard, then creates a Scanner object in memory The object will read input from System.in
int number; Scanner keyboard = new Scanner(System.in); System.out.print("enter an integer value: "); number = keyboard.nextInt(); calls the Scanner class's nextInt method. The nexInt method formats an input value as an int, and then returns that value. Therefore, this statement formats the input that was entered at the keyboard as an int, and then returns it. value asigned to # var
import java.util.Scanner; tells the Java compiler where in the Java library to find the Scanner class, and makes it available to your program
Reading a character String input; //to hold a line of input char answer; // to hold a single char Scanner keyboard = new Scanner(system.in); System.out.print("Are you fun?"); input = keyboard.nextLine(); answer = input.charAt(0);
Keyboard Buffer clear the keyboard buffer when mixing nextLine with calls to other Scanner methods
JOptionPane class that allows you to quickly display a dialog box, which is a small graphical window displaying a message or requesting input
import javax.swint.JOptionPane; the import statement used to call the JOptionPane class
JOptionPane.showMessageDialog(null, "Hello World"); used to display a message dialog
Displaying input dialogs showInputDialog method to display an input dialog
String name; name = JOptionPaneshowInputDialog("Enter your name."); displaying input dialog
Converting strings to numbers Double num num= Double.parseDouble(str); int num; num = Integer.parsInt(str);
The if Statement used to create a decision structure which allows a program to have more than one path of execution; causes one or more statements to execute only when a boolean expression is true
Relational Operators >,<,>=,<=,==,!=
Flags a boolean variable that signals when some condition exists in the program Set to false? indicates condition doesn't yet exist Set to true? the condition does exist
The if-else Statement execute on group of statements if its boolean expression is true, or another group if the boolean is false
Nested if Statements to test more than one condition, and if statement can be nested to include another if statement
The If-else-if Statement tests a series of conditions, Often simpler to test a series of conditions with the if-else-if statement than with a set of nested if-else statements if () else if() else()
Logical Operators connect two or more relational expressions into one or reverse the logic of an expression
&& AND - connects two boolean expressions into one. Both expressions must be true for the overall expression to be true
|| OR - connects two boolean expressions into one, One or both expressions must be true for the overall expression to be true. It is only necessary for one to be true, and it does not matter which one.
! NOT - reverses the truth of a boolean expression, If it is applied to an expression that is true, the operator returns false. If it is applied to an expression that is false, the operator returns true.
The Precedence of Logical Operators ! && ||
Precedence of All Operators 1. -(unary negation) ! 2. */% 3. +- 4. <><=>= 5. == != 6. && 7. || 8. = += -= *= /= %=
Comparing String Opjects you cannot use relational operators to compare String objects. Instead you must use a String method StringReference1.equals(StringReference2) if (name1.equals(name2))
StringReference.compareTo(OtherString) string reference is a variable that references a String object, and OtherString is either another variable that references a string object or a string literals. The method returns an integer value that can be used
Scope the scope of a variable is limited to the block in which it is declared
Conditional Operator used to create short expressions that work like if-else statements.
BooleanExpression ? Value1: Value2; booleanexpression - boolean expression in the parentheses of an if statement true? then the value of the conditional expression is Value1. Otherwise the value is Value2.
System.out.println("Your grade is: " + (score < 60 ? "Fail." : "Pass.")); conditional operator
switch statement lest the value of a variable or expression determine where the program will branch to. multiple alternative decision structure - allows you to test the value of a variable or an expression and then use that value to determine which statemet(s) to execute
switch (month) { case 1: System.out.println("January"); break; case 2: System.out.println("Feb"); break; default: System.out.println("Error: Invalid month"); break; } Example of Switch statement
System.out.printf Method allows you to format output in a variety of ways
System.out.printf
DecimalFormat class used to format the appearance of floating point numbers rounded to a specified number of decimal places
import java.text.DecimalFormat; Decimal Format formatter = new DecimalFormat("#0.00"); example of decimalformat class
A computing task consists of 3 actions: Input: entering raw data using the keyboard or mouse Processing: turning the raw data into useful information Output: display the useful information
CPU Brain of the computer It executes all instructions in the programs you write
RAM The main (primary) memory of the computer. All programs and data being executed must be stored here – it is volatile (if the power goes off, RAM is erased)
ROM Permanent instructions to boot up the computer (load the OS) is stored here
USB / CD / DVD / Fixed Disk Secondary (permanent) storage of programs and data
ASCII a specific set of codes represented by 0s and 1s that indicate each instruction or character or digit that can be stored by the computer
Assembly Language three letter nmemonics were created to code for each instruction
Procedural Language / High Level Language Instructions are like algebra and english
Object Oriented Languages a library (folder) that contains classes to perform common activities is provided will look like microsoft wrote it
Application Class think of this as the means by which the flow of the application is controlled
Classes that Represent Objects think of this as a blueprint of a type of object or "thing" that is represented in our application
Java Application a body of java code that can be executed. it must contain a main method, it may contain other java classes
Java Classes body of java code that has: a data section, a method section, does not execute on its own, it provides all the code to create objects with similar characteristics (attributes) and similar behaviors
All java programs are composed from one or more java classes
public class classname always start the application class source. Public: whatever you are making is available to other classes
Main method public static void main(String[] args)
Class.aattribute.method System.out.print()
Literal any string, number or character that can be written into a program, and that we want to program use to generate the intended result
variables a bucket that holds data until you are ready to use it
Variable declaration give the bucket a name and tell the compiler what kind of data the bucket can hold
whole numbers? use int
decimal numbers? use double
boolean true/valse
char single character
Initialiing the variable double gpa = 3.25; instead of double gpa; gpa = 3.25
Arithmetic Operation Rules If either operand is a double, the result is double, else If either operand is a float, the result is float, else If either operand is a long, the result is long, else the result is integer
Integer Expression only integers (4 + 6)
Real Expression only decimals (12.8 - 6.2)
Mixed-mode expression both integer and non integer 16.4 + 2
Division of integers produces the quotient only when two int values are divided
Modulous operator produces the remainder only when two int values are divided
java.lang math class
Constants buckets that we set asid for times when the data in the bucket will never change final double MINI_BLIZZARD 2.70
Class like a blueprint of some "thing" that is represented in our program
Each class has a... name, attributes called instance variables and methods
Each class gets instantiated into an object before it is uses
Reference data type classes are used within methods of other classes and are considered...
String Class java.lang
To create a string object String fName= "Ken"; that statement creates a String object in memory and stores Ken in it. It then assigns the memory address of that String object to the variable fName
length provides the length of a string object
java.lang package do not have to do anything special to use classes from this package
to use other API classes requires a special statement at the top of your class source code IMPORT STATEMENT
Import Statement tells the compiler that we want to use a certain package and class from the Java API
import java.util.Scanner says i will be using the scanner class from the java.util package
Scanner class used to get data into the program
Scanner keyInput = new Scanner(System.in); this says we want to create a variable called keyInput that references an object of the class Scanner.
String name; Scanner keyInput = new Scanner(System.in); System.out.print("What is your name?"); name = keyInput.nextLine(); ???? that statement says store in the String variable name a string of text that the user enters in and is referenced by the variable keyInput. nextLine() is one of the methods of the scanner class.
If you accept a number value from the keyboard right before you accept a string value, you are going to run into issues Solution 1: Try to accept string data first Solution 2: run an extra nextLine() method between accepting the number and string
import javaz.swing.JOptionPane; says i will be using the JOptionPane class from the javax.swing package
JoptionPane.showMessageDialog(null,"Java is fun"); displaying a message on a dialog box
JOptionPane.showInputDialog("What is your pets name?"); input dialog box, gives a way for users to enter data
Byte.parseByte(string variable) String ==> Byte
Double.parseDouble(string variable) String --> Double
Float.parseFloat(string variable) String --> Float
Integer.parseInt(string variable) String ==> Int
DecimalFormat Class is from what package? java.text package
ClassName variableName = new ClassName( args if needed); DecimalFormat class ClassName - class that you want to create the object from variableName - is the name of the variable that will reference the object new - says to the compiler "create a new object of this type and store a ref to the obj in the var
double price = 1.25; int quantity = 21; double salePrice = price * quatity; DecimalFormat dollarFormat = new DecimalFormat(#0.00); System.out.println(dollarFormat.format(salePrice)); Decimal format
Printf belongs to the System class of the java.lang package System.out.printf("FormatString", Arguments)
Print F - Format strings lays out the string the way you want it to print
Print F - arguments fill in the blanks
double price = 1.25; int quantity = 21; double salePrice = price*quantity; System.out.printf("The sale price is $%.2f\n", salePrice); .2f says "there is an argument on the right side of the comma. Print it here and give it two decimal places"
One Way Decisions no alternative choices
Two way decisions alternative choices allowed
Two ways to make decisions in Java code: if construct - one or two way switch construct - multiple selections as from a menu
Switch construct can be used when the variable being tested is an int or char data type
Variable scope variable or constant must be declared befor eyou can use it; local variables
I would find the decimalformat class in the.....package java.text
I would find the scanner class in the ....package java.Util
I would find the messageDialog method in the....class of the ....package JOption.pane class of the javax.swing
what is the first thing I have to do in my code before i can use either of the classes from eithe rof the packages above? IMPORT STATEMENT
what is the statement found right above the class header? IMPORT STATEMENt
I IMPORTED THE SCANNER CLASS AND NOW WANT TO ACCEPT INPUT USING IT. what do i do first? Import Java.Util.Scanner Public class reviewclass { public static void main { int Somenumber; Scanner Keyinput = new scanner(system.in);
What is the scanner method to retrieve an integer that was entered at the keyboard using an object of type Scanner? System.out.Print("Provide a number"); Somenumber = keyinput.nextInt();
What do i need to remember to do if i retrieve an numeric value before a string? Clear the buffer! kEYINPUT.NEXTLINE();
The showMessage Dialog method accepts two arguments..what are the? posistion, string that displays message
I've just used the showInputDialog to retrieve the value 2.25. The method returns that number as a: string!
Correct syntax to instantiate an object is: Classname variable = new classname(params);
PrintF Statement: Integers with a minimum width
PrintF Statement: Floats with a minimum width:
PrintF Statement: Left justified integers with a minimum width:
PrintF statement: Left Justified floats with a minimum width:
Printf statement: string
PrintF statement: string left justified with a minimum length
Created by: Kmrosewa
Popular Computers sets

 

 



Voices

Use these flashcards to help memorize information. Look at the large card and try to recall what is on the other side. Then click the card to flip it. If you knew the answer, click the green Know box. Otherwise, click the red Don't know box.

When you've placed seven or more cards in the Don't know box, click "retry" to try those cards again.

If you've accidentally put the card in the wrong box, just click on the card to take it out of the box.

You can also use your keyboard to move the cards as follows:

If you are logged in to your account, this website will remember which cards you know and don't know so that they are in the same box the next time you log in.

When you need a break, try one of the other activities listed below the flashcards like Matching, Snowman, or Hungry Bug. Although it may feel like you're playing a game, your brain is still making more connections with the information to help you out.

To see how well you know the information, try the Quiz or Test activity.

Pass complete!
"Know" box contains:
Time elapsed:
Retries:
restart all cards