CC and Java
CC and Java
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.
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.
14. Which are the two ways to create a new thread in Java?
o New
o Runnable
o Running
o Blocked
o Terminated
o java.net (networking)
CC
o Lexical Analysis
o Semantic Analysis
o Code Optimization
o Code Generation
o Error Handling
o Inherited Attribute: An attribute whose value is passed down from its parent
or siblings.
o Example: A → Aα | β
vbnet
CopyEdit
A → βA'
A' → αA' | ε
o Expression: b * (a + c) + e * d
o DAG Construction:
css
CopyEdit
/\
* *
/\ /\
b +e d
/\
a c
o Shift-Reduce Conflict
o Reduce-Reduce Conflict
10. State True or False: Shift-Shift conflict does not occur in an LR Parser.
CopyEdit
E → E+T | T
T → T*F | F
F → (E) | id
java
CopyEdit
void E() {
T();
match('+');
T();
void T() {
F();
match('*');
F();
void F() {
if (lookahead == '(') {
match('(');
E();
match(')');
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
less
CopyEdit
S → Aa | b
A → Ac | sd | ε
vbnet
CopyEdit
S → b | Aa
A → sd A' | ε
A' → c A' | ε