0% found this document useful (0 votes)
2 views

CC and Java

The document provides definitions and explanations of various Java concepts, including Collections, Frameworks, Iterators, Lists, Threads, JDBC, and compiler phases. It also covers parsing techniques, including top-down and bottom-up parsing, as well as attributes in syntax-directed definitions. Additionally, it discusses multithreading, database connectivity, and the elimination of left recursion in grammars.

Uploaded by

akgaming45ff
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

CC and Java

The document provides definitions and explanations of various Java concepts, including Collections, Frameworks, Iterators, Lists, Threads, JDBC, and compiler phases. It also covers parsing techniques, including top-down and bottom-up parsing, as well as attributes in syntax-directed definitions. Additionally, it discusses multithreading, database connectivity, and the elimination of left recursion in grammars.

Uploaded by

akgaming45ff
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

1.

Define Collection
A Collection in Java is a framework that provides architecture to store and
manipulate a group of objects efficiently. It includes interfaces like List, Set, and
Queue.

2. Define Framework
A Framework in Java is a collection of pre-defined classes and interfaces that
provides a reusable structure for software development, such as the Collection
Framework and Spring Framework.

3. Define Iterator
An Iterator is an interface in Java that provides methods (hasNext(), next(), remove())
to iterate over elements in a Collection one by one.

4. Define List
A List in Java is an ordered collection that allows duplicate elements. It is part of the
Collection Framework and implemented by classes like ArrayList, LinkedList, and
Vector.

5. What is TreeSet?
TreeSet is a class in Java that implements the Set interface and stores elements in
sorted order (ascending by default). It does not allow duplicate values and is backed
by a Red-Black tree.

6. Difference between Array and ArrayList

o Arrays have a fixed size, while ArrayLists are dynamic.

o Arrays can store both primitive and object types, whereas ArrayList only
stores objects.

o ArrayList provides built-in methods like add(), remove(), and size(), which
arrays do not.

7. Define Thread
A Thread in Java is a lightweight process that allows concurrent execution of tasks to
improve performance.

8. Define Thread Property


Thread properties include attributes like priority, state, and daemon status that
determine how a thread behaves in execution.

9. What is a Multithreading Program?


A multithreading program is a Java program that allows multiple threads to run
concurrently to enhance performance and responsiveness.
10. Thread is a lightweight process. Comment
Yes, a thread is called a lightweight process because multiple threads share the same
process memory but execute independently, reducing resource consumption.

11. What is the use of the notifyAll() method?


The notifyAll() method wakes up all threads that are waiting on an object's monitor,
allowing one of them to proceed based on scheduling.

12. What is the use of the notify() method?


The notify() method wakes up a single thread that is waiting on an object's monitor.

13. How do we set priority in a thread?


We can set a thread’s priority using the setPriority(int priority) method, where the
priority ranges from Thread.MIN_PRIORITY (1) to Thread.MAX_PRIORITY (10).

14. Which are the two ways to create a new thread in Java?

o By extending the Thread class.

o By implementing the Runnable interface.

15. run() is used to create a new thread. True or False?


False. The run() method only defines the task of a thread; to create and start a new
thread, we use start().

16. Which states occur in the life cycle of multithreading?

o New

o Runnable

o Running

o Blocked

o Terminated

17. Define Driver


A driver in Java is a software component that enables Java applications to interact
with a database, such as JDBC drivers.

18. What is JDBC?


JDBC (Java Database Connectivity) is an API that allows Java applications to connect
and interact with databases.

19. What is a ResultSet?


A ResultSet is an object that holds the results of an SQL query executed through
JDBC.
20. Define Metadata
Metadata in Java refers to data about data, such as information about a database's
tables, columns, and types, retrieved using DatabaseMetaData.

21. What is the role of the Connection interface?


The Connection interface in JDBC represents a database connection session and
provides methods for executing SQL queries.

22. Which packages are required for Java?


Commonly used packages include:

o java.lang (default package)

o java.util (utility classes)

o java.io (input/output handling)

o java.sql (JDBC API)

o java.net (networking)

23. What is Database Connectivity?


Database connectivity in Java refers to establishing a connection between a Java
application and a database using JDBC.

24. What is a Transaction?


A transaction in Java (JDBC) is a set of SQL operations that are executed as a single
unit. It follows ACID properties (Atomicity, Consistency, Isolation, Durability).

CC

1. List out all phases of the compiler in sequence.

o Lexical Analysis

o Syntax Analysis (Parsing)

o Semantic Analysis

o Intermediate Code Generation

o Code Optimization

o Code Generation

o Symbol Table Management

o Error Handling

2. Define synthesized attribute and inherited attribute.


o Synthesized Attribute: An attribute whose value is derived from its children in
a parse tree.

o Inherited Attribute: An attribute whose value is passed down from its parent
or siblings.

3. Differentiate between top-down parsing and bottom-up parsing.

Feature Top-Down Parsing Bottom-Up Parsing

Direction Starts from root Starts from leaves

Methods Recursive Descent, LL(1) Shift-Reduce, LR(1)

Backtracking May require backtracking No backtracking required

Example Predictive Parsing LR Parser

4. Define left recursion. How can it be eliminated?

o Definition: A grammar rule where a non-terminal appears at the beginning of


its own production.

o Example: A → Aα | β

o Elimination: Convert to right-recursive form:

vbnet

CopyEdit

A → βA'

A' → αA' | ε

5. Construct the DAG (Directed Acyclic Graph) for the expression:

o Expression: b * (a + c) + e * d

o DAG Construction:

css

CopyEdit

/\

* *

/\ /\

b +e d
/\

a c

6. What are the basic and auxiliary tasks of a lexical analyzer?

o Basic Tasks: Tokenization, removing whitespace/comments, and detecting


lexical errors.

o Auxiliary Tasks: Symbol table management, keyword recognition.

7. List the two classes of SDD (Syntax Directed Definition).

o S-attributed SDD: Only synthesized attributes.

o L-attributed SDD: Both synthesized and inherited attributes.

8. List the different types of conflicts in LR parsing.

o Shift-Reduce Conflict

o Reduce-Reduce Conflict

9. What is the output of lexical analysis?

o A sequence of tokens (e.g., IDENTIFIER, NUMBER, OPERATOR).

10. State True or False: Shift-Shift conflict does not occur in an LR Parser.

o True (LR parsers only have Shift-Reduce or Reduce-Reduce conflicts).

11. Define cross-compiler.

o A cross-compiler generates machine code for a platform different from the


compiler's host system.

Q2. Answer the following Questions (Any 2) - [Marks: 10]

1. Write a Recursive Descent Parser (RDP) for the given grammar:

CopyEdit

E → E+T | T

T → T*F | F

F → (E) | id

Recursive Descent Functions:

java
CopyEdit

void E() {

T();

while (lookahead == '+') {

match('+');

T();

void T() {

F();

while (lookahead == '*') {

match('*');

F();

void F() {

if (lookahead == '(') {

match('(');

E();

match(')');

} else if (lookahead == 'id') {

match('id');

} else {

error();

}
2. Check whether the given grammar is SLR(1) or not:

less

CopyEdit

S→A|B

A → aA | b

B → dB | b

o Compute FIRST and FOLLOW sets.

o Construct LR(0) Items and the Parsing Table.

o If there are Shift-Reduce or Reduce-Reduce conflicts, it's not SLR(1).

o This grammar is not SLR(1) because b appears in both A → b and B → b,


leading to a Reduce-Reduce conflict.

3. Eliminate Left Recursion from the following grammar:

less

CopyEdit

S → Aa | b

A → Ac | sd | ε

Solution (Converted to Right-Recursive Form):

vbnet

CopyEdit

S → b | Aa

A → sd A' | ε

A' → c A' | ε

You might also like