CSE Reading Notes

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

Int x = 5000000; Int y = 1000; Int z = x * y; Result should give us 5 billion....but....

There are rules Java follows when evaluating code • 1. A literal numeric value that doesn't contain a decimal point is always treated as an int • 2. An int times an int always gives an int result • 3. An int has a size limit of approximately +- 2.15 B • 4. The assignment operator is always executed last after everything to the right of it has completely resolved to a single value oBecause of these rules, the literal value 5000000 times the literal value 1000 are treated as int times an int = int -Int cant contain the number 5 billion because it doesn't fit so the program result will be inaccurate -This will not cause a compile error nor will it display an error at runtime. It will just stuff an incorrect value in the variable z

increment a by 1 then use the new value of a in the expression in which a resides

++a PREFIX increment

to left justify the output put a ----- sign in front of the width specifier

- minus sign

A multi-line comment block can be created by surrounding the text with -----

/* and */ /**/

Put the operations in order of evaluation

1. Multiplication, Division, Remainder 2. Addition/Subtraction 3. Assignment

what are the basic steps to compile and execute a program

1. open a terminal window 2. navigate to the folder where your program is located 3. compile the source code 4. run the JVM and pass it the name of your class file

why does give the wrong result long z = 500 * 100

500 * 100 is int * int meaning it will evaluate to an int before assigned to long variable (assignment happens after the right side is down to a single value or all math on the right is complete)

java includes --- -primitive types that can be used to declare variables

8

We didn't include ---- in our class or method blocks, because they aren't Java statements

;s

A ---- test is an expression that evaluates to true or false

Boolean

When the exit option is selected you may want to bypass all remaining logic and exit out of the loop right away. --- statement can help to accomplish this

Break

how can we bypass short circuiting?

If we desire the second expression to be evaluated anyway, we should use the single & operator which bypasses short circuiting and evaluates the entire expression -Might be necessary if using incrementers/decrementers with variables in the second expression that we want to execute

ExampleProgram.java file was compiled to create an ExampleProgram.class file That file was opened and managed by ---- which.... Operating system transforms requests from the JVM into machine language which is down to a language that...

JVM translated it for the host operating system our CPU and the rest of our computer hardware can understand

&& and || are examples of additional --- operators that can be used to construct complex Boolean expressions

Logical

--- ----are used to combine 2 boolean expressions and resolve them down to a single true or false

Logical operators

Variable must be declared with what 2 things before it can be used

Name and Type -A variable's name enables the program to access the value of the variable in memory -The name can be any valid identifier -A variable's type specifies what kind of information is store at the location in memory

When do variables no longer exist?

Once declared in a block, variables are available for use in other statements within the same block

--- writes out the steps of the solution in plain narrative form

Psuedocode

----- used to repeat a line or block of code. Loops will continue to repeat execution as long as some Boolean expression continues to evaluate to true. It exits when the condition becomes false. Repetition statements are implemented using while, do..while, or for statements

Repetition statements

Java statement: ? Description: Sets the value of a variable to a literal string

String s = SMU;

---- represents the standard Java output destination which by default is the terminal or cmd window

System.out

Java statement: ? Description: prints a literal String to the console without a carriage return / line feed

System.out.print

Prints Java Programming! starting where the cursor was positioned previously, then outputs a newline character

System.out.println("Java Programmming!");

What does the output look like? System.out.println("Welcome\nto\nJava\nProgramming");

Welcome to Java Programming! cursor left on a new line \n allows for new line to be entered anywhere in the string

what is the symbol to enter a newline

\n

Class signature must always be followed by...

a set of curly braces

use the current value of a in the expression in which a resides, then increment a by 1

a++ POSTFIX increment

Scanner import statement is placed...

above the class signature

the += operator...

adds the value of the expression on its right to the value of the variable on its left and stores the result in the variable on the left of the operator

A set of instructions to solve the same type of problem with different sets of data is called an---

algorithm

What is the one word term that describes the contents of a set of curly brace characters { and } in a class, method, or elsewhere in Java?

block

When a --- statement is encountered, flow control moves automatically to the closing curly brace of the while or for block

break

When using either counter controlled or sentinel controlled repetition, its possible to interrupt the normal looping logic using....

break or continue

Useful if you build a menu of choices that continues to display until the user chooses the exit option

break statement

In an expression containing values of the type int and double, the int values are promoted to double values for use in the expression

casting

what is the the bare minimum code required to successfully compile a Java program is:

class ClassName -but doesnt contain any logic

a variable called a --- or control variable controsl the nubmer of times a set of statements will execute

counter

the body of a method is contained within its ---

curly braces {}

int number1; int number2; int number 3; variables that are --- but not ---

declared; initialized

declares a variable and sets its value to a floating point number

double d = 21.5;

what will be the output of the following: int d, e; double f; d = 9; e = 6; f = d/e;

double f = 1.0 dividing 2 ints results in int AFTER THE RESULT IS CALCULATED because f is a double the int result is converted to double (but answer should be 1.5 but when it was made into an int it truncated the .5)

Any text that begins with a ----- is considered a comment, and will be ignored by the compiler

double slash //

there are implicit math operations in java. T/F

false -xy wouldnt be evaluated as x*y need operator always

most commonly used Java statement for managing loops

for statement

Combining the CPU, primary memory and secondary memory, along with input and output devices, computers are equipped to ....

host and run software

The --- statement requires a single parameter which is a Boolean expression that evaluates to the value true or false

if If the result is true the statement following the if will execute otherwise it will be skipped

simple if statement if (---- ---- goes here) --- ---- goes here;

if (boolean expression) java statement;

For OR how can you bypass short circuiting

if you want both expressions to be evaluated everytime you could use single operator |

%20s

inset right justified String at this point -will fill with spaces if necessary to occupy 20 character spaces

Java statement: ? Description: declare an integer variable x without initializing it

int x;

50000 (is treated as --) 50000L (is treated as --)

int, long

What is the line that compiles the program? What is the line that runs the program?

javac ExampleProgram.java java ExampleProgram

math operators work with...

literal numerical values or variables that have been declared as one of the 5 number primitive types

a non floating point number can be treated as a long instead of --- by putting the suffix L at the tail end of the number

long x = 5000000L; int y = 1000; long z = x*y;

--- --- begins execution of Java application

main method

a system can have one or more classes and each of those classes may contain one or more methods but one of these class must have a method named ____. Why?

main; because that is always the starting point for every system

java statements that manage the flow and execute logic must exist within a ---, and each --- must be contained within a ---

method, class

All program logic must be contained inside what's referred to as a ----- and each method must be contained inside the block of a ----

method; each method must be contained inside the block of a class

does short circuiting happen with the ^ operator?

no because both sides must always be evaluated to determine the result of the compound expression

in a method, parentheses contain ....

parameters which give a variable name to data passed in from elsewhere

a program with a class but no methods is...

possible to compile but doesnt actually do anyhting

The substitution symbols are placed within the String and the values to be substituted are contained within the --- parentheses following the String

printf's

if(x > 5) System.out.println("Greater"); description?

prints text to the console when the boolean expression is true

Conventional to declare most classes as -------- (another keyword) so that the class can be used by other classes

public

a --- method can be invoked by other classes

public where invoked means cause (a procedure) to be carried out

what is the class signature

public class ExampleProgram {}

which control structure? statements repeat as long as a specified condition is true and cease execution when that condition becomes false

repetition 3 types: while, for, do...while

placing a ! in front of any boolean expression automatically...

reverses the value, i.e. true becomes false and vice versa

When the --- ---- exceeds the size of the String integer or floating point number the displayed output will be...

right justified and stuffed with blank spaces on the left

which control structure? statements execute only if a specified condition is true

selection 3 types: if, if...else, switch

used to execute specified java statements if a certain condition is true or false. These are implemented using if, if...else, or switch statements

selection statements

o Often known as indefinite repetition because the number of repetitions is not known before the loop begins executing

sentinel conrolled repetition unlike counter controlled which is definite repetition

used when we want to loop a block of code continuously until a user chooses to exit the loop

sentinel controlled repetition

which control structure? statements in a program execute after the other in the order in which they are written

sequential

By default, printf will automatically limit and force the display of a floating point number to have ---- digits to the right of a decimal point

six

the main method is a ---- method which means that it is invoked directly on the class itself

static, means when you run a program by passing a compiled class to java it invokes the following: YourClassName.main();

System.out.printf("x=%d",5); description?

substitutes an integer value within the String when the program runs

/* notes */

syntax for a mult-line comment

//note

syntax for a single line comment

For each substitution symbol inside the String, there must be a corresponding parameter with a value of ----

that type following the string

Temporarily changes the int to a double for the calculation, but does not permanently change the value or type of variable j

the cast

in division if either the num or denom is a double, then...

the other is treated as a double too

when using a numeric variable in a math expression......

the variable must be declared AND must contain a value

note that --- and --- are java keywords that are used to represent these two boolean values. these words can be included as literal values within a java statement

true, false

when stuffing a floating point number into an int, java will

truncate everything to the right of the decimal place and WILL NOT ROUND

A location in the computer's memory where a value can be stored for use later in a program

variable

Programs remember numbers and other data in the computer's memory and access that data through program elements called ---

variables

all the ---- that were declared as parameters inside the method body will no longer exist when the method reaches the closing curly brace

variables -if the calling method needs data from this method you must use a return statement

a java keyword that indicates that the method returns nothing. This will be replaced by a type indicator for methods that have a return statement

void

What does a variable type specify

what kind of information is stored at that location in memory

what is a sentinel value

when the user enters a predetermined exit value, which is referred to as a sentinel value

Java compiler ignores extra --- --- , so feel free to organize code in whatever format

white space

You can override the default by inserting a -- specifier and a -- specifier between the % and the f

width; precision

x=x%5;

x = x%5

x*=5; what is the full statement

x = x*5

x+=5; what is the full statement

x = x+5

x-=5; what is the full statement

x = x-5

x/=5; what is the full statement

x = x/5

Checks to see if either of the Boolean expressions are true

||

What are the 4 basic capabilities of computer software?

• 4 basic capabilities at its core: o 1. Accept input of information/data This could include a human entering data on a keyboard, touch scree, or some other type of device with buttons/keys/dials/etc. This data could be retained temporarily for a single purpose, or it could be retained longer-term for later retrieval and use o 2. Send information/data Information may be sent to a device such as a monitor, TV, projector or printer. It could also be sent to another computer program on the same computer or on a different computer o 3. Manipulate data Computer software is great for performing simple to highly complex math functions. It can also transform non-numeric data such as alphabetizing lists, adding prefixes or suffixes, deleting letters or words, etc. o 4. Manage flow control Computer software can be set up to repeatedly do multiple steps in a predetermined order. Additionally certain steps may repeat while others only happen in certain conditions o Not all software does all 4 things but all software does at least one of them


संबंधित स्टडी सेट्स

AP BIo Unit 6 Topic 2: Replication

View Set

HS&F: Chapter 5 - Integumentary System

View Set

Endocrine NCLEX practice questions

View Set

NUR 221 PrepU Ch 7 Legal Dimensions of Nursing Practice

View Set