Unit 1 Flashcards

1
Q

What is a programming language?

A

A system of communication used to instruct a computer to perform specific tasks.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a low-level programming language?

A

Languages that provide little abstraction from a computer’s instruction set architecture.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is machine code?

A

The lowest level of code, consisting of binary strings specific to hardware instructions.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is assembly language?

A

A low-level programming language that uses human-readable opcodes instead of binary.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

True or False: Assembly language is portable across different hardware.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are high-level programming languages primarily designed for?

A

To bridge the gap between human abstraction and machine-level operations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

List some examples of programming languages.

A
  • Fortran (1956)
  • COBOL (1960)
  • BASIC (1964)
  • Pascal (1971)
  • C (1972)
  • C++ (1979)
  • Java (1995)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the main feature of the C programming language?

A

Allowed flexible system-level programming without extensive use of assembly.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does ‘write once, compile anywhere’ refer to?

A

The ability of C to be compiled on any platform without modification.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Java originally known as?

A

Oak

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What were the original use cases for Java?

A

Interactive television set-top boxes.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the goals of Java?

A
  • Simple
  • Robust and secure
  • Portable and platform-neutral
  • Concurrent and event-driven
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the Java Virtual Machine (JVM)?

A

A specification for a target computer that interprets bytecode.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What does the Java Development Kit (JDK) include?

A
  • Java Runtime Environment (JRE)
  • Compiler (javac)
  • Debugger (jdb)
  • Documentation generator (javadoc)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the latest Long-Term Support (LTS) version of Java as of September 2023?

A

Java 21

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is OpenJDK?

A

The reference implementation of Java, which is free and open-source.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

What was the first killer app of Java?

A

The World Wide Web (WWW)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

What is a key difference between Java and C++?

A

Java is fully object-oriented while C++ allows both procedural and object-oriented paradigms.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

Fill in the blank: Java has _______ inheritance only.

A

single

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

What does Java lack in terms of memory management?

A

Direct memory access

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

True or False: Java allows operator overloading.

A

False

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

What is the primary advantage of Java’s garbage collection?

A

Automatic memory management

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

What is the main architectural feature of the Java Virtual Machine?

A

32-bit stack architecture

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

What is a significant characteristic of Java’s class structure?

A

One outer class per source file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
What is the purpose of the compiler in Java?
To convert Java code into bytecode that the JVM can execute.
26
What is the role of the Java Runtime Environment (JRE)?
To provide the necessary environment to run Java applications.
27
What must the file name of a Java class match?
The class name ## Footnote For example, the file Hello.java defines class Hello.
28
What is the purpose of Java packages?
To organize classes ## Footnote Packages affect namespaces, visibility, and access control.
29
What must a Java class have if it is part of a package?
A package statement on the first non-comment line ## Footnote If no package statement is present, it is placed in the default package.
30
What does the classloader do in Java?
Finds bytecode during compilation and runtime ## Footnote It checks usage against class definitions at compilation time and allows methods to be invoked at runtime.
31
What is the classpath in Java?
The path where the classloader searches for bytecode ## Footnote It includes standard libraries and user-defined classes.
32
What is the significance of the import statement in Java?
Allows omission of the package name ## Footnote For example, import java.util.Vector allows you to use Vector without specifying the full package name.
33
What does a wildcard import do?
Imports every class in a package ## Footnote Example: import edu.georgetown.cosc2020.*; does not recursively import subpackages.
34
Which package is always assumed to be imported in Java?
java.lang.* ## Footnote This allows classes like String to be used directly without a package prefix.
35
What are Java identifiers?
Names used for classes, methods, and variables ## Footnote They must start with an alphabetic character, '_', or '$' and cannot start with a digit.
36
How are Java classes structured?
Classes are the only global entities ## Footnote There are no global variables or functions in Java.
37
What are Java's primitive data types?
Numeric types, characters, and boolean ## Footnote Numeric types include byte, short, int, long, float, and double.
38
What is type coercion in Java?
Implicit type conversion when types are compatible and lossless ## Footnote Otherwise, it results in a compile-time error.
39
What are Java's type wrappers?
Object forms of primitive types ## Footnote Examples include Byte, Short, Integer, Long, Float, Double, Character, and Boolean.
40
What is autoboxing in Java?
Automatic conversion between primitive types and their corresponding wrapper classes ## Footnote Example: Integer jObj = j; where j is an int.
41
How do you declare an array in Java?
Using int[] arrayName or int arrayName[] ## Footnote Arrays are dynamically allocated in Java.
42
What is the syntax for a two-dimensional array in Java?
int[][] arrayName = new int[rows][columns] ## Footnote Arrays can also be 'ragged' where each row can have different lengths.
43
What types of operators are available in Java?
Arithmetic, relational, logical, and combined assignment ## Footnote Java does not support operator overloading.
44
What is a switch statement in Java?
A selection statement that can evaluate integral, character, enum, or String expressions ## Footnote It has fall-through behavior by default unless a break statement is used.
45
What are the types of loops available in Java?
While, do-while, traditional for, and enhanced for loops ## Footnote The enhanced for loop is also known as a range-based for loop.
46
What is the ancestor class of all throwable things in Java?
java.lang.Throwable ## Footnote This class includes errors and exceptions thrown by the JVM or through explicit throw statements.
47
What are the two main categories of throwables in Java?
* Errors * Exceptions ## Footnote Errors are serious problems that should not be caught, while exceptions can be caught and handled.
48
What does the Error class represent in Java?
Serious problems that a reasonable application should not try to resolve ## Footnote Examples include LinkageError and VirtualMachineError.
49
What is the purpose of the Exception class in Java?
Conditions that a reasonable application might want to catch ## Footnote Custom exceptions can be created by extending this class.
50
What is a RuntimeException?
A special kind of exception thrown by the JVM when bad behavior is detected ## Footnote Examples include ArithmeticException, NullPointerException, and ArrayIndexOutOfBoundsException.
51
What information does a Throwable class member provide?
* Stack trace * Message describing the problem * Cause (another Throwable) ## Footnote The cause is useful for chained exceptions.
52
What happens to an uncaught exception in Java?
It is passed to the calling method ## Footnote If uncaught by main(), execution ends and the exception is reported to the console.
53
What are the three parts of Java exception-handling?
* try * catch * finally ## Footnote They are used to handle exceptions gracefully.
54
What does the try block contain in exception handling?
The 'risky' code to attempt ## Footnote If an exception occurs, the execution stops immediately.
55
What is the role of the catch block?
To handle exceptions that occur in the try block ## Footnote It only executes if an exception is raised that matches the specified type.
56
What should a catch block do?
* Handle the situation indicated by the exception * Address the problem causing the exception * Allow normal execution to proceed * Pass information upward or re-throw the exception ## Footnote It may also throw a new exception with the original as a cause.
57
What is the significance of the order of catch blocks?
Catch blocks are checked first-to-last ## Footnote The first matching block executes, and subsequent blocks are not checked.
58
What is a multi-catch block in Java?
A single catch block that can handle multiple exception types ## Footnote Syntax: catch (ExceptionType1 | ExceptionType2 e) {}
59
What does the finally block do?
Executes after the try and catch blocks, regardless of success or failure ## Footnote It is used for cleanup code that must run in all scenarios.
60
What is the difference between Java’s finally and C++’s RAII?
Java uses finally for resource cleanup, while C++ uses RAII for automatic resource management ## Footnote RAII allocates resources in the constructor and frees them in the destructor.
61
What is the purpose of the throw statement?
To report a problem to the caller ## Footnote It consists of the keyword throw followed by an object of type Throwable.
62
What keyword is used to declare an exception-generating method?
throws ## Footnote It appears in the method signature after the parameter list.
63
What are checked exceptions?
Exceptions that must be addressed in a try-catch block or declared thrown ## Footnote They are detected during compile-time.
64
What advice is given for designing good methods regarding exceptions?
* Use exceptions to indicate unusual circumstances * Use checked exceptions almost all the time * Use unchecked exceptions for bugs or unexpected failures ## Footnote This approach helps with clarity and error management.
65
What are the two main types of Java I/O stream classes?
Byte streams and Character streams ## Footnote Byte streams handle binary data while character streams handle character data.
66
What is the primary function of InputStream and OutputStream in Java?
To read and write bytes respectively ## Footnote These are the abstract classes for byte stream operations.
67
What is the role of the java.io package in Java?
Provides standard I/O tools and classes ## Footnote It includes classes for file handling, data input/output, and stream management.
68
What does the term 'stream-based I/O' imply in Java?
An ordered sequence of bytes flowing into or out of your code ## Footnote It abstracts data sources or sinks without needing to know the specifics of the file system.
69
True or False: Most Java I/O classes are asymmetric.
False ## Footnote Most Java I/O classes are symmetric, meaning for every Input there is an Output.
70
What are the two abstract classes for byte streams in Java?
InputStream and OutputStream ## Footnote These classes provide the fundamental operations for reading and writing bytes.
71
What member fields does java.lang.System provide for standard streams?
System.in, System.out, System.err ## Footnote These fields are used to access input and output streams in Java.
72
What is the purpose of the File class in Java?
To abstract file operations such as exists(), create(), and delete() ## Footnote It provides methods to interact with the file system.
73
Fill in the blank: The fundamental operation of byte streams is to _______.
read/write a byte
74
What are the two abstract classes for character streams in Java?
Reader and Writer ## Footnote These classes are used for reading and writing character data.
75
What is the function of BufferedReader in Java?
To read text from a character input stream efficiently ## Footnote It provides methods like readline() for reading lines of text.
76
What does the java.util.Scanner class do?
Divides input into tokens separated by delimiters ## Footnote It provides methods to check and retrieve tokens based on their types.
77
What is the use of the try-with-resources statement in Java?
To automatically close resources at the end of the try block ## Footnote It simplifies resource management and reduces the need for finally blocks.
78
True or False: IOException is a checked exception in Java.
True ## Footnote It indicates that an I/O operation has failed or been interrupted.
79
What is the purpose of ObjectInputStream in Java?
To read serialized Java objects ## Footnote It is used to deserialize objects that were written to a stream.
80
What does the term 'buffering' refer to in I/O operations?
Storing data in memory temporarily to optimize performance ## Footnote Buffered streams help manage slow data sources more efficiently.
81
Fill in the blank: The fundamental operation of character streams is to _______.
read/write a character
82
What is the significance of the PrintWriter class in Java?
It provides formatted character output with auto-flushing capabilities ## Footnote It includes methods like println() to print formatted data.
83
How does the FileInputStream class work?
Constructed around a File object to read bytes from a file ## Footnote It allows for basic file reading operations.
84
What are the steps to handle exceptions during I/O operations?
Use try/catch blocks and include a finally block to close streams ## Footnote This ensures that resources are released even when an exception occurs.
85
What are the key definitions associated with Java classes?
Fields and methods; access control and static
86
What is the purpose of inner classes in Java?
To express compositional HAS A relationships
87
What is the C++ relationship to Java's object-oriented design?
C++ extended C to include object-oriented ideas
88
What does the .class extension in Java indicate?
Source/bytecode organization
89
What are the key object-oriented principles in Java?
Abstraction and encapsulation
90
How are Java classes declared and defined?
In a single file
91
What is an example of a Java class declaration?
public class Complex { ... }
92
What does instantiating an object in Java involve?
Using the new operator to invoke a constructor
93
What does the keyword 'private' indicate in member access levels?
Accessible only within the same class
94
What are the four access levels in Java?
* private * package private (default) * protected * public
95
What is a default constructor in Java?
A zero-argument constructor that creates a default object
96
What is the purpose of a copy constructor?
To create a new object as a copy of an existing object
97
What does the keyword 'static' mean in Java?
Class-level, meaning one copy for all instances
98
What is a static nested class?
An inner class declared as static, does not require an outer instance
99
What does 'extends' indicate in Java?
Inheritance from a superclass
100
What is the diamond problem in inheritance?
Ambiguity in method resolution when multiple paths of inheritance exist
101
What does polymorphism allow in Java?
A subclass reference to refer to superclass objects
102
What happens to private members in inheritance?
Subclasses inherit them but cannot access them directly
103
What must derived class constructors do?
Call the base class constructor using the keyword 'super'
104
What is dynamic method dispatch?
Method calls are resolved at run-time based on the object type in memory
105
What does the @Override annotation do?
Tells the compiler that a method is intended to override an inherited method
106
In Java, what does 'final' signify?
No changes allowed; final variables are constants
107
What is an abstract class?
A class that cannot be instantiated and may contain abstract methods
108
What is the purpose of interfaces in Java?
To represent a contract of behavior
109
How are methods in an interface declared?
Automatically abstract with no method body provided
110
What must fields in an interface be?
public, static, final
111
What is a pure abstract class?
A class that contains only abstract methods, serving as a contract
112
What does the keyword 'super' do in a subclass method?
Accesses the inherited version of an overridden method
113
What happens if a subclass does not match the method signature when overriding?
Compile-time error occurs
114
What is an example of a class that cannot be instantiated?
An abstract class
115
What is the implication of a class having abstract methods?
The class must be marked as abstract
116
What is a pure abstract class?
A pure abstract class is a class design that contains only abstract methods.
117
What is an interface in Java?
An interface is a representation of a contract of behavior.
118
How are Java interfaces declared?
Java interfaces are declared with the keyword 'interface'.
119
What characteristics do all methods in a Java interface have?
All methods in a Java interface are prototypes and automatically abstract.
120
What must be the properties of fields in a Java interface?
Fields in a Java interface must be public, static, and final.
121
What is the purpose of a class implementing an interface?
A class implements an interface to fulfill the contract for behavior defined by that interface.
122
True or False: A class can implement more than one interface.
True.
123
What does it mean for a class to implement all interface methods?
It means the class provides concrete implementations for each method defined in the interface.
124
What is the role of interface references?
Interface references refer to objects that implement the interface.
125
How do interfaces facilitate interchangeable parts?
Interfaces create an agreement between what one class needs and what another class provides, allowing for swapping implementors without affecting the user.
126
What are Java Generics?
Generics are an abstraction over type in Java.
127
How do Java Generics differ from C++ templates?
Java Generics only work for Object-type data and use type erasure at run-time, while C++ templates work with both primitives and objects and generate separate machine code for each data type.
128
What is the significance of the Object class in Java?
All objects in Java are subclasses of Object, allowing a reference to Object to point to any object.
129
Fill in the blank: A linked list node in Java can be defined as class Node with a _______ data type.
Object
130
What happens when a non-matching data type is set in a generic linked list node?
It results in a compile-time error.
131
What is the purpose of generics in Java?
Generics provide a way to define classes, interfaces, and methods with a placeholder for the type of data they operate on.
132
What is the type-checking behavior of Java Generics?
Type-checking occurs at compile time, but type erasure happens at run-time.
133
What is the implication of using a generic class Node?
It allows the node to store any type of data without the need for casting.