Akshaya IT Project
Akshaya IT Project
Page 1 of 1
1 ABOUT JAVA 3
2 ABOUT SQL 9
10 CONCLUTION 56
Page 2 of 2
Java is a high-level, class-based, object-oriented programming language
that is designed to have as few implementation dependencies as
possible. It is a general-purpose programming language intended to let
programmers write once, run anywhere (WORA), meaning that compiled
Java code can run on all platforms that support Java without the need
for recompilation. Java is a concurrent, class-based, and object-oriented
language. It is freely accessible, and we can run it on all the platforms or
the operating systems. Java is simple and easy to learn. Java
applications are typically compiled to bytecode that can run on any Java
virtual machine (JVM) regardless of the underlying computer
architecture. The syntax of Java is similar to C and C++, but has fewer
low-level facilities than either of them. The Java runtime provides
dynamic capabilities (such as reflection and runtime code modification)
that are typically not available in traditional compiled languages.
Page 3 of 3
FEATURES:
1. Simple
2. Object-oriented
Objects
Classes
Inheritance
Encapsulation / Data hiding
Abstraction
Polymorphism
Note- Java is not a pure object-oriented language as it allows the use of
primitive data types.
3. Platform-independent
Java programs can run on any machine or the operating system that
does not need any special software installed. Although the JVM needs
to be present in the machine. Java code compiles into bytecode (.class
file), which is platform-independent. We can run this bytecode on
Windows, Linux, Mac OS, etc.
4. Portable
Page 4 of 4
bytecode over to any other platform it runs on.
5. Robust
6. Secure
Java does not support pointers that make Java robust and secure.
All Java programs run inside a virtual machine sandbox.
The Java Runtime Environment (JRE) has a classloader that
dynamically loads the classes into the Java Virtual Machine.
Page 5 of 5
JAVA ARCHITECTURE:
Page 6 of 6
JAVA SUPPORT SYSTEMS:
Internet Connection
Web server
Web Browser
HTML (HyperText Markup Language) which is a language for
creating hypertext for the web.
APPLET tag
Java code
Bytecode
Proxy Server that acts as an intermediate server between the client
workstation and the original server.
Mail Server
Page 7 of 7
extensions for other languages like PHP, C, C++, HTML5, and JavaScript.
Applications based on NetBeans, including the NetBeans IDE, can be
extended by third party developers.
MySQL:
Page 8 of 8
FEATURES:
Easy to use
It is secure
Free to download
It is scalable
Speed
High Flexibility
Page 9 of 9
Allows transactions to be roll-back
Memory efficiency
High Performance
High Productivity
Platform Independent
GUI Support
Operating System
Java SDK or JRE 1.6 or higher
Java Servlet Container (Free Servlet Container available)
Supported Database and library that supports the database
connection with Java.
Page 10 of 10
HARDWARE REQUIREMENTS FOR MYSQL:
CPU: Intel Core or Xeon 3GHz (or Dual Core 2GHz) or equal AMD
CPU
USE OnlineQuiz;
);
question_id INT,
Page 12 of 12
option_text VARCHAR(255) NOT NULL,
);
question_id INT,
);
(1, 'Hyderabad'),
(1, 'Amaravati'),
(1, 'Visakhapatnam'),
(1, 'Vijayawada'),
Page 13 of 13
(2, 'Mumbai'),
(2, 'Pune'),
(2, 'Nagpur'),
(2, 'Thane'),
(3, 'Chennai'),
(3, 'Madurai'),
(3, 'Coimbatore'),
(3, 'Trichy'),
(4, 'Lucknow'),
(4, 'Varanasi'),
(4, 'Agra'),
(4, 'Kanpur'),
(5, 'Kolkata'),
(5, 'Darjeeling'),
(5, 'Siliguri'),
(5, 'Asansol');
Page 14 of 14
1. Questions Table
question_id question_text
1 What is the capital of Andhra Pradesh?
2 What is the capital of Maharashtra?
3 What is the capital of Tamil Nadu?
4 What is the capital of Uttar Pradesh?
5 What is the capital of West Bengal?
Options Table
Page 15 of 15
option_id question_id option_text
20 5 Asansol
3. Answers Table
question_id correct_option
1 2
2 5
3 9
4 13
5 17
import java.sql.*;
import java.util.*;
private static final String USER = "root"; // Change if your MySQL user is
different
int score = 0;
try {
Page 16 of 16
Statement statement = connection.createStatement();
ResultSet questionResultSet =
statement.executeQuery(getQuestionsQuery);
while (questionResultSet.next()) {
System.out.println(questionText);
int optionIndex = 1;
while (optionsResultSet.next()) {
optionIndex++;
ResultSet correctAnswerResultSet =
statement.executeQuery(getCorrectAnswerQuery);
correctAnswerResultSet.next();
Page 17 of 17
int correctOption = correctAnswerResultSet.getInt("correct_option");
if (userAnswer == correctOption) {
System.out.println("Correct!\n");
score++;
} else {
System.out.println("Quiz Over!");
connection.close();
} catch (SQLException e) {
e.printStackTrace();
} finally {
scanner.close();
Page 18 of 18
Sample Output:
...
Quiz Over!
Your final score: 5
Page 19 of 19
Java AND SQL Source Code (Online Quiz Program) This Java program
will ask questions related to historical dates
Page 20 of 20
INSERT INTO Options (question_id, option_text) VALUES
(1, '1912'),
(1, '1914'),
(1, '1916'),
(1, '1918'),
(2, 'George Washington'),
(2, 'Thomas Jefferson'),
(2, 'Abraham Lincoln'),
(2, 'John Adams'),
(3, '1947'),
(3, '1950'),
(3, '1952'),
(3, '1965'),
(4, '1909'),
(4, '1912'),
(4, '1915'),
(4, '1919'),
(5, '1985'),
(5, '1989'),
(5, '1991'),
(5, '1995');
Questions;
question_id question_text
Page 21 of 21
question_id question_text
Empire?
Options Table:
option_id question_id option_text
1 1 1912
2 1 1914
3 1 1916
4 1 1918
5 2 George Washington
6 2 Thomas Jefferson
7 2 Abraham Lincoln
8 2 John Adams
9 3 1947
10 3 1950
11 3 1952
12 3 1965
13 4 1909
14 4 1912
15 4 1915
16 4 1919
17 5 1985
Page 22 of 22
option_id question_id option_text
18 5 1989
19 5 1991
20 5 1995
Answers Table:
question_id correct_option
1 2
2 1
3 1
4 2
5 2
Page 23 of 23
try {
// Establish the database connection
Connection connection = DriverManager.getConnection(URL, USER,
PASSWORD);
Statement statement = connection.createStatement();
while (questionResultSet.next()) {
int questionId = questionResultSet.getInt("question_id");
String questionText = questionResultSet.getString("question_text");
System.out.println(questionText);
System.out.println("Choose the correct option:");
int optionIndex = 1;
while (optionsResultSet.next()) {
String optionText = optionsResultSet.getString("option_text");
System.out.println(optionIndex + ". " + optionText);
optionIndex++;
}
Page 24 of 24
int userAnswer = scanner.nextInt();
Page 25 of 25
Correct!
...
Quiz Over!
Your final score: 5
Page 26 of 26
Table to store options for each question
CREATE TABLE Options (
option_id INT AUTO_INCREMENT PRIMARY KEY,
question_id INT,
option_text VARCHAR(255) NOT NULL,
FOREIGN KEY (question_id) REFERENCES Questions(question_id)
);
Page 27 of 27
(4, 'Kolkata'),
(4, 'Gujarat'),
(4, 'Andhra Pradesh'),
(5, 'Ghevar'),
(5, 'Gulab Jamun'),
(5, 'Rasgulla'),
(5, 'Kachori');
Uestions Table
question_id question_text
1 What is the traditional dish of Punjab?
Which Indian dish is made from fermented rice and black
2
lentils?
3 What is the staple food of Kerala?
4 Which Indian state is famous for its "Pakhala Bhata"?
5 Which is the popular sweet dish of Rajasthan?
2. Options Table
Page 28 of 28
option_id question_id option_text
4 1 Dosa
5 2 Chole Bhature
6 2 Dosa
7 2 Idli and Sambar
8 2 Biryani
9 3 Idli and Sambar
10 3 Pav Bhaji
11 3 Khichdi
12 3 Fish Curry and Rice
13 4 Odisha
14 4 Kolkata
15 4 Gujarat
16 4 Andhra Pradesh
17 5 Ghevar
18 5 Gulab Jamun
19 5 Rasgulla
20 5 Kachori
3. Answers Table
question_id correct_option
1 3
2 7
3 9
4 13
5 17
Page 29 of 29
username
private static final String PASSWORD = "password"; // Update with your
MySQL password
try {
// Establish the database connection
Connection connection = DriverManager.getConnection(URL, USER,
PASSWORD);
Statement statement = connection.createStatement();
while (questionResultSet.next()) {
int questionId = questionResultSet.getInt("question_id");
String questionText = questionResultSet.getString("question_text");
System.out.println(questionText);
System.out.println("Choose the correct option:");
int optionIndex = 1;
while (optionsResultSet.next()) {
String optionText = optionsResultSet.getString("option_text");
System.out.println (optionIndex + ". " + OptionText);
optionIndex++;
}
Page 30 of 30
WHERE question_id = " + questionId;
ResultSet correctAnswerResultSet =
statement.executeQuery(getCorrectAnswerQuery);
correctAnswerResultSet.next();
int correctOption = correctAnswerResultSet.getInt("correct_option");
Page 31 of 31
Which Indian dish is made from fermented rice and black lentils?
Choose the correct option:
1. Chole Bhature
2. Dosa
3. Idli and Sambar
4. Biryani
Enter your answer (1-4): 3
Correct!
...
Quiz Over!
Your final score: 5
Java AND SQL Source Code (Online Quiz Program) This Java program
will ask questions related to continent
sql
Copy code
Create the database for the online quiz
CREATE DATABASE IF NOT EXISTS OnlineQuiz;
Page 32 of 32
option_id INT AUTO_INCREMENT PRIMARY KEY,
question_id INT,
option_text VARCHAR(255) NOT NULL,
FOREIGN KEY (question_id) REFERENCES Questions(question_id)
);
Page 33 of 33
(5, 'Africa'),
(5, 'Europe'),
(5, 'Asia'),
(5, 'North America');
Insert correct answers (option_ids for the correct answers)
INSERT INTO Answers (question_id, correct_option) VALUES
(1, 1), -- Asia is the largest continent by area
(2, 2), -- Africa is known as the "Dark Continent"
(3, 3), -- Australia is located entirely in the Southern Hemisphere
(4, 1), -- Africa is home to the Sahara Desert
(5, 1); -- Africa has the most countries
1. Questions Table
question_id question_text
1 Which is the largest continent by area?
2 Which continent is known as the "Dark Continent"?
Which continent is located entirely in the Southern
3
Hemisphere?
4 Which continent is home to the Sahara Desert?
5 Which continent has the most countries?
2. Options Table
Page 34 of 34
option_id question_id option_text
12 3 Antarctica
13 4 Africa
14 4 Australia
15 4 Asia
16 4 North America
17 5 Africa
18 5 Europe
19 5 Asia
20 5 North America
3. Answers Table
question_id correct_option
1 1
2 2
3 3
4 1
5 1
This Java program will connect to the SQL database and fetch the
questions, options, and correct answers, then display them to the user
for answering and track the score.
java
Copy code
import java.sql.*;
import java.util.*;
Page 35 of 35
MySQL password
try {
// Establish the database connection
Connection connection = DriverManager.getConnection(URL, USER,
PASSWORD);
Statement statement = connection.createStatement();
while (questionResultSet.next()) {
int questionId = questionResultSet.getInt ("question_id");
String questionText = questionResultSet.getString("question_text");
System.out.println(questionText);
System.out.println("Choose the correct option:");
int optionIndex = 1;
while (optionsResultSet.next()) {
String optionText = optionsResultSet.getString("option_text");
System.out.println (optionIndex + ". " + optionText);
optionIndex++;
}
Page 36 of 36
statement.executeQuery(getCorrectAnswerQuery);
correctAnswerResultSet.next();
int correctOption = correctAnswerResultSet.getInt("correct_option");
Sample Output:
Page 37 of 37
Correct!
Page 38 of 38
ONLINE QUIZ SAMPLE 5
Java AND SQL Source Code (Online Quiz Program) This Java program
will ask questions related to stars
Page 39 of 39
('What is the name of the largest star in the Milky Way?'),
('Which star is known as the "Evening Star"?'),
('What type of star is the Sun?'),
('Which star is the brightest in the night sky?');
1. Questions Table
Page 40 of 40
question_id question_text
1 Which star is the closest to Earth?
What is the name of the largest star in the
2
Milky Way?
3 Which star is known as the "Evening Star"?
4 What type of star is the Sun?
5 Which star is the brightest in the night sky?
2. Options Table
3. Answers Table
question_id correct_option
1 1
Page 41 of 41
question_id correct_option
2 2
3 2
4 2
5 1
import java.sql.*;
import java.util.*;
try {
// Establish the database connection
Connection connection = DriverManager.getConnection(URL, USER,
PASSWORD);
Statement statement = connection.createStatement();
Page 42 of 42
statement.executeQuery(getQuestionsQuery);
while (questionResultSet.next()) {
int questionId = questionResultSet.getInt("question_id");
String questionText = questionResultSet.getString("question_text");
System.out.println(questionText);
System.out.println("Choose the correct option:");
int optionIndex = 1;
while (optionsResultSet.next()) {
String optionText = optionsResultSet.getString("option_text");
System.out.println(optionIndex + ". " + optionText);
optionIndex++;
}
Page 43 of 43
}
}
Sample Output:
Page 44 of 44
4. Mercury
Enter your answer (1-4): 2
Correct!
Page 45 of 45
ONLINE QUIZ SAMPLE 6
Java AND SQL Source Code (Online Quiz Program) This Java program
will ask questions related to friendship game
USE OnlineQuiz;
);
question_id INT,
);
Page 46 of 46
CREATE TABLE Answers (
question_id INT,
);
(1, 'Football'),
(1, 'Chess'),
(2, 'Soulmates'),
Page 47 of 47
(3, 'Ron Weasley'),
(3, 'Dumbledore'),
(4, 'Monopoly'),
(4, 'Football'),
(4, 'Basketball'),
(5, 'Kabaddi'),
(5, 'Ludo'),
(5, 'Carrom'),
(5, 'Pictionary');
1. Questions Table
Page 48 of 48
question_id question_text
1 Which of the following is a popular game played by friends?
2 Which phrase signifies strong friendship?
Which character is best known for friendship in Harry
3
Potter?
4 Which friendship game involves a lot of physical activity?
5 Which game is commonly played by friends in India?
2. Options Table
3. Answers Table
question_id correct_option
1 3
2 1
Page 49 of 49
question_id correct_option
3 2
4 3
5 1
import java.sql.*;
import java.util.*;
try {
// Establish the database connection
Connection connection = DriverManager.getConnection(URL, USER,
PASSWORD);
Statement statement = connection.createStatement();
while (questionResultSet.next()) {
int questionId = questionResultSet.getInt("question_id");
String questionText = questionResultSet.getString("question_text");
System.out.println(questionText);
System.out.println("Choose the correct option:");
Page 50 of 50
// Fetch options for the current question
String getOptionsQuery = "SELECT * FROM Options WHERE question_id
= " + questionId;
ResultSet optionsResultSet = statement.executeQuery(getOptionsQuery);
int optionIndex = 1;
while (optionsResultSet.next()) {
String optionText = optionsResultSet.getString("option_text");
System.out.println(optionIndex + ". " + optionText);
optionIndex++;
}
Page 51 of 51
e.printStackTrace();
} finally {
scanner.close();
}
}
}
Sample Output:
markdown
Copy code
Who is known as the greatest chess player of all time?
Choose the correct option:
1. Bobby Fischer
2. Magnus Carlen
3. Garry Kasparov
4. Anatoly Karpov
Enter your answer (1-4): 2
Correct!
Page 52 of 52
Choose the correct option:
1. Checkmate
2. Check
3. Fork
4. Castling
Enter your answer (1-4): 2
Correct!
Quiz Over!
Your final score: 5
Page 53 of 53
Conclusion:
The Online Quiz system developed using Java and SQL has successfully
met its objectives of creating an interactive, user-friendly, and data-
driven quiz platform. By leveraging Java for the user interface and SQL
for managing quiz data, the project offers a seamless user experience
and a scalable solution for administering quizzes.
The project demonstrates how Java and SQL can be integrated to build
dynamic, real-time applications that provide valuable feedback and
improve user engagement. The system is both efficient and scalable,
with the potential for future enhancements such as user authentication,
advanced analytics, and the inclusion of additional quiz features.
The Online Quiz system holds great potential for both educational and
entertainment purposes, offering an effective way to assess knowledge,
engage users, and facilitate learning. Future iterations of the system
could focus on enhancing security, adding more question types, and
integrating additional multimedia elements to create a more engaging
and comprehensive experience.
Page 54 of 54