Data and Expressions java

Ace your homework & exams now with Quizwiz!

Explain the difference bw Unary operators and binary operators? Unary operators represent has ---- operands while the binary had ----- operands The binary operators accomplish ----- and ---- Urinary operators only work one ----- -- Ex: Count++ or Count--

1 2 positive and negative only one operand

What range of values can be held in int given int takes up four bytes in memory?

1. Realize that 4 bytes ( 4*8 b/c 8 bits in one byte) are 32. In other words. 32 bits of space 2. Think of the possible combinations of 0 and 1 s - use 2^k. k = bits of space 3. 2^32 is 4 billion 4. Realize both negative and positive numbers are stored so 4 billion / 2 2 billion is negative and the other is 2 billion is positive

you can't store a variable higher -------and lower than the -------- number in the int variable.

2 billion and - 2 billion

escape sequence

A sequence of code that represents a special character when used inside a string.

\n Where do I put it ?

ASCII LineFeed (LF) - Goes to the next line -newline escape Put inside the double quotes to show the finishing of the line "

Whitespace

Any character that shows up as a blank space on the screen, such as a space, a tab, or a new line; helps separate different parts of the document to make it easier to read int = 10, 12; 13; int 10 12; 13;

How to indent in java to have a good style ( like the one in pic)

Control A then control I

System.out.println

Displays text for the user: Ex. System.out.println("Hello") Hello

Why is it do important to know which primitive to use when declaring a variable? - what is a trade-off

Do you have to ask how large is my number needs to be? space of data storage is limited - if you don't need high numbers use lower byte primitive to SAVE SPCE

\'"

Double-quote (")

name all primitive values who hold nonwhole values FUC*ING DECIMALS

Float holds ----- 4 bytes double hold -- 8 bytes

Why use constants?

If you refer to one piece of information several times, like interest rate, it's easier to refer to the constant name instead of writing in the calculation or number each time. Also makes that code easier to read. The constant value remains through the program If you want to go back and change it, you only have to change in one place and it will be saved. - compiler gives you an error if you attempt to change a constant

String Concatenation and operation can look to similar: How do you show the difference: Write a program to shows the difference

In case of adding put a Prentiss around you want to add in case of string you want to attach to each other just use + System.out.println(" 10 +10 nated :" + 10 +10 ); // show how concatenated no 10 and 10 System.out.println(" 10 + 10 added :" + (10 +10) ); // shows addition

What is a Literal number? why use L when adding to a really large number when declaring it into a variable what would be the issue you if you forget to put the L for long variables put --------- for floats put -------

In direct number, you put in a variable L is to show the value is too big to be stored in " int" so mark it L for the "long" variable the compiler thinks the " long" variable is " int" and will give you an error l F

Write a program where c-nation occurs despite the operator being there

Just put a string on the left side

permative data types

Look at the pic

what is RAM

Random Access Memory; temporary memory. RAM is expandable, and resides on the motherboard. - bunch of bytes

\'

Single-quote (')

String literals do not span over multiple lines, so use ----- to connect two string literals without writing the object ( system.out twice ) String -------- refers to joining two texts together using what operator --- With------- The goal is to ------

String Concatenation ( +) Concatenation write everything on the same line

Write a string variables that contains string concatenation

String firstName = " Bob" String lastName = " Mick" String fullName = firstName + lastName; // should have no space

epthy string

String s = " "

String variables are primitive or reference variables and why? write a declaring a string variable what does it need? in string variable declaration the first letter is --

String variables reference b/c string is referring to an object String name = " Fred" - this string called fred is an object Capitalized

How to find information about a string object Describe its structure? When calling out out the info what should think about ? write an example

Structure: call out + a varible + a dot(.) + info you need String animal = " mice"; Sytem.out.println( animal.lenth() ) // when calling out how many letters are inside the word mice remember the space inside the double count matters : - string animal = " mice " is different from: string animal = "mice"

Write escape sequence involving all of them ? all in the same string literal

System.out.println ( " Roses are red , \n \t Violets are blue, n\ \t" + " Suger is sweet, \n\t But I have \ " commitment issues \ n \ t" + " So I'd rather just be friends \ n\ ta At this point in our " + relationship: " );

Tell me what is happing and the issue Result= 10 +10/2; what is the formula name of the issue Operator precedence Hierarchy ( OPH)

The calculation will occur and then be stored in the variable called " result" The issue is the order of operation is not correct Result = (10+10) / 2 is solution the computer will read it as an addition coming first. Prentiss can be nested and the innermost will be be used first Result = (10* (10+10) / 2 ) 10 +10 will go first

Operands

The inputs (operands) for an arithmetic operation could be numbers, variables, or arithmetic expression.

What is an operands and operators In the following example what is the operands and operators 2 + x = 10

The inputs (operands) for an arithmetic operation could be numbers, variables, or arithmetic expressions. ----- is the mathematical symbols intended for some calculation or comparisons + is the operator 2 and X are the operands

Write an example of combining basic operation with assignment

Total += 5; is same as total = total

System. out is represented ------- device println is used to tell --------- to print our texts. So println basically takes the "parameters" parameters --------

We send the println message to the system. out which an object, to request that some text be printed out. ( picture shows) object: system.out to used to represent the output device parameters: the data sent to the object found quotes

Variables and Assignments

a name for memory location used to value of particular type

Explain the difference bw a string and char a string is an ----, creates --------, and has ---------- around it char is a ------, stores ----------, and has -------- around it Why is this char = " X" be incorrect to be called a a string

a string is an object , creates a reference variable, and has double quotes around it char is a primitive data type, stores only a single letter, and had a single quote around it bc of of the char type and Double quotes but we can still string be its still a one letter in possible long text. the

A string is not primitive data type ( int, byte, short long) it is -------------

an object

Forgetting to put your curser in the code you just wrote

an old will ran

\b

backspace - causes the cursor to back up, or move left, one position

Which variables hold true or false ? which variable holds characters such as &

boolean char- ' A'

Name all primitive types who can hold whole numbers and how many memory spaces they can hold? Biking in Long Shorts!

byte = 1 bytes 2^8= 256 combinations short = 2 bytes int = 4 bytes long = 8 bytes We use 2^k( number of bits)

\r

carriage return

What are floating primitive ? floating varribles are -------- or/and------ depeding how much do you want to store ----- holds bytes ----- holds bytes what is the difference between ------- and ---------- the more ------ one is useful for ---------------

decimal number or nonwhole numbers float double float can is less precise since it holds much less space double can hold very large space so its more percises double is more precise scientific measurements

String have ----- around its texts

double quotes around its text

Red line under word in java

error and java won't run it

what happens if you use "int" variable when deviding a value that will give you a float or decimal number

even the value should be nonwhole number you will get an whole number

call stack

found in the RAM. This where the data stores in the permative types go.

\t Where do I put it ?

horizontal tab Put it at of double quotes to show it is for the next sentences System.out.println ( " Roses are red,\n \t Violets are blue, \n " /* Notice How ,in the bollow, we let out \t so Suger is Sweet wen back */ + "Suger is sweet,\n\t But I have \"commitments issues \" \n \t" + // another " " inside already " " Commitmenent issues "So I'de rather just be friends\n\t At this point in our" // need "+" b/c we droped to a new line + " relationship: " );

Write a variable declaration on the same line You only need one ------ which goes on the last variable

int cost = 10, food =1, people;

java converts some whole numbers into decimals to swtch b/w data types Write an example

int x; x=5; this will work double y; y=5; it will be stored as 5.0 But this will not work int 5.3;

Write a string literal being connected by String Concatenation

int yearInAfrica = 256; System. out.print(" Every year " + yearInAfrica + " passes in Africa " ); //show use /* I just placed a variable within a string, so I know all I have to do change the variable to change everything */

short Variable Type How many bytes of space does it take up in RAM ?

integer type that takes up 16 bits of memory (2 bytes)

int variable How many bytes of space does it take up in RAM ? Why do we say it takes 32 bits of memory?

integer type that takes up 34 bits of memory (4 bytes) - eats 4 bytes of space in RAM holds numbers inside a stack which is found inside the RAM

long variable holds - How many bytes of space does it take up in RAM? what kind of things does it store? What is a literal

integer type that takes up 64 bits of memory ( 8 bytes) 8 bytes -64 bits - used for storing whole numbers literal is an actual number

you can't store a variable higher --128-----and lower than the -------- number in the int variable.

integer type that takes up 8 bits of memory (1 byte) only 256 bytes 128 and neg 127

What will the following code print int x = 20; int y = 10; Sytem.out.println( " The sum is " + x + y); How would you turn it into arithmetic?

it will stringfy not add b/c incase there are multiple operators ( many " +" s ) and there are no precedence's over another ( mulplication has precedence over adding) the complier read from left to write. in this case a string and the " x" comes first. output: The sum is 53 put a Prentiss Sytem.out.println( " The sum is " + (x + y) );

primitive: char variable holds ----- with one ---------- on each side How many bytes does char hold ?

letter with a quotation on each side char holds 4 bytes

Assignments

look at the pic

Decimal numbers variables

look at the pic

Write a program to covert 32 Celsius temp to Fahrenheit temp using the equation

look at the pic

All primitive types are written in --- case

lower case ex: int, short

String is an ----- so you need a ---------------

object and reference

Variable can only store ----- of its own type.

one a new value overwrites the old one

System.out is an object of the class _________________. 1. Applet 2. Output 3. System 4. PrintStream

output

How do you make a constant in java

put a the word "final" before the declaration Capitalize the name with underscore if you are using two words Ex: final int = INTEREST_RATES

To store objects what variable do you need ---- variables For example, If we create a variable to hold a String object, then it is called reference variable because String is a class.

reference

String is

sequences of characters, symbols, and texts

If eighter left side or the right side is a string, then the " +" is for ------------ The only way the " +" sign applies for asthmatic is ----------- Forgetting to put you curser in the code you just wrote

string concatenation there are both numbers on both sides ( using prentis if needed ) Example int x = 20; int y = 10; System.out.println( " x is" + x ) // In that code there is both an a string ( " x is" ) and a single (+x) , so this works for string concatenation only

string literal What can it hold ?

text in double quotes

yellow line under word in java What is an example where that would occur:

warning but not a mistake that will prevent the compiler from runner the code When you have declared a variable you will never use

primitive: Boolean variable the l is boolean stands for -----------

when declaring a variable that is true or false; A Boolean value is either true or false in a logical way logic- b/c boolean is logic-based- only false or true variables boolean hasDog = true;

name all primitive variables ( note there are reference variables such as a string ) what is my mnemonics ?

whole numbers? when " Biking in Long shorts" make sure to decimal: " double float" words: boleans= true of false char= characters Double floats 1. int 2.byte 3.long 4.short 5. double 6. boolean 7. char 8. float


Related study sets

Chapter 16 Interest Rates and Monetary Policy Quiz

View Set

Unit 4: Foundations of Psychiatric Nursing

View Set

역학-인과성 판단의 근거

View Set

SOCI1001 - RELIABILITY & VALIDITY

View Set