Data Structures and Java Class Library Review

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/49

flashcard set

Earn XP

Description and Tags

These flashcards cover key concepts, methods, and best practices in Data Structures and Java Class Library.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

50 Terms

1
New cards

What is the role of comments in programming code?

Comments document and describe the meaning and purpose of lines of code.

2
New cards

Which method is used to output object content as a character string?

The toString() method.

3
New cards

What does the '==' operator compare in Java?

It compares object references, not their contents.

4
New cards

How do you compare the contents of two objects in Java?

By using the equals() method.

5
New cards

What can the hashCode() method be used for?

To generate a unique key based on the object's content.

6
New cards

What is a Java annotation?

Metadata about the source code that can be programmatically evaluated by the Java compiler.

7
New cards

What is the purpose of the Javadoc tool?

To automatically generate documentation from comments in the source code.

8
New cards

What do code conventions help with?

They assist in structuring, formatting, and naming classes, attributes, and methods.

9
New cards

What is a key feature of arrays in Java?

They provide a simple way to store lists of values or object references.

10
New cards

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.

11
New cards

What is the difference between ArrayList and LinkedList?

ArrayList stores elements in an array, while LinkedList is implemented as a chain of linked nodes.

12
New cards

What do Set data structures in Java ensure?

They ensure that no duplicate elements exist.

13
New cards

What is the Java class associated with implementing a stack?

The class Deque or Stack can be used to implement a stack.

14
New cards

What does a Queue data structure represent?

A data structure where elements are processed in the order they are received (FIFO).

15
New cards

What is the purpose of the File class in Java?

To access and manipulate file and directory paths in the file system.

16
New cards

What is the use of a BufferedReader?

To read text from an input stream efficiently, buffering characters for performance.

17
New cards

What does the split() method do in Java?

It splits a string into an array of substrings based on a specified delimiter.

18
New cards

What is the significance of the constant File.separator?

It provides the correct file path separator based on the operating system.

19
New cards

What exceptions might be thrown when dealing with file operations?

FileNotFoundException and IOException are common exceptions.

20
New cards

How can you read a text file line-by-line in Java?

Using a BufferedReader with a FileReader.

21
New cards

What is the role of the try-catch block in file handling?

To handle potential exceptions that may occur during file operations.

22
New cards

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.

23
New cards

What do Wrapper classes do in Java?

They encapsulate primitive data types into objects so they can be treated as objects.

24
New cards

What is the purpose of the compareTo() method?

To determine the ordering between two objects of the same class.

25
New cards

What is the primary task of a collection implementation in Java?

To store data efficiently and provide access to it.

26
New cards

What method would you use to generate a hash code for a String?

The hashCode() method.

27
New cards

What is the typical order of methods you use when working with collections?

Add, remove, and iterate.

28
New cards

How is the length of an array determined in Java?

By using the length attribute of the array.

29
New cards

What is the implication of strings being immutable in Java?

Strings cannot be changed after creation; any modification results in a new string object.

30
New cards

What does the Class Date represent in Java?

It represents specific points in time down to the millisecond.

31
New cards

What class is recommended for formatting dates in a locale-specific manner?

The class SimpleDateFormat.

32
New cards

What is the primary purpose of the java.nio.file package?

To provide a more intuitive framework for working with the file system.

33
New cards

How can files be compressed using data streams in Java?

By creating a pipeline of data streams that include a compressor.

34
New cards

What is a character-oriented data stream?

They interpret the data as characters and are used for text data.

35
New cards

What does the listFiles method of the File class do?

It retrieves and lists the contents of a specified directory.

36
New cards

What does the method mkdirs do?

It creates a directory and any necessary but nonexistent parent directories.

37
New cards

What types of data streams are used for binary data?

Byte-oriented data streams.

38
New cards

What does the method renameTo() do in file manipulation?

It renames a file or directory, effectively moving it in the file system.

39
New cards

What type of structure do Maps provide in Java?

Maps store key-value pairs for fast access to values associated with unique keys.

40
New cards

What will happen if you try to access an index in an array that is out of bounds?

An ArrayIndexOutOfBoundsException will be thrown.

41
New cards

What is a transient field in a serializable class?

A field that is not serialized when the object is serialized.

42
New cards

What exception is thrown if you attempt to read a file that does not exist?

FileNotFoundException.

43
New cards

What type of data can be processed using BufferedInputStream?

It processes binary data efficiently from input streams.

44
New cards

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.

45
New cards

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.

46
New cards

What is the difference between shallow copy and deep copy?

Shallow copy copies references to objects, whereas deep copy copies the actual objects.

47
New cards

What is an Iterator in Java?

An interface that provides methods to traverse a collection.

48
New cards

How can you reduce memory consumption when concatenating many strings?

Using StringBuilder or StringBuffer to manage concatenation without creating multiple temporary string objects.

49
New cards

How can you ensure that your Java code is platform-independent?

Use the File.separator constant and handle path structures correctly.

50
New cards

How do you catch exceptions in Java?

Use try-catch blocks to handle unexpected situations.