JAVA - What you need to know

Created by Jaina Stephens

Decimal to binary
number / 2 = end number + quotient do this until the number is gone, making a chart x/2 = Number Remainder repeat until you get a decimal at this point, the number you have before dividing is the bit Then reverse the remainders to get your binary

1/69

Review Mode
TermDefinition
Decimal to binarynumber / 2 = end number + quotient do this until the number is gone, making a chart x/2 = Number Remainder repeat until you get a decimal at this point, the number you have before dividing is the bit Then reverse the remainders to get your binary
Decimal to hexnumber / 16 = end number + quotient do this until the number is gone, making a chart x/16 = Number Remainder repeat until you get a decimal at this point, the number you have before dividing is the bit Then reverse the remainders to get your hex
Decimal to octnumber / 8 = end number + quotient do this until the number is gone, making a chart x/8 = Number Remainder repeat until you get a decimal at this point, the number you have before dividing is the bit Then reverse the remainders to get your oct
Decimal formJust write it like normal
Binary form1's and 0's, sometimes with a 1. or 0. in front for pos/neg
Hex form0x(the code)
Oct form0(the code)
Hex to decimalnumber x 16^ its place .... number x 16^0
Binary to decimalnumber x 2^ its place .... number x 2^0
Oct to decimalnumber x 8^ its place .... number x 8^0
Hex to binaryEach hex bit becomes a 4bit piece of binary
Hex to octEach hex bit becomes a 4bit piece of binary, then that becomes 3bit pieces, which we then turn into oct.
Binary to hexSection binary into 4's, then turn each 4 into a hex
Oct to hexConvert into binary, then section binary into 4's, then turn each 4 into a hex
binary to octBinary into sections of 3, then convert into hard numbers
oct to binaryEach oct bit becomes a 3bit binary
The color gray is created by using the same value for r, g, and b. How many shades of gray are there? Why255, because r, g, and b are 2bit hex, so max value is 255
The process of compiling a fileMake a file Name.java Then make sure the file name and class are the same Then in command type javac Name.java It will compile into Name.class Then to run we type in command run Name
=, +=, −=, *=, /=, %= <- What do these symbols mean?= applies the right value to the right var += is left eqls left + value -= is left eqls left - value *= is left eqls left * value /= is left eqls left / value %= is left eqls left % value
Rules for a Java file / class nameMust be the same, must use uppercase for each word
Rules for identifier / var / object / methodcamel case
Rules for legit all namingMust start with a valid Java letter Can have # just not at the start No spaces Case Sensitive No keywords, reserved words, or getting too close to them
Types of data and what they are used for (in order)byte, short, int, long, float, double, char, boolean |128|, |32k|, |2bil|, |9 gazillion|, small x.yz 4 byte, big x.yz 8byte, one character two bytes, true or false
Difference between x / y and x.0 / yusing ints will give you an int esc result even if the end result will be shown as a double. Instead, is one of the numbers is a double (.0) the math will be done assuming doubles are in play, and you will get a more precise number.
What do () do to the flow of operations?Instead of going left to right, you can change order to left to right, this affects casting.
Rules for ConstantAll caps and _ for spaces put final before the dataType
How to type floats and longs?end with the letter caps, ie 3.2F and 12L
, $ and % arenot literals, they are for computers
Char and Strings need what'' and ""
DataTypes can be declared how many timesOnce
Strings arelines of text that are treated as both class and data type
concatenation ie the combining of strings and vars to print
How many lines can a string be?Only one, any more and you have to use concatenation
\n, \t, \b, \', \", \\, \r, \fnewline, tab, backspace, quote, quotes, \, carrage return, form feed, all meant for the inside of strings
What is a packageA group of Java classes premade that can be imported
Methods can access/change whatthe instance variables within that class
Classes protect data howonly methods can change the fields so classes end up as a layer of protection for any data
Benefits of classesreliability, encapsulation, reusability
User imput can come from three placeskeyboard, file, user interface
What does System.in do? What is it?Means your Scanner will look at keyboard inputs. It is an input stream
What java package comes free with your xbox <- reference, not actual console based questionjava.lang
System - tell meSystem is a java.lang class it has static constant fields: in, out, exit In = keyboard out = java console exit = terminate program here, not at end of program
print and println - tell me broPrintStream take arguemtns of primitive data / string / object reference println prints a newline character right after the output
number in da system exit, write it, tell me what meanSystem.exit(num); 0 = normal terminate any other num = something wacky happen
toStringa method of every class automatically used whenever an obj is used as a string converts an object into a printable string value toString is used auto when an obj. is used in a string API => String toString();
Class() <- blank arugment list means whatThe constructor's default argument list will autofill there, whatever those values happen to be
API keeps track of whatmethods, classes, the types of data used in those methods, argument lists, etc
what happens if you use a method to set an objects variable to an inavlid valuethe method will not change the thing, ensuring valid values
WHat happens if I chance an objects refference to match another object. What happens to the object with two references now? What about the one with no reference?The reference moves to that other object, so now one object has two references, and the other has none. The one with two can now be reffered to multiple ways. The one with none is marked for garbage collection.
Garbage Collectorreleases memory of objects not referenced, dust in the wind now
when do we get the value nullwhen an object references is declared but not assigned an object
What happens when you run a method with a null referenceexception error
public vs private
static vs notmethod that can be called without needing an obj
constructor overloadas long as the parimeters are diff, you can have multiple constructors of the same class, this is called overlaoding
DecimalFormat - 0 # . , $ % <- What mean?0 = required digit - if no # given, will be a zero, will round up # = optional digit - if no # given, will be blank, will round up . = Decimal point ; = Comma separator $ = dollar sign % = multiplpy by 100, format, then and add percent sign
Static classes can use what? Can't use what?Cannot use obj data, can use class data
Wrapper classTurns a primitive dataType into an obj
Can you call a method on a prim. dataType? Nope, only objs
runtime errorbroken math rules
compile errorbroke java rules
logic erroryou fucked it up moron
those assigning statements, how workdataType varName = expression is the same thing as ClassName varName = new ClassName();
Can you cast onto varNames?Yes
Is the & symbol allowed in varNames?No
Classes to packagesScanner -> .util Character -> .lang NumberFormat -> .text Math -> .lang (default) DecimalFormat -> .text
You can string methods together maybe sometimes?scan.next().charAt(number);
binary opperationsmeaning they compare two vars, has nothing to do with binary 010011, binary as in two broski
! and || require both statements beboolean