Midterm Review Flashcards

1
Q

What is the difference between a Simple and Prepared JDBC statement?

A

A Simple JDBC statement is executed directly without pre-compiling, which makes it vulnerable to SQL injection.

A PreparedStatement, on the other hand, is precompiled, allowing for parameterized queries, which enhances security and performance.

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

What is SQL Injection and how can we prevent it using JDBC?

A

SQL Injection is a security vulnerability where an attacker can manipulate SQL queries by injecting malicious input. To prevent it in JDBC, use PreparedStatement or CallableStatement with parameterized queries to avoid direct concatenation of user inputs.

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

What is a foreign key?

A

A foreign key is a column or a set of columns in a table that uniquely identifies a row in another table. It is used to establish and enforce a link between the data in two tables.

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

What is normalization?

A

Normalization is the process of organizing data to reduce redundancy and improve data integrity by dividing a database into two or more tables and defining relationships between them.

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

What is referential integrity?

A

Referential integrity is a property of a relational database that ensures relationships between tables remain consistent. For example, a foreign key in one table must match a primary key in another table.

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

What is multiplicity?

A

Multiplicity defines the number of instances of one entity that can or must be associated with each instance of another entity in a relationship, such as one-to-many or many-to-many.

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

Describe what a join is

A

It is an SQL operation that combines rows from two or more tables based on a related column.

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

Explain the different types of joins we can create.

A
  • INNER JOIN: Returns rows with matching values in both tables.
  • LEFT JOIN (or LEFT OUTER JOIN): Returns all rows from the left table and matched rows from the right table.
  • RIGHT JOIN (or RIGHT OUTER JOIN): Returns all rows from the right table and matched rows from the left table.
  • FULL JOIN (or FULL OUTER JOIN): Returns rows when there is a match in one of the tables.
  • CROSS JOIN: Returns the Cartesian product of both tables.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the difference between a join and a set operation?

A

Joins combine columns from multiple tables based on a related column, while set operations (such as UNION, INTERSECT, and EXCEPT) combine rows from multiple queries. Joins merge data horizontally, while set operations merge data vertically.

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

What is a view and why is it useful?

A

A view is a virtual table created by a query on one or more tables. It is useful for simplifying complex queries, presenting data in a specific format, and enhancing security by restricting access to certain data.

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

What is HTTP? Why is it important to know about?

A

HTTP (Hypertext Transfer Protocol) is a protocol used for transferring hypertext requests and information on the web. It is important to understand HTTP because it is the foundation of data communication on the web.

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

What are common HTTP verbs used when a client application is making a request?

A

Common HTTP verbs include:
* GET: Retrieve data from the server.
* POST: Send data to the server.
* PUT: Update data on the server.
* DELETE: Remove data from the server.
* PATCH: Apply partial modifications to data.

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

What are some common HTTP status codes that can be included in a response?

A

Common HTTP status codes include:
* 200 OK: Request succeeded.
* 201 Created: Resource created successfully.
* 204 No Content: Request succeeded, no content to return.
* 400 Bad Request: Client-side error.
* 401 Unauthorized: Authentication required.
* 404 Not Found: Resource not found.
* 500 Internal Server Error: Server-side error.

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

What is a RDBMS?

A

An RDBMS (Relational Database Management System) is a database management system that stores data in a structured format, using tables that can be related to each other based on data values.

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

What is SQL and why would we use this language?

A

SQL (Structured Query Language) is a language used for managing and manipulating relational databases. It allows for querying, updating, and managing data, which is essential for interacting with relational databases.

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

What are the SQL sublanguages and their purpose?

A

SQL sublanguages include:
* DML (Data Manipulation Language): For querying and modifying data (e.g., SELECT, INSERT, UPDATE, DELETE).
* DDL (Data Definition Language): For defining and modifying database structures (e.g., CREATE, ALTER, DROP).
* DCL (Data Control Language): For controlling access to data (e.g., GRANT, REVOKE).
* TCL (Transaction Control Language): For managing transactions (e.g., COMMIT, ROLLBACK).

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

Describe relational database tables.

A

Relational database tables are structured collections of data organized into rows and columns. Each row represents a record, and each column represents an attribute of the record. Tables are related to each other through keys.

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

What are constraints and can you describe a few constraints?

A

Constraints are rules enforced on columns to ensure data integrity. Examples include:
* PRIMARY KEY: Uniquely identifies each record.
* FOREIGN KEY: Enforces a link between tables.
* UNIQUE: Ensures all values in a column are unique.
* NOT NULL: Ensures a column cannot have NULL values.

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

What are some operators that can be used in SQL?

A

SQL operators include:
* =, <, >, <=, >=, <> (or !=): Comparison operators.
* AND, OR, NOT: Logical operators.
* BETWEEN, LIKE, IN: Specialized operators for matching and range queries.

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

Why would I use the WHERE clause?

A

The WHERE clause is used to filter records based on specified conditions, allowing you to retrieve only the rows that meet certain criteria.

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

What is the JDBC API and the benefits of using it?

A

The JDBC (Java Database Connectivity) API is a Java-based API for connecting and executing queries on a database. Benefits include standardization of database access, ease of use, and integration with Java applications.

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

What is the DAO Design Pattern and why should we use it?

A

The DAO (Data Access Object) design pattern provides an abstract interface for interacting with a database, separating data access logic from business logic. It promotes code modularity, maintainability, and testability.

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

What information would you need in order to successfully connect to a database?

A

To connect to a database, you need:
* JDBC URL: The database location and protocol.
* Username: The database user account.
* Password: The password for the user account.
* Driver: The JDBC driver for the specific database.

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

Describe abstraction and how would you use it in a project?

A

Abstraction involves hiding the complex implementation details and showing only the necessary features. In a project, use abstraction to define abstract classes or interfaces to represent generalized concepts and hide complexity.

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

Describe encapsulation and how would you use it in a project?

A

Encapsulation is the concept of wrapping data and methods into a single unit, typically a class, and restricting direct access to some of the object’s components. Use encapsulation to protect data integrity and provide controlled access through getter and setter methods.

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

What are the four levels of access we can give to class members? How are they different from one another?

A

The four access levels are:
* public: Accessible from anywhere.
* protected: Accessible within the same package and subclasses.
* default (no modifier): Accessible only within the same package.
* private: Accessible only within the same class.

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

What is the purpose of using getter and setter methods?

A

Getter and setter methods provide controlled access to private fields of a class, allowing for encapsulation and data validation while maintaining the integrity of the object.

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

Why would you use an interface over an abstract class?

A

Use an interface when you need to define a contract that multiple classes can implement, especially if the classes do not share a common base class. Interfaces support multiple inheritance, unlike abstract classes.

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

What are the SOLID design principles and are they important?

A

SOLID principles are guidelines for object-oriented design:
* S: Single Responsibility Principle (SRP)
* O: Open/Closed Principle (OCP)
* L: Liskov Substitution Principle (LSP)
* I: Interface Segregation Principle (ISP)
* D: Dependency Inversion Principle (DIP) They are important for creating maintainable, flexible, and scalable code.

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

What is Maven? Why would we use it?

A

Maven is a build automation tool used primarily for Java projects. It simplifies project builds, dependency management, and project documentation through a standardized approach and a POM (Project Object Model) file.

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

What is the SDLC? Why is it important?

A

SDLC (Software Development Life Cycle) is a process used for planning, creating, testing, and deploying software. It is important for ensuring systematic, organized, and efficient development.

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

When would you use an Agile methodology versus Waterfall?

A

Use Agile when projects require flexibility, frequent updates, and customer feedback. Use Waterfall for projects with well-defined requirements and a clear, linear progression.

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

What are the Maven build lifecycle phases?

A

Maven build lifecycle phases include:
* validate: Validate the project structure and configuration.
* compile: Compile the source code.
* test: Run tests.
* package: Package the compiled code into a distributable format.
* verify: Perform any additional verification.
* install: Install the package into the local repository.
* deploy: Deploy the package to a remote repository.

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

Describe the POM.xml file and its importance.

A

The POM.xml (Project Object Model) file is the core configuration file in a Maven project. It defines project dependencies, build configurations, and plugins, and manages project information and settings.

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

What is source control management? Why is it useful?

A

Source control management (SCM) tracks and manages changes to source code over time. It is useful for versioning, collaboration, and maintaining a history of code changes.

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

What are the main sections of a Git project?

A

Main sections of a Git project include:
* Working Directory: The current files you are working on.
* Staging Area (Index): Where you prepare files to be committed.
* Repository: Where committed files are stored.

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

What are some common Linux commands? Why are they useful?

A

Common Linux commands include:
* ls: List directory contents.
* cd: Change directory.
* cp: Copy files or directories.
* mv: Move or rename files or directories.
* rm: Remove files or directories.
* chmod: Change file permissions.
* grep: Search for text in files.

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

What are some common operations you would be performing when using Git?

A

Common Git operations include:
* git init: Initialize a new repository.
* git clone: Clone a repository.
* git add: Stage changes for commit.
* git commit: Commit staged changes.
* git push: Push commits to a remote repository.
* git pull: Fetch and merge changes from a remote repository.
* git branch: List or create branches.
* git merge: Merge branches.

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

What is the difference between assigning and declaring a variable?

A

Declaring a variable means defining its type and name, while assigning a variable involves initializing it with a value. Declaration and assignment can occur together or separately.

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

What do a pair of opening and closing curly braces represent?

A

A pair of curly braces {} defines a block of code, such as the body of a method or class.

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

What is the difference between source code and bytecode?

A

Source code is the human-readable code written in a programming language. Bytecode is the intermediate code generated by a compiler that can be executed by a virtual machine, such as the Java JVM.

40
Q

What is the difference in syntax between calling a method and creating a method?

A

Creating a method involves defining its signature (return type, name, parameters) and body. Calling a method involves using its name and passing required arguments.

41
Q

What is a method?

A

A method is a block of code that performs a specific task and can be called upon to execute. It may take parameters and return a value.

42
Q

What is a variable?

A

A variable is a storage location identified by a name and used to hold data that can be modified during program execution.

43
Q

What is the difference between the JDK, JRE, and JVM?

A
  • JVM (Java Virtual Machine): Executes Java bytecode.
  • JRE (Java Runtime Environment): Provides the JVM and standard libraries needed to run Java applications.
  • JDK (Java Development Kit): Includes the JRE and development tools like compilers and debuggers for developing Java applications.
44
Q

What is a conditional statement?

A

A conditional statement controls the flow of execution based on whether a condition is true or false, using constructs like if, else, else if, and switch.

45
Q

Explain the different kinds of loops you can create and use in a program.

A

Common loops include:
* for: Repeats a block of code a specific number of times.
* while: Repeats a block of code while a condition is true.
* do-while: Similar to while, but guarantees the block executes at least once.

46
Q

Explain the main method.

A

The main method is the entry point of a Java application. It must be defined as public static void main(String[] args).

47
Q

What is a primitive datatype? Please list a few and explain them.

A

Primitive datatypes are basic data types provided by Java. Examples include:
* int: Integer values.
* double: Floating-point numbers.
* char: Single characters.
* boolean: True or false values.

47
Q

What are shorthand assignment operators?

A

Shorthand assignment operators combine an arithmetic operation with assignment, such as +=, -=, *=, /=, %=.

48
Q

What is the modulo operator? How is it useful?

A

The modulo operator % returns the remainder of a division operation. It is useful for determining if a number is divisible by another or for cyclic operations.

49
Q

How do you use increment and decrement operators?

A

Increment (++) and decrement (–) operators increase or decrease a variable’s value by one, respectively. They can be used in prefix (++var) or postfix (var++) forms.

50
Q

How can you iterate over an array?

A

You can iterate over an array using a for loop or an enhanced for loop.

Example:

java
Copy code
for (int i = 0; i < array.length; i++) {
// Access array[i]
}
or
java
Copy code
for (int element : array) {
// Access element
}

51
Q

What is an array? Why is it useful?

A

An array is a data structure that stores a fixed-size sequence of elements of the same type. It is useful for efficiently storing and accessing multiple values using indices.

52
Q

What is a stacktrace? How can you use it to debug your application?

A

A stacktrace provides information about the call stack at the point an exception was thrown. It helps identify the sequence of method calls leading to the error, aiding in debugging.

53
Q

What is a stacktrace? How can you use it to debug your application?

A

A stacktrace provides information about the call stack at the point an exception was thrown. It helps identify the sequence of method calls leading to the error, aiding in debugging.

54
Q

What is the Scanner class used for? Give an example of how you would use it.

A

The Scanner class is used for reading input from various sources, including user input from the console.

Example:

java
Copy code
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();

55
Q

When would you use a switch statement over an if statement?

A

Use a switch statement when you have multiple discrete values to compare against a single variable, as it can be more readable and efficient.

56
Q

When would you use an if statement over a switch statement?

A

Use an if statement for complex conditions or when dealing with ranges or non-discrete values. Use switch for cleaner code with discrete values, such as enumerations or constants.

56
Q

What is an operating system?

A

An operating system is software that manages hardware resources and provides services for computer programs. It acts as an intermediary between users and the computer hardware.

57
Q

What does the term “full stack” mean?

A

“Full stack” refers to the complete set of technologies and layers required to develop a complete application, including both frontend (client-side) and backend (server-side) components.

58
Q

Which datatype represents text in Java?

A

The String datatype represents text in Java.

59
Q

How would you access the last value in an array if you do not know the size of the array?

A

Use the length property to access the last value:
java
Copy code
array[array.length - 1]

60
Q

What steps would you take to debug your program if it crashed with an error message in the console?

A

Check the error message and stacktrace for clues, review the code at the indicated line, ensure there are no syntax errors, and use debugging tools to inspect variables and execution flow.

61
Q

: What steps would you take to debug your program if it runs, but gives you the wrong results?

A

Verify the logic of your code, check input values and assumptions, use print statements or a debugger to trace execution, and test individual components to isolate the issue.

62
Q

Give me an example of why you would need to create a method other than the main method.

A

Creating methods helps modularize code. For example, a method calculateArea() can be used to compute the area of a shape, improving code reusability and readability.

63
Q

How would you describe the compilation process for Java?

A

The compilation process converts Java source code into bytecode using the javac compiler. The bytecode is then executed by the JVM.

64
Q

Can you describe some of the basic entities of a Java program?

A

Basic entities include:
* Classes: Blueprints for creating objects.
* Objects: Instances of classes.
* Methods: Functions defined within classes.
* Variables: Storage for data.

65
Q

What are some of the benefits of Java?

A

Benefits of Java include platform independence (write once, run anywhere), strong community support, rich standard libraries, and robust security features.

66
Q

What is a flow control statement?

A

Flow control statements manage the execution order of code, including conditional statements (if, switch) and loops (for, while, do-while).

67
Q

What is a package and why would we use one?

A

A package is a namespace that organizes related classes and interfaces. It helps in managing code modularity, avoiding name conflicts, and improving maintainability.

68
Q

What is a fully qualified class name?

A

A fully qualified class name includes the package name and the class name, such as com.example.MyClass.

68
Q

If you received text input from the user, how would you go about comparing it to a value, like “yes” or “no”?

A

Use the equals() method to compare strings:
java
Copy code
if (input.equals(“yes”)) {
// Do something
}

69
Q

What is the difference between using an instance variable and a static variable?

A

An instance variable is unique to each object instance, while a static variable is shared across all instances of a class.

69
Q

If there was an error in the console when you tried to run your program, how would you debug?

A

Review the error message and stacktrace, check for syntax errors or exceptions, and use debugging tools to inspect the code and execution flow.

69
Q

What is the difference between calling an instance method and a static method?

A

An instance method requires an object to be called and can access instance variables. A static method can be called on the class itself and can only access static variables.

70
Q

What are the different scopes in Java?

A

Scopes in Java include:
* Local Scope: Within a method or block.
* Instance Scope: Within an instance of a class.
* Class Scope: For static variables and methods within a class.

70
Q

If I define a variable within a method, how can I access its value outside of the method?

A

Variables defined within a method are local to that method and cannot be accessed outside. To access data outside, use instance variables or return values from the method.

71
Q

What are classes used for?

A

Classes are used to create objects, define data structures, and encapsulate methods and variables that operate on the data.

72
Q

Describe what an object is.

A

An object is an instance of a class that encapsulates data (attributes) and methods (functions) that operate on the data.

73
Q

What is the role of garbage collection in Java?

A

Garbage collection automatically reclaims memory occupied by objects that are no longer in use, helping manage memory efficiently and preventing memory leaks.

73
Q

What is the difference between an array and an ArrayList?

A

An array is a fixed-size collection of elements of the same type, while an ArrayList is a resizable collection from the Java Collections Framework.

73
Q

What is the difference between an Error and an Exception?

A

Errors are severe issues not typically handled by applications (e.g., OutOfMemoryError), while exceptions are conditions that applications can handle (e.g., IOException).

74
Q

Describe the difference between the stack and the heap.

A

The stack stores method call frames, including local variables and control flow, while the heap stores objects and their associated data. The stack is faster but has limited size, while the heap is larger but slower.

75
Q

What is a constructor and how is it different from a method?

A

A constructor initializes a new object and has the same name as the class, while a method performs operations and has a name that is different from the class name.

75
Q

What is the difference between a checked and an unchecked exception?

A

Checked exceptions must be declared or handled, while unchecked exceptions (RuntimeException and its subclasses) do not need to be explicitly handled or declared.

75
Q

How would you handle an exception?

A

Use a try-catch block to handle exceptions:
java
Copy code
try {
// Code that may throw an exception
} catch (Exception e) {
// Handle the exception
}

76
Q

What is explicit and implicit casting?

A

Implicit casting automatically converts a smaller data type to a larger one. Explicit casting manually converts a larger data type to a smaller one.

77
Q

What is autoboxing and unboxing?

A

Autoboxing is the automatic conversion of primitive types to their corresponding wrapper classes. Unboxing is the conversion of wrapper classes back to primitive types.

78
Q

What are some operations you can perform on a List?

A

Operations on a List include adding, removing, and accessing elements, as well as sorting and iterating through the list.

79
Q

Describe polymorphism and how would you use it in a project?

A

Polymorphism allows objects to be treated as instances of their parent class, enabling one interface to be used for a general class of actions. Use it to simplify code and enhance flexibility.

80
Q

Describe inheritance and how would you use it in a project?

A

Inheritance allows a class to inherit fields and methods from another class, promoting code reuse and creating a hierarchical relationship. Use it to extend functionality and create specialized subclasses.

81
Q

How is method overriding different from method overloading?

A

Method overriding redefines a method in a subclass with the same signature as in the parent class. Method overloading involves defining multiple methods with the same name but different signatures in the same class.

82
Q

What methods are commonly overridden from the Object class and why?

A

Commonly overridden methods include toString(), equals(), and hashCode(). These methods provide custom string representations, equality checks, and hash codes for objects.

83
Q

What state and behavior would you define in a subclass but not in the parent class?

A

Define state and behavior specific to a subclass, such as unique attributes and methods that extend or refine the parent class functionality.

84
Q

What state and behavior would you define in a parent class but not a subclass?

A

Define state and behavior in a parent class that is common to all subclasses, such as shared properties and methods that are not specific to any single subclass.

85
Q

How does upcasting an object work?

A

Upcasting refers to casting a subclass object to its superclass type. This is safe and allows for more general handling of objects.

86
Q

How does downcasting an object work?

A

Downcasting refers to casting a superclass object to a subclass type. This requires an explicit cast and should be done with caution to avoid ClassCastException.

87
Q

What is a Collection in Java?

A

A Collection is a framework in Java that provides a set of classes and interfaces for storing and manipulating groups of objects.

88
Q

What is the difference between a Stack and a Queue?

A

Stack: A collection that follows LIFO (Last-In-First-Out) order. Example operations include push and pop.

Queue: A collection that follows FIFO (First-In-First-Out) order. Example operations include enqueue and dequeue.