click below
click below
Normal Size Small Size show me how
Java, Midterm
Methods, 1D Arrays, and Formatting Outputs
Question | Answer |
---|---|
Method/Function | Subroutines |
Formal Parameters | Defined in the method header. When the method is invoked we will be using the actual parameter. |
Actual Parameters | When a method is invoked you pass a value to the parameter. Also called argument. |
Return Value Type | The data type of the value the method returns |
Return Statement | Required for a value-return method. |
A benefit of methods | Reusable; don't have to repeat code (Modularizing). Hide the implementation from the user (Incapsulation). Reduce complexity, using the idea of divide and conquer. Also called the Stepwise Refinement. Decomposes the code into subproblems. |
Libraries | Give the coder access to additional features/tools. |
Scanner (import java.util.Scanner;) | Scans/reads/input strings into the console; based on the concept of scanning. Emphasizes platform independence. Also how Users can interact with program. |
Method Overloading | We use the same method name but with different argument types or number of arguments. |
/**This comment is called java doc. */ | These comments can be put in a separate document that help further describe/explain the code. Help build code documentation |
Ambiguous Invocation | When the method arguments are too similar,& there may be 2 or more possible matches for an invocation. Example: one method calls for a double while another calls for an int. Compiler can’t determine the match. Causes a compiler type of error. |
Local variable | A variable defined inside of a method. |
Scope | The part of the program where the variable can be referenced. The life of the variables. Once we are out of the method/loop/block/etc., that variable no longer exists. Must be declared before it can be used. |
Abstract method | Does not have a body. The body is provided by the subclass (inherited from). Process of hiding certain details and showing only essential information to the user. |
Array | A data structure that represents a collection of the same types of data. Must be logically related(the same data type) |
How to declare an array | double[] myList = new double[10]; |
How to declare and create an array in one line, if you know the size of the array. | Datatype[] arrayRefVar = new datatype[arraySize]; |
A PROPERTY used to get the size of the array | myList.length |
When an array is created, its elements are assigned these | Default Values; #s = 0, char = \u000, boolean = false |
BASIL_FD | Byte, Short, Int, Long, Float & Double (numeric primative data types from smallest to largest) |
Indexed Variables | How you normally navigate an array myList[i] |
Create, declare, and initialize an array in one step | double[] myList = {1.9, 2.9, 3.4, 3.5}; |
For Each also called The Enhanced For-Loop - -Helps to reduce the amount of code we need to write. | Don’t need to reference size or index. Just go through every element in the array. |
Garbage Collection Utility | Areas of memory that Java can’t access it considers it garbage. It checks the memory and if it finds something unacceptable, it removes it from memory, throws it in the garbage and helps to clear up space in the memory. |
Anonymous arrays | Used once and discarded. Usefully if you know you only need array for a temporary purpose. |
Java uses ______ to pass arguments to a method | Pass by value |
Heap | The JVM stores the array in an area of memory, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order. |
Class and class are the same reserved word. | False. Only if lowercase first letter. |
A value can be more than one data type. | False. Only one. |
compile AND THEN we interpret | True |
&& has a HIGHER precedence than || | True |
String can be written as string and mean the same thing. | False. Always uppercase first letter. |
Values are not assigned in the condition. | True |
Java compiler translates Java source code into _________. Java is not like other languages that DO compile it into machine code. | JavaBytecode |
How is Java robust | Java tries to catch errors as the code is being written. Not after it’s compiled. |
White spaces mean... | Nothing |
What is the engine that allows Java to be platform independent? | The JVM(Java Virtual Machine). |
What is used for writing(and compiling) a program? | JDK |