AOOP
AOOP
all Java technology code? Java Virtual ● What is the output of the given program?
Machine (JVM) Object Oriented Programming hello Enjoy
● What do you call a special language that can Programming in Java
be understood by the Java Virtual Machine
(JVM)? Bytecode
Java
● Which of the following is responsible for
freeing any memory? Garbage Collection public class JavaSample{
thread
● Which of the following is responsible for public static void
loading all classes needed in the Java main(String args[]){
program? Class loader
● What is the output of the given program? String str = "Object
CS002-OOP Oriented Programming";
char
Java arrCh[]={'h','e','l','l','o
'};
public class Hello {
String str2 = new
String name;
String(arrCh);
//Constructor
String str3 = new
Hello(){ String("Enjoy Programming
in Java");
this.name =
"CS002-OOP";
System.out.println(str);
}
System.out.println(ob }
j.name);
● What is the size of double variable? 64 bit ● This is the keyword used for making fields to
● What is the default value of char variable? be available to subclasses. protected
'\u0000' ● Write a Java program to create a class
● Which of the following is true about protected called Animal with a method named move().
access modifier? Variables, methods and Create a subclass called Cheetah that
constructors which are declared protected in overrides the move() method to run.
the superclass can be accessed only by its
child class.
● What is function overriding? Both A and B Java
(If a subclass uses a method that is already class Animal {
provided by its parent class, it is known as
public void move() {
Method Overriding, If a subclass provides a
specific implementation of a method that is
already provided by its parent class, which is System.out.println("This
known as method overriding.) animal moves.");
● Which of the following is a primitive data type }
in Java? Int }
● Which of the following is the smallest
primitive data type in Java? byte
class Cheetah extends
● What character data type cannot store the
following value? 75 Animal {
● What is the output of the following code @Override
snippet? 17Hello public void move() {
System.out.println("The
Java cheetah runs fast!");
}
int x = 7;
}
int y = 10;
public class Main {
System.out.println(x + y +
public static void
"Hello");
main(String[] args) {
new
Animal().move();
new
Quiz 3 Cheetah().move();
((Animal) new
● What type of relationship represents objects Cheetah()).move();
to be associated with one another and able
}
to exist individually? Aggregation
AOOP
Quiz 6
Java
public class Controller extends
JFrame{
● It represents the "Is-a" relationship. private Ball model;
Inheritance private View view;
private JButton btnStep;
public Controller(){
Quiz 5 model = new Ball(1, 1, 1,
1, 10);
● It is the process of reconstructing the object view = new View(model);
a class.
II. Observer is an interface and Observable
is a class. Only statement II is True
model.addObserver(view);
● The part of the application that represents
the presentation of data. View
btnStep.addActionListener(new
● a process in which the current state of the
ActionListener() { Object will be saved in the stream of bytes.
public void Serialization
actionPerformed(ActionEvent ae){ ● The class enables a mechanism that allows
the model to broadcast or notify the target
model.move(view.getWidth(), when changes to itself occur. Observable
view.getHeight()); class
} ● Instead of allowing a specific type, a generic
}); object accept different type of parameter.
} True
} ● A component that does work is needed to
solve the problem- defines the Business
Logic of the application. Model
Java
public<T, S super T> S[] copy(T[]
● These are nameless classes defined inside src, S[] dest){
for(int i=0; i<src.length;
another class. Anonymous Inner Class
i++){
● Which is not an advantage of applying MVC?
dest[i] = src[i];
Serial Development
}
● Which of the following statements are true?
I. Observable is an interface and Observer is
AOOP
● Which generic bound uses extends keyword ● Always mix Model code with GUI code.
and it is the limit that states that the False
accepted type must be a subtype of the ● A Model does the "business logic". True
given class? upperbound
● Which of the following are the uses for
different purpose of byte stream? Send to
Database and DBMS
other platform over network and Write to
A database is a shared, integrated computer structure
disk
that houses:
● Which generic bound uses super keyword
and it is the limit that states that the ● Raw Data
accepted type must be supertype of the ● Metadata
given class? lowerbound
● What is the pair of symbols that enclose a A DBMS or Database Management System is a
type in generics? <> collection of programs that manages the database
● Which of the following is not a limitation of structure and controls access to the data. It allows
generics? Allow type inheritance users to perform the following tasks:
● What is the keyword that limits the generic to
● Data Definition: Helps in the creation,
the subclass of the specified type? extends
modification, and removal of definitions that
● Which of the following is not a required
organize the data in the database.
modifier for serialVersionUUID field? private
● Data Updation: Enables insertion,
● What is the keyword that relates a field to the modification, and deletion of actual data in
class not to the instance? static the database.
● What is the java class that is capable of ● Data Retrieval: Facilitates retrieving data
reading data in byte stream format? from the database for use in applications.
ObjectInputStream ● User Administration: Assists in registering
● What interface is used to mark the class as and monitoring users, enforcing data
available for conversion into byte stream security, monitoring performance,
format? Serializable maintaining data integrity, handling
● Which of the following is not a purpose of concurrency control, and recovering data
using generics? Specification over Type corrupted by unexpected failures.
● What describe the higher -level organization
of solutions to common problems? Design There are many DBMS options to choose from:
Patterns
● MySQL
● What provides for user input and
● MSSQL
modification? Controller
● Oracle DBMS
● The model should not be independent of ● PostgreSQL
both the Controller and the View. False ● MariaDB
● The controller decides what the model is to ● SQLite
do. True ● IBM DB2
● The View should not display what the
Controller thinks is happening. True
AOOP
● Java Applications
Tables ● Java Applets
Most data in a database is stored in tables. ● Java Servlets
● Java Server Pages (JSPs)
A table is a two-dimensional structure composed of ● Enterprise JavaBeans (EJBs)
rows and columns:
);
CREATE Syntax and Examples
Example:
● CREATE DATABASE: Creates a new
sql
database.
Copy code
Syntax:
● DOUBLE: Stores numbers with decimal This command deletes the school database,
parts. including all its objects.
Syntax:
DML
sql
DML manages data stored in the database. Common
Copy code
operations include:
DROP DATABASE database_name;
● SELECT
● INSERT
● UPDATE
Example: ● DELETE
sql
Copy code
○ Each process has its own 1. Applications with distinct tasks that can
address/memory space. be performed independently:
○ The OS's scheduler decides when ○ Any kind of application that requires
each process is executed. such division of tasks.
○ Only one process is actually 2. Applications with a GUI:
executing at any given time, but the ○ Threads dedicated to the GUI can
system appears to be running delegate user requests to other
several programs simultaneously. threads.
● In a multithreaded application: ○ The GUI remains responsive to the
○ There are several points of user while requests are being
execution within the same memory processed.
space. 3. Applications requiring asynchronous
○ Each point of execution is called a response:
thread. ○ Network-based applications:
○ Threads share access to memory. ■ Data can arrive from the
network at any time.
■ In a single-threaded
system, data is queued
Why Use Multithreading? until the thread can read it.
■ In a multithreaded system,
● In a single-threaded application:
a thread can be dedicated
○ One thread of execution must do
to listening for data and
everything.
processing it or delegating
○ Tasks are performed when the
its processing to another
thread can get to them.
thread.
○ A single task requiring a lot of
processing can make the entire
application appear "sluggish" or
unresponsive. How Does It All Work?
● In a multithreaded application:
○ Each task can be performed by a ● Threads have their own "context":
separate thread. ○ Includes virtual registers and their
○ A long process in one thread does own calling stack.
not make the entire application wait ● The scheduler decides which thread
for it to finish. executes:
○ On a system with multiple ○ The VM may use its own scheduler
processors, the OS may execute or the system's scheduler.
separate threads simultaneously on ○ Scheduler maintains a list of ready
separate processors. threads (run queue) and threads
waiting for input (wait queue).
○ Threads have priorities, and the
scheduler typically schedules the
What Kind of Applications Use Multithreading?
AOOP
Synchronization
● Why synchronize?
○ Prevents data corruption when
multiple threads access shared
data.
● How to synchronize:
○ Use the synchronized
keyword for methods or blocks.