Introduction of the Project
Are you ready to begin the exciting journey of building your online Exam Management System in Java? Look no further, as we’ve got you covered with our detailed guide.
With the increasing demand for remote learning and online assessments, building an efficient and user-friendly Online Exam Management System has become crucial. Our Java-based solution empowers you to create a system that simplifies exam administration, streamlines student registration, automates grading, and ensures easy implementation.
Whether you’re an experienced Java developer or just starting out, our guide will provide you with step-by-step instructions and practical insights to create a powerful system that meets your unique requirements. To make this Java project more interesting, we will use the Swing module to make the GUI. Also, we will use the SQL database to store information regarding the person who has taken the test, age, email & score in the exam.
So, get ready to dive into the world of online exams with our streamlined and informative guide! Let’s make exam management a breeze with Java!
Objectives
1. To implement the tables that contain the exam-related information and attach the functionality of calculating scores and storing it in the database.
2. To create a user interface with relevant labels to make it easier for the user to interact with this system.
Requirements
The main prerequisites required to build this Online Exam Management System In Java are as follows:
1. Understanding of Java programming language and its concepts, such as object-oriented programming (OOP), exception handling, file handling, and database connectivity
2. Swing module to create the Graphic User Interface.
3. SQL database for managing and storing the information
Source Code
package com.company; public class Main { public static void main(String[] args) { new Exam(); } } package com.company; import javax.swing.*; import java.awt.* public class Exam { private JButton TAKEEXAMButton; private JButton STATUSButton; private JPanel mainPanel; JFrame examF = new JFrame(); public Exam(){ examF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); examF.setContentPane(mainPanel); examF.pack(); examF.setLocationRelativeTo(null); examF.setVisible(true); TAKEEXAMButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { examF.dispose(); new Candidate(); } }); STATUSButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { examF.dispose(); new Status(); } }); } } package com.company; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.* import java.sql.*; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Vector; public class Candidate { private JTextField nameData; private JTextField ageData; private JButton SUBMITButton; private JButton BACKButton; private JPanel studentPanel; private JTextField emailData; private JList list1; JFrame studentF = new JFrame(); public Candidate(){ studentF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); studentF.setContentPane(studentPanel); studentF.pack(); studentF.setLocationRelativeTo(null); studentF.setVisible(true); SUBMITButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if(nameData.getText().equals("")|| ageData.getText().equals("")|| emailData.getText().equals("")){ JOptionPane.showMessageDialog(null,"Please Fill All Fields to take test."); }else{ try { String sql = "insert into exam"+"(Name,Age,Email,Date)"+"values (?,?,?,?)"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy"); Date date = new Date(); statement.setString(1,nameData.getText()); statement.setString(2, ageData.getText()); statement.setString(3, emailData.getText()); statement.setString(4, formatter.format(date)); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"PRESS OK TO CONTINUE"); studentF.dispose(); new Test(nameData.getText(),ageData.getText()); }catch (Exception ex){ System.out.println(ex.getMessage()); } } } }); BACKButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { studentF.dispose(); new Exam(); } }); } } package com.company; import javax.swing.*; import java.awt.* import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; public class Test { private JPanel testPanel; private String name; private String age; private JButton SUBMITTESTButton; private JRadioButton ans1; private JRadioButton ans4; private JRadioButton ans2; private JRadioButton ans3; private JRadioButton ans5; private int counter=0; JFrame testF = new JFrame(); public Test(String name,String age){ this.name = name; this.age = age; testF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); testF.setContentPane(testPanel); testF.pack(); testF.setLocationRelativeTo(null); testF.setVisible(true); SUBMITTESTButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { testF.dispose(); new Exam(); } }); SUBMITTESTButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { String sql = "UPDATE exam " + "SET Score = '"+ score()+"'"+ " WHERE Name= '"+name+"' AND Age= '"+age+"'"; try{ Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); PreparedStatement statement = connection.prepareStatement(sql); statement.executeUpdate(); JOptionPane.showMessageDialog(null,"EXAM SUBMITTED SUCCESSFULLY."); }catch (Exception exception){ JOptionPane.showMessageDialog(null,exception.getMessage()); } testF.dispose(); new Exam(); } }); } public String score(){ if(ans1.isSelected()){ counter+=2; } if(ans2.isSelected()){ counter+=2; } if(ans3.isSelected()){ counter+=2; } if(ans4.isSelected()){ counter+=2; } if(ans5.isSelected()){ counter+=2; } String ans = String.valueOf(counter); ans+="/10"; return ans ; } } package com.company; import javax.swing.*; import javax.swing.table.DefaultTableModel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.*; import java.util.Vector; public class Status { private JPanel statusPanel; private JButton BACKButton; private JTable table1; JFrame statusF = new JFrame(); public Status(){ statusF.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); statusF.setContentPane(statusPanel); statusF.pack(); statusF.setLocationRelativeTo(null); statusF.setVisible(true); tableData(); BACKButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { statusF.dispose(); new Exam(); } }); } public void tableData() { try{ String a= "Select* from exam"; Class.forName("com.mysql.cj.jdbc.Driver"); Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/intern","root","root"); Statement statement = connection.createStatement(); ResultSet rs = statement.executeQuery(a); table1.setModel(buildTableModel(rs)); }catch (Exception ex1){ JOptionPane.showMessageDialog(null,ex1.getMessage()); } } public static DefaultTableModel buildTableModel(ResultSet rs) throws SQLException { ResultSetMetaData metaData = rs.getMetaData(); // names of columns Vector<String> columnNames = new Vector<String>(); int columnCount = metaData.getColumnCount(); for (int column = 1; column <= columnCount; column++) { columnNames.add(metaData.getColumnName(column)); } // data of the table Vector<Vector<Object>> data = new Vector<Vector<Object>>(); while (rs.next()) { Vector<Object> vector = new Vector<Object>(); for (int columnIndex = 1; columnIndex <= columnCount; columnIndex++) { vector.add(rs.getObject(columnIndex)); } data.add(vector); } return new DefaultTableModel(data, columnNames); } }
Explanation of the Code
For you to better understand the code, we have broken it down into two sections. The first one involves creating the GUI, so let us look at the GUI first:
1. Our main screen consists of 2 buttons “Take Exam” for taking the exam & “Status” to check the status.
2. Status panel has a Jtable with columns “Name, Age, Email, Date, and Score” and a Back button.
3. The Candidate panel consists of 3 text fields, “Candidate Name, Age, and Email ID” 2 buttons “Submit and Back”, and a text area to provide the exam info.
4. The Test panel consists of a button and 5 Jlabels for questions, and each question has 4 radio buttons as options for answers.
Moving to the retrieval from the SQL database & updating it according to the user’s input., we will apply the following:
1. First, we built a connection first with the database using the Connection object.
2. Then we Inject the query that stores table data in ResultSet.
3. After that score is calculated by increasing the value of the total by 2 for each correct answer.
4. Next, we update the score to the respective entries in the table from the provided name and age of the candidate.
5. Finally, send data to the Jtable.
Output
Main Interface
Exam Interface
Status Interface
We have successfully built an Online Exam Management System In Java that helps to manage information about the person taking the test, his score, and contact details & helps to take the test. This Java project is a very efficient & easy way to conduct an examination and store the results in the database.

As a passionate Java developer with over 10 years of experience, I live and breathe Java programming. I have a deep understanding of Java core concepts such as object-oriented programming, multithreading, exception handling, and Java collections. I am proficient in using Java libraries, frameworks, and tools and can write clean, efficient, and maintainable Java code. I can design and implement RESTful APIs, work with databases, and integrate with various third-party services.
0 Comments