Exam 1 Flashcards
Java is a fully ___.
Object-oriented language
High-level languages
Python/Java -meant for humans
Machine code
Low-level code that can be executed on a computer
Bytecode
Between high and low level code-easier to interpret into machine instructions
Interprets bytecode into machine code
Virtual machine -different ones needed for different OS
All Java programs require ___
Scaffolding -all code must be in body of a class
Static
Marks a method or field as belonging to the class it’s in -can be accessed without creating an object
Public
Accessible from anywhere outside the class
All strings must be enclosed in ___
Double-quotes
Maven
Organizers, compiles, and runs code.
Manages third-party dependencies by downloading from Internet
Java is a ___ typed language
Statically
To create a long or float (instead of int or double)
Add l or f to end of number
Primitive types
Integers, floats, characters, booleans
Reference types
Strings, arrays, objects
T/F: Any type can be concatenated to a string
True, using +
Result of arithmetic operators using both an int and a float
Float -more complex type
T/F: Strings are iterable
False
Also can’t use []. Must use charAt(int index) to find char
T/F: Java supports negative indexes
False. Index from 0 to length - 1
String literal pool
If same string literal used in multiple places, single copy stored and reused
All functions in Java are __
Methods
Assigning the return value of a void method to a variable results in a ___
Compiler error
T/F: A void method can return an empty (return;)
True
Except for void methods, all branches of a method must terminate with a ___ statement
Return
Structure of a for statement
Initialization -executed exactly once
Boolean expression - evaluated before each iteration
Modification statement -executed after each iteration
Safe type converting
Less complex type to more complex. No loss of data
Conversion of types can be forced using ___
Casting: int x = (int) 3356787645754;
Scanner
Package to read input.
next() next word entered until whitespace
nextLine() everything up to enter key
nextInt(), long, float…
Arrays are allocated as a __ block of memory
Contiguous
How to initialize an array
Integers = new int[10]
Array default values
0 for numeric types (including char),
False for booleans,
Null for reference types
2D arrays
Array of arrays, first dimension values are just addresses to other arrays
T/F: in try/catch, catch doesn’t need to specify the exception being caught
False
Methods available from creating file instance JUST using the File class constructor
exists -if file exists at path
IsDirectory - returns if file if a directory
getAbsolutePath
length -number of bytes
To read character data from text, the __ and __ packages are needed
FileReader and BufferedReader
Scanner, FileReader, and BufferedReader should be ___ when finished with
Closed. close()
How to handle checked exceptions
Using try/catch
Rethrowing by adding a throws declaration (string readline() throws IOException
T/F: Unlike unchecked exceptions, checked exceptions must be handled
True
Nearly all methods for reading data from files can throw a ___
IOException
Packages to write to files
FileWriter and PrintWriter
How to write to a file
[writer object].print(…) for a string
[writer object].println(…) for string with newline
[writer object].flush() pushes changes