1/49
These flashcards cover key concepts, methods, and best practices in Data Structures and Java Class Library.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What is the role of comments in programming code?
Comments document and describe the meaning and purpose of lines of code.
Which method is used to output object content as a character string?
The toString() method.
What does the '==' operator compare in Java?
It compares object references, not their contents.
How do you compare the contents of two objects in Java?
By using the equals() method.
What can the hashCode() method be used for?
To generate a unique key based on the object's content.
What is a Java annotation?
Metadata about the source code that can be programmatically evaluated by the Java compiler.
What is the purpose of the Javadoc tool?
To automatically generate documentation from comments in the source code.
What do code conventions help with?
They assist in structuring, formatting, and naming classes, attributes, and methods.
What is a key feature of arrays in Java?
They provide a simple way to store lists of values or object references.
How are elements in arrays accessed and what is their index range?
Elements are accessed by their index, which starts at 0 and ends at n-1.
What is the difference between ArrayList and LinkedList?
ArrayList stores elements in an array, while LinkedList is implemented as a chain of linked nodes.
What do Set data structures in Java ensure?
They ensure that no duplicate elements exist.
What is the Java class associated with implementing a stack?
The class Deque or Stack can be used to implement a stack.
What does a Queue data structure represent?
A data structure where elements are processed in the order they are received (FIFO).
What is the purpose of the File class in Java?
To access and manipulate file and directory paths in the file system.
What is the use of a BufferedReader?
To read text from an input stream efficiently, buffering characters for performance.
What does the split() method do in Java?
It splits a string into an array of substrings based on a specified delimiter.
What is the significance of the constant File.separator?
It provides the correct file path separator based on the operating system.
What exceptions might be thrown when dealing with file operations?
FileNotFoundException and IOException are common exceptions.
How can you read a text file line-by-line in Java?
Using a BufferedReader with a FileReader.
What is the role of the try-catch block in file handling?
To handle potential exceptions that may occur during file operations.
What are Generics in Java?
An extension of Java’s type system that allows methods and classes to operate on objects of various types while providing compile-time safety.
What do Wrapper classes do in Java?
They encapsulate primitive data types into objects so they can be treated as objects.
What is the purpose of the compareTo() method?
To determine the ordering between two objects of the same class.
What is the primary task of a collection implementation in Java?
To store data efficiently and provide access to it.
What method would you use to generate a hash code for a String?
The hashCode() method.
What is the typical order of methods you use when working with collections?
Add, remove, and iterate.
How is the length of an array determined in Java?
By using the length attribute of the array.
What is the implication of strings being immutable in Java?
Strings cannot be changed after creation; any modification results in a new string object.
What does the Class Date represent in Java?
It represents specific points in time down to the millisecond.
What class is recommended for formatting dates in a locale-specific manner?
The class SimpleDateFormat.
What is the primary purpose of the java.nio.file package?
To provide a more intuitive framework for working with the file system.
How can files be compressed using data streams in Java?
By creating a pipeline of data streams that include a compressor.
What is a character-oriented data stream?
They interpret the data as characters and are used for text data.
What does the listFiles method of the File class do?
It retrieves and lists the contents of a specified directory.
What does the method mkdirs do?
It creates a directory and any necessary but nonexistent parent directories.
What types of data streams are used for binary data?
Byte-oriented data streams.
What does the method renameTo() do in file manipulation?
It renames a file or directory, effectively moving it in the file system.
What type of structure do Maps provide in Java?
Maps store key-value pairs for fast access to values associated with unique keys.
What will happen if you try to access an index in an array that is out of bounds?
An ArrayIndexOutOfBoundsException will be thrown.
What is a transient field in a serializable class?
A field that is not serialized when the object is serialized.
What exception is thrown if you attempt to read a file that does not exist?
FileNotFoundException.
What type of data can be processed using BufferedInputStream?
It processes binary data efficiently from input streams.
In what scenario would you use a TreeSet versus a HashSet?
Use a TreeSet for sorted order and HashSet for fast insertions/deletions without duplicates.
What do you need to do when handling resources such as file streams in Java?
Always ensure they are closed using finally or try-with-resources to prevent resource leaks.
What is the difference between shallow copy and deep copy?
Shallow copy copies references to objects, whereas deep copy copies the actual objects.
What is an Iterator in Java?
An interface that provides methods to traverse a collection.
How can you reduce memory consumption when concatenating many strings?
Using StringBuilder or StringBuffer to manage concatenation without creating multiple temporary string objects.
How can you ensure that your Java code is platform-independent?
Use the File.separator constant and handle path structures correctly.
How do you catch exceptions in Java?
Use try-catch blocks to handle unexpected situations.