CSDS 132: Intro to Programming in Java (Final Exam Review)

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

What signals the Java lamba shortcut?

" - > "

What signals the Java method reference shortcut?

"::"

What is the difference between "=" "==" and equals?

"=" is an assignment operator whose return type is the same as the variable. "==" is an equality operator whose return type is boolean. equals is a method of object used to compare two objects.

What is "super ()"?

"super ()" is used to access the parent class constructor.

What is "super"?

"super" is used to access the specific variable of a superclass.

What is "this"?

"this" is used in the body of an instance method and it is the location in memory of the class instance that the method is acting on.

What is the format of a typecast?

(desired-type) value

What is an abstract class?

An abstract class is a class that cannot be directly instantiated. They are used to enforce common behavior of all "child" classes.

When is it better to use an array than a linked list?

An array is more beneficial than a linked list in situations where we need fast access to any arbitrary element.

What is a multidimensional array?

An array of arrays.

What are anonymous classes? What can they access?

Anonymous classes are a kind of local class in which the class is created on the same line of code that the instance is created. Anonymous classes have no name. They have access to everything the containing method has access to.

What are the different primitive operators?

Arithmetic operators, comparison operators, boolean operators, and equality operators.

What is the result type of boolean operators? (&&, ||, ! , &, |)

Boolean.

What is the result type of comparison operators? (>, <, >=, <=)

Boolean.

What is the result type of equality operators? (==, !=)

Boolean.

What is the difference between declaring and assigning a variable?

Declaring a variable refers to creating a variable. Assigning a variable refers to storing a value in the variable.

What are the four main primitive types?

Double, int, char, and boolean.

What does it mean to say that Java is strongly typed?

Every piece of data will have a well-defined type and an unambiguous type.

What are exceptions?

Exceptions are separate channels used to send error indications. They are NOT errors, but they are objects.

What is final?

Final is a non-access modifier applicable to only variables, methods, or classes. Final methods prevent method overriding, final variables create constant variables, and final classes prevent extensions..

What does the non-access modifier final do?

Final makes the classes, attributes, and methods non-changeable.

What is finally?

Finally contains all of the crucial statements, regardless of whether the exception occurs or not.

What is the "has-a" rule?

If A has-a B, then we make B a method/methods in A.

What is the "is-a" rule?

If A is-a B, then we make A and B classes where A extends B.

Why should we use an anonymous class over a normal one?

If the only place you need that class is at one location in the code there is no real need to make a whole new class with its own name and its own file. You just create the anonymous class at that one location in the code where the type is needed.

What are instance fields? When do they exist?

Instance fields are variables that belong to each instance of a given class. Every instance has its own version. They exist as long as the containing instance exists.

What is the purpose of wrapper classes?

Java has wrapper classes to allow us to store a primitive type inside an object. This gives us the ability to use primitives where the code is expecting objects.

What is the difference between linear search and binary search?

Linear search means to search straight through a collection of data from one end to the other. Binary search means to search through a collection of data beginning at some point within the data.

What are local types? What can they access?

Local types are types that are declared inside of methods. They have access to the local variables of the method, as well as anything of the class that the method has access to.

What are local variables? When do they exist?

Local variables are variables declared inside a method. They exist from the moment created until the end of the compound statement they are declared in.

What is method overloading?

Method overloading is creating multiple versions of a method. You can choose which version to call by changing the inputs to the method.

What is method overriding?

Method overriding is changing the behavior of a method so that all instances of a true type will use the new version of the method.

What are method parameters?

Method parameters are the variables that store inputs of methods.

What are method parameters? When do they exist?

Method parameters are variables that store an input to a given method. Parameters exist only in the body of the method they are in.

What is the fundamental property of a non-primitive type?

Non-primitive types are values that represent addresses to where the actual data for the value is stored.

What are non-static nested classes? What can they access?

Non-static nested classes are classes that are located within the body of another class. They belong to instances of the class. They have access to the non-static methods and fields of the instance belong to.

What is Optional?

Optional is a Java class. Its purpose is to wrap a non-primitive value that might be null, and have methods that let you do operations on that value without having to deal with the null explicitly.

What are packages?

Packages are folders used to group related classes.

What are generic types?

Placeholders (usually a single capital letter) that indicates that the type will be specified later.

What is polymorphism?

Polymorphism is the property of a value being many types at once.

What is the fundamental property of a primitive type?

Primitive types are values that directly represent values.

What does it mean to say that Java is strictly typed?

The compiler will verify that every type is used correctly. Java requires the programmer to use the data only for operations appropriate for the type.

Explain ? super JFrame.

The generic must be JFrame or wider. *Think: to the left of JFrame.*

Explain ? extends JFrame.

The generic the must be JFrame or narrower. *Think: to the right of JFrame*

What is the heap and what is stored in it?

The heap is unorganized memory used for data that needs to be permanent. The heap contains all classes and objects. Each class "object" in the heap stores the super class of that class, all static fields declared in that class, all methods (static and non-static) defined in the class, all constructors of the class, and any classes that are inside the class.

What is the main method?

The main method is a special method in Java. Every stand-alone program must have a main method, It is what the JVM calls to start the program.

What does the private access modifier do?

The private access modifier makes the code accessible only in the body of this type.

What does the protected access modifier do?

The protected access modifier makes the code accessible in this type and in any type that extends this type.

What does the public access modifier do?

The public access modifier makes the code accessible anywhere in the program.

What is the method call stack and what is stored in it?

The stack is organized memory used for method calls. The stack fame contains method parameters, the special value "this" on instance methods, local variables for the method, and bookkeeping information (where to send a return value).

What is the difference between the true type and current type of an object?

The true type of an object is the type it is initialized as using the new operator. The current type of an object is the type that it is currently typecast to.

What is the type of a value?

The type of a value is what the value represents.

What is the result type of arithmetic operators? (+, - , * , / , %)

The type of the wider operand, or int if both operands are narrower than int.

What is the Java lambda shortcut used for?

This shortcuts can be used for creating anonymous classes in the special case that the class is implementing an interface that contains a single method stub.

What are threads and when can they cause issues?

Threads are executions of your computer. They can cause issues when two executions try to use the same variables.

How do you catch an exception?

To catch an exception, we use try/catch blocks. try { - code that could throw an exception } catch (ExceptionType e) { - code that is executed if an exception of type ExceptionType occurs within the block - e is a variable that stores the exception object address }

When must typecasts be explicit?

Typecasts must be explicit when we are converting from a "wider" type to a "narrower" type.

What is unit testing?

Unit testing is testing the individual pieces of a program one at a time, instead of testing how the whole program works together.

When are typecasts done automatically?

Values are automatically converted from "narrower" types to "wider" types.

What are variables?

Variables are locations in memory. They are associated with types in Java and are used to store data.

What does volatile do?

Volatile informs Java that the value of the variables could be changed by another thread.

How do typecasts affect the values of primitive types?

When converting to a wider type, Java converts the value to be as close as possible to the original value. When converting to a narrower type, Java generally truncates the value.

When is it better to use a StringBuilder than a string?

When string concatenation is complex and a loop is required.

How do you access characters from a string?

You can access characters from a string using the charAt method in Java's string class.

How do you concatenate strings?

You concatenate strings using the + operator.

How do you declare/initialize a multidimensional array?

arraysType *to be stored* [] [] = new arraysType [1st] [2nd]

How do you write a foreach loop?

for (T i : desiredClass) loop-body-statement

How do you write a for loop?

for (initial statement; condition; increment statements) loop-body-statement

How do you write anonymous classes?

new TypeToExtendorImplement () { body of class }

How do you use a method reference shortcut?

objectOrClassToCallMethodOn :: nameOfMethodToCall

What does a constructor look like?

public ClassName (inputs) {

How do you create a class that contains a generic?

public class ClassName <Generic> {

How do you write a main method?

public static void main (String [] args) {

How do you declare an array?

type [] variableName;

How do you initialize an array?

variableName = new type [size]

How do you write a while loop?

while (condition) loop-body-statement

What can interfaces contain?

1) Static final fields 2) Static public nested types 3) Static methods 4) Abstract public instance methods (method stubs) 5) Private methods (starting in java 9)

What is the order of things that are executed inside a constructor?

1) The first line of the constructor is that calls another constructor is executed. 2) All fields of the instance are initialized. 3) The rest of the constructor body is executed.

What are the steps that occur when you execute the new operator?

1) Allocates space for the object 2) Initializes the object using the inputs to new 3) Returns the address of the object

What can abstract classes contain?

1) Constructors 2) Abstract methods 3) Non-abstract methods

What are the two ways to throw an exception?

1) Placing "throws ExceptionType" in the header 2) Explicitly (using the throw statement) throw e; throw new ExceptionType();

What are the JavaFX properties?

1) Stage: A window 2) Scene: What we place on the "stage" 3) Layout Manager: Dictates how the different GUI gadgets are arranged on the screen.

What is ArrayList?

A "wrapper" class for an array that allows us to use generics with the array and automatically handles the "allocate a new array and copy data over" when the array runs out of memory.

What is an array?

A collection of variables of the same type.

What is a constructor? What is its purpose?

A constructor is a special instance method that is called by the new operator to initialize a class.

What is a linked list?

A data structure that holds a sequence of linked nodes.

What is a jar file?

A jar file is a collection of Java .class files.

When is it better to use a linked list than an array?

A linked list is more beneficial than an array in situations where we need to easily decrease of increase the size of the collection of data or insert and delete information at any location within the collection.

What is an interface?

A non-primitive type like a class, but it cannot contain instance methods, fields, or constructors. Their main purpose is to contain public abstract methods.

How is data represented on a computer?

All data is represented by wires that are on or off.

Why must we make some variables final when using them in an anonymous class?

Since anonymous classes are stored in the heap, while local variables and method parameters are stored on the stack, the memory difference can cause errors. Because of this, Java limits anonymous classes to only use local variables if they are final.

What are static fields? When do they exist?

Static fields are variables that belong to a given class. All instances of the class share one copy. They exist for the duration of the program.

What is the difference between static and non-static fields?

Static fields belong to the class as a whole.

What is the difference between static and non-static methods?

Static methods belong to the class itself and non-static methods belong to the object that is generated from that class.

What are static nested classes? What can they access?

Static nested classes are classes that are located within the body of another class. They belong to the class itself. They have access to the static private fields and methods of the class they are inside.

What are the four nested types?

Static nested types, non-static nested types, local types, and anonymous classes.

How do you create a string?

String variable-name = " ";

What is StringBuilder?

StringBuilder is a class that optimizes the amount of memory used when creating a string.

What are wildcards?

Symbols used in place of generic types that mean we are not requiring the type to be anything other than object and we are not doing any operation that would require type-checking the generic.

What does synchronized do?

Synchronized is used to lock code.


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

Scrum Guide---Definition of done

View Set

Save the Planet! Trivia questions

View Set

Accounting 1 Spring final review vocab

View Set

chapter 8 - mastering microbiology

View Set

GULLIVER'S TRAVELS Jonathan Swift Topic Test

View Set

UNIT 7 - LIFE INSURANCE POLICY PROVISIONS

View Set

Ch 1: Intro to Anatomy & PhysiologyAssignment

View Set