Vous êtes sur la page 1sur 61

GYAN TECHNO SOLUTION

601B, ADARSH NAGAR, NEAR AJAY GARMENT,


ROHTAK, HARYANA

A TRAINING REPORT
ON
CORE JAVA

SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS
FOR THE AWARD OF THE DEGREE OF

BACHELOR OF TECHNOLOGY
(Information Technology)

SUBMITTED TO
MAHARSHI DAYANAND UNIVERSITY, ROHTAK

SUBMITTED BY
Name of Student: User-ID:
SHUBHAM SAINI 11IT055


025-06-13 to 30-07-13













THE TECHNOLOGICAL INSTITUTE OF TEXTILE & SCIENCES,
BHIWANI, HARYANA.



DECLARATION

I SHUBHAM SAINI bearing Roll No: 11IT055, a bonafide student of The Technological
Institute of Textile & Sciences, would like to declare that the project titled Report on Core-
Java.
A partial fulfillment of BY BACHELOR OF TECHNOLOGY Degree course of MDU
UNIVERSITY is my original work in the year 2013 under the guidance of Mrs. Satvika
Assistant Professor of the Department of Information Technology.




DATE: NAME:
ROLL NO: 11IT055 SHUBHAM SAINI
PLACE:





















ACKNOWLEDGEMENT

I would like to express my gratitude to all those who gave me helping hand in completion this
term paper. I want to thank my teacher Raj Kumar Sharma for helping me whenever I needed it
the most. My friends have also supported me in my work. I want to thank them all for their
help, support, interest and valuable hints.

I am extremely thankful to Asstt. Prof, Dr.Mukesh Sharma HOD, Computer Science & IT, The
Technological Institute of Textile & Sciences, Bhiwani for valuable suggestions and
encouragement .


Signature of Student
SHUBHAM SAINI
























CERTIFICATE

I hereby certify that I have completed the Six weeks Trainingin partial fulfilment of the
requirements for the award of Bachelor of Technology in Information Technology. I did my
training in Gyan Techno Solution at Rohtak, Haryana from 25-06-13 to 30-07-13.

The matter presented in this Report has not been submitted by me for the award of any
other degree elsewhere.
Signature of Student
SHUBHAM SAINI (11IT055)

Signatures
Examined by: (Concerned Faculty)





HOD Department of Computer Engineering & Information Technology

TABLE OF CONTENTS
1. Introduction
1.1 What is JAVA
1.2 Versions of JAVA
1.3 The Birth Of Modern Programming
1.4 Creation of Java
1.5 About Java
1.6 Features of Java
1.7 Java Architecture
1.8 A Simple Java Application
1.9 Java Data Types
1.10 Operators in Java
1.11 Javas Selection Statements
1.12 Inheritance
1.13 Exception Handing
1.14 Multithreading
1.15 Applets
1.16 Garbage Collector
1.17 Constructors

2 Project Work
2.1 Technology Use
2.2 Java Platform
2.3 Introduction to Project
2.4 General Description
2.5 Functional Requirements


1. INTRODUCTION TO JAVA
1.1 What is Java?
Java is a computer programming language that is concurrent, class-based, object-oriented, and
specifically designed to have as few implementation dependencies as possible. It is intended to
let application developers "write once, run anywhere" (WORA), meaning that code that runs on
one platform does not need to be recompiled to run on another. Java applications are
typically compiled to bytecode (class file) that can run on any Java virtual machine (JVM)
regardless of computer architecture.
JAVA is related to C++, which is a direct
descendant of C. Much of the character of java is
inherited from these two languages. From C,java
derives its syntax.Many of javas object oriented
features were influenced by C++.In fact,several of
javas defining characteristics come from or is
responses toits predecessors.Moreover the creation
of java was deeply rooted in the process of
refinement and adaption.
1.2 Versions of Java
JDK Alpha and Beta(1995)
JDK 1.0(1996)
JDK 1.1(1997)
J2SE 1.2(1998)
J2SE 1.3(2000)
J2SE 1.4(2002)
J2SE 5.0(2004)
J2SE(2006)
JAVA SE 7(2011)
1.3 The Birth of Modern Programming:
1.3.1 C: The creation of C was a direct result of the need for a structured, efficient,high-level
language that could replace assembly code when creating system programs. As you probably
know when a computer language is designed, trade-offs are often made, such as the following:
Ease of use versus power
Safety versus efficiency
Rigidity versus extensibility
1.3.2 C++: The Next Step
Since C is a successful and useful programming language, you might ask why need for
something else existed. The answer is Complexity. Throughout the history of programming,the
increasing complexity of programs has driven the need for better ways to manage that
complexity. C++ is a response to that need. C++ has a features of OOPS.OOP is programming
methodology that helps organize complex programs through the use of ---
Inheritance
Encapsulation
Polymorphism

1.4 CREATION OF JAVA
Java was conceived by James Gosling, Patrick Naughton, Chris Warth and Mike Sheridan at
Sun Microsystems Inc in 1991. It took 18 months to develop the first working version. This
language is initially called Oak, but was renamed java in 1995. The primary motivation
was the need for a platform-independent (that is,architecture neutral) language that could be
used to create software to be embedded in various customer electronic devices,such as
microwave ovens and remote controls.
The problem is that compilers are expensive and time consuming to create. So Gosling
and others began work on portable, platform independent language that is used to
produce code that would run on a variety of CPUs under differing environments. This
effort led to the creation of java.
Second and ultimately more important, factor was emerging that would play a crucial
role the World Wide Web. Had the Web not taken shape at about the same time that
java was being implemented; java might have remained a useful but obscure language
for programming consumer electronics. However, with the emergence of the World
Wide Web, java was propelled to the forefront of computer language design because the
Web, too, demanded portable programs.


1.5 ABOUT JAVA:
Java technology is both a programming language and a platform.In the Java programming
language, all source code is first written in plain text files ending with the .java extension.
Those source files are then compiled into .class files by the javac compiler. A .class file does
not contain code that is native to your processor; it instead contains bytecodes the machine
language of the Java Virtual Machine1 (Java VM). The java launcher tool then runs your
application with an instance of the Java Virtual Machine.




Fig. 1

The JAVA Platform: A platform is the hardware or software environment in which a program
runs. The Java platform differs from most other platforms in that it's a software-only platform
that runs on top of other hardware-based platforms.
The Java platform has two components:

The Java Virtual Machine.
The Java Application Programming Interface (API).

The general-purpose, high-level Java programming language is a powerful software platform.
Every full implementation of the Java platform gives you the following features:
Development Tools: The development tools provide everything you'll need for
compiling, running, monitoring, debugging, and documenting your applications. As a
new developer, the main tools you'll be using are the javac compiler, the java launcher,
and the javadoc documentation tool.
Application Programming Interface (API): The API provides the core functionality
of the Java programming language. It offers a wide array of useful classes ready for use
in your own applications. It spans everything from basic objects, to networking and
security.
User Interface Toolkits: The Swing and Java 2D toolkits make it possible to create
sophisticated Graphical User Interfaces (GUIs).
Class Thread: A thread is a thread of execution in a program. The Java Virtual
Machine allows an application to have multiple threads of execution running
concurrently. Every thread has a priority. Threads with higher priority are executed in
preference to threads with lower priority.

1.6 FEATURES OF JAVA:
Object oriented: This means that it takes into consideration real world entities.
Cross platform language: It means that program can run across several platforms-
Microsoft Windows, AppleMacintosh, Linux etc. The language automatically uses
pointers behind the scenes for complex types, and no pointer specific syntax is
required.All objects are referenced by pointers--but the language handles them, not the
programmer.
Simple: It was designed to be easy for the professional programmer to learn and use
efficiently.
Secure: In java, Applets provide security feature. In order to enable applets to be
downloaded and executed on the client computer safely, it was necessary to prevent an
applet from launching such an attack.
Portable: Same code executes on all computers. This feature is provided by java.
Object-oriented: java provides all OOPS features i.e. Inheritance, Polymorphism.
Everything is an object in java. The focus therefore is on data and methods that operate
on the objects in the application
Robust: The ability to create robust programs was given a high priority in the design of
java.
Multithreaded: Java supports multithreaded programming, which allows you to write
programs that do many things simultaneously.
Architecture-neutral: Their goal was write once; run anywhere, anytime, forever.
Interpreted: Java creates cross platform programs. This code can be executed on any
system that implements the java virtual machine.
High performance: This cross platform code directly translates native machine code
for very high performance.
Distributed: It is designed for distributed systems because it handles TCP/IP protocols
and also supports Remote method invocation (RMI).
Dynamic: It is used to verify and resolved accesses to objects at run time. This makes it
possible to dynamically link code in a safe and expedient manner.
Platform Independent: It refers to the ability of the program to move from one
computer to another without difficulty i.e. it can run over any operating system. Java is
platform independent at source level and binary level. Platform Independence at source
level allows user to move the source code from one system to another, compile the code
and run it clearly on a system.Platform Independence at binary level allows user to run
compiled binary file on multiple platform without recompiling the code.
1.7 JAVA ARCHITECTURE:
Java is Object-Oriented--that means everything in the language behaves like an object.
Javas Architecture comes from four separate but intertwined technologies:
The Java Programming Language.
The Java class file format.
The Java API, or Application Programming Interface.
The Java Virtual Machine.
Source programs are written in the Java Programming Language.
All procedural code falls within methods.
Programs are compiled into Java class files.
Classes run in the Java Virtual Machine.
When a Java program runs, it is assisted by other classes in the Java the
Application Programming Interface, or API.
A JVM has an interpreter component that enables communication between java
bytecode and a computers operating system.
By using JVM java code can be run on any platform.
A JVM reads and executes java statements one at a time.
The java compiler is responsible for turning java source code into java bytecode that
can be executed within the java runtime system.
The JVM which is a component of runtime system is responsible for interpreting the
bytecode and making the native code out of it.
JVM may include JIT ( just in time) compiler in it which converts bytecode into native
code without making use of interpreter.
If JIT is not present the bytecode classes will be processed and executed by the runtime
interpreter.
The Virtual Machine interprets the bytecode one instruction at a time, and
translates it into native machine code.
You compile your program once into bytecode, but it is interpreted anew every
time it runs.
C and C++ are famous for speed.
One reason they are fast is because C and C++ dont do things like checking the
bounds of arrays.
In C or C++, a program can walk off the edge of an array and invade the
memory space beyond.
Hackers love that about C and C++.
Another weakness of C/C++, that is a favourite among Hackers, is the Buffer
Overflow.
In this attack, the Hacker floods too much data into a buffer and whatever
overflows it is turned loose on the system.
Java solves these problems.
How Java Combats malicious code:
Java checks array boundaries.
Java halts Buffer Overflows.
Java has Garbage collection to get rid of objects that are no longer used.
Javas compiler checks to make sure the code is safe before it run.
1.8A Simple Java Application
The TestGreeting.java Application
// Sample "Hello World" application
public class TestGreeting {
public static void main (String [] args) {
Greeting hello = new Greeting ();
hello.greet();
}
}

The Greeting.java Class
public class Greeting {
public void greet()
{
System.out.println(hi);
}
}


1.8.1 Compiling and Running the TestGreeting Program
Compile TestGreeting.java:
javac TestGreeting.java
The Greeting.java is compiled automatically.
Run the application by using the following command:
java TestGreeting
Locate common compile and runtime errors.

1.9 JAVA DATA TYPES:
Integers
Table 1
Character
Floating point
Table 2

Boolean
true
false
1.10 OPERATORS IN JAVA:
Arithmetic Operators
Arithmetic operators are used in mathematical expressions in the same way that they are used
in algebra. The following table lists the arithmetic operators:










Table 3
The Bitwise Operators
Java defines several bitwise operators that can be applied to the integer types, long, int, short,
char, and byte. These operators act upon the individual bits of their operands. They are
Summarized in the following table:
Table 4
Relational Operators
The relational operators determine the relationship that one operand has to the
other.Specifically, they determine equality and ordering. The relational operators are shown
here:

Table 5
Boolean Logical Operators
The Boolean logical operators shown here operate only on Booleanoperands. All of the
Binary logical operators combine two Booleanvalues to form a resultant Booleanvalue.
Table 6
Table 7



1.11 Javas Selection Statements:
if
if else
if else if else ladder
switch
nested switch
Iterations
for
while
do-while
1.12INHERITENCE:
Inheritance is one of the cornerstones of object-oriented programming because it allowsthe
creation of hierarchical classifications. Using inheritance, you can create a generalclass that
defines traits common to a set of related items. This class can then be inheritedby other, more
specific classes, each adding those things that are unique to it. In the terminologyof Java, a
class that is inherited is called a superclass. The class that does the inheriting is
calledasubclass. Therefore, a subclass is a specialized version of a superclass. It inherits all of
theinstance variables and methods defined by the superclass and add its own, unique elements.

1.13 EXCEPTION HANDLING:
Exceptions are the run-time errors which can be handled in java applications and do not
result in abnormal termination.
Exception handling is a structured mechanism of handling runtime exception in the java
application.
Purpose of exception handling is to avoid abnormal termination of the program.
1.14 MULTITHREADEDING:
Unlike many other computer languages, Java provides built-in support for
multithreadedprogramming.
A multithreaded program contains two or more parts that can runconcurrently.
Each part of such a program is called a thread, and each thread definesa separate
path of execution. Thus, multithreading is a specialized form of multitasking.
You are almost certainly acquainted with multitasking, because it is supported
by virtuallyall modern operating systems.
There are two distinct types of multitasking: processbasedand thread-based.
1.15 APPLETS:
Appletsare small applications that are accessed on an Internet server, transported over the
Internet, automatically installed, and run as part of a web document. After an applet arrives on
the client, it has limited access to resources so that it can produce a graphical user interface and
run complex computations without introducing the risk of viruses or breaching data integrity.

1.16 GARBAGE COLLECTOR:
The JVM automatically re-collects the memory which is not referred to by other objects. The
java garbage collector checks all object references and find the objects which can be
automatically released.
While the garbage collector releases the programmer from the need to explicitly manage
memory the programmer still need to ensure that he does not keep unneeded object references
otherwise the garbage collector cannot release the associated memory. Keeping unneeded
object references are typically called memory leaks.

1.17 CONSTRUCTORS:
In object-oriented programming, a constructor (sometimes shortened to ctor) in a class is a
special type of subroutine called to create an object. It prepares the new object for use, often
accepting arguments that the constructor uses to set member variables required.
A constructor resembles an instance method, but it differs from a method in that it has no
explicit return type, it is not implicitly inherited and it usually has different rules for scope
modifiers. Constructors often have the same name as the declaring class. They have the task
of initializing the object's data members and of establishing the invariant of the class, failing if
the invariant is invalid. A properly written constructor leaves the resulting object in
a valid state. Immutable objects must be initialized in a constructor.

2. PROJECT
2.1 TECHNOLOGY USED:
The strength of any project depends upon the technology on which the project is based. Today
we are living in a world where technologies related to information technology are evolving
every day, new technologies are taking an edge over the older ones. Every new technology
provides some new benefits, but only small part of them remains in the competitive world.
JAVA is the latest technology, which is in use nowadays and has proved to be the most reliable
development framework.
2.2 JAVA Platform
A platform is the hardware or software environment in which a program runs. The Java
platform differs from most other platforms in that it's a software-only platform that runs on top
of other hardware-based platforms.
The Java platform has two components:

The Java Virtual Machine.
The Java Application Programming Interface (API).

The general-purpose, high-level Java programming language is a powerful software platform.
Every full implementation of the Java platform gives you the following features:

Development Tools: The development tools provide everything you'll need for
compiling, running, monitoring, debugging, and documenting your applications. As a
new developer, the main tools you'll be using are the javac compiler, the java launcher,
and the javadoc documentation tool.
Application Programming Interface (API): The API provides the core functionality
of the Java programming language. It offers a wide array of useful classes ready for use
in your own applications. It spans everything from basic objects, to networking and
security.
User Interface Toolkits: The Swing and Java 2D toolkits make it possible to create
sophisticated Graphical User Interfaces (GUIs).
Class Thread: A thread is a thread of execution in a program. The Java Virtual
Machine allows an application to have multiple threads of execution running
concurrently. Every thread has a priority. Threads with higher priority are executed in
preference to threads with lower priority.
STUDENT MANAGEMENT SYSTEM
1. A Student Management System with the following functions:
* Add class Set metadata for a new class.
* Add Record To add student record.
* Show Record To view Records.
* Modify Record To modify student records. .
2. Used Button for the numbers and functions.
3. Used TextField for the displaying.
4. Used JFrame for the component.
5. Created a class to respond to the events caused by numbers, functions, exit.
6. Used FlowLayout to layout various components in the Calculator Frame.
A FlowLayout out a container, arranging and resizing its components to fit in according to
there occurrences for addition in frame.
7. import statements are used to import different packages ad classes.
8.comments are used to explain the functions of statements.
9.jdk 1.7 kit is used.
10. The calculator will respond to both mouse and keyboard events.
2.3 Introduction to Project
Calculator is basically designed for providing an effective and easy interface for the
calculation.
It is designed here at a very basic level and in such a way it has scope for expansion as
per the requirements.
Its simplicity does not affect its security at all.
Calculaor has been built in JAVA which itself is a platform independent language
which further adds to Project being universal.

Scope and Objective
The main objective of the application is to have quick calculations.
The project can be used in calculating at various levels.
Software used
JDK(Java Development Kit) 1.7

JRE(Java Run Time Environment) 6.0

Command Prompt

2.4 General Description

Product Description:
This software is aimed toward evey person who needs the calculation or teacher and the
students of the organization,computations regarding the results of the students according to
their internal exams. It should be user-friendly, quick to learn and reliable software for the
above purpose.
This is intended to be a stand-alone product and should not depend on the availability of other
software but the back-end database file already provided with the package. It should run on
both UNIX and Windows based platform.
The product aims at the following objectives
Smooth flow of data without any hurdles.
Flexibility in the system according to the changing environment.
Accuracy, timeliness and comprehensiveness of the system output.
Stability and operability by people of average intelligence.
Enhancement in the completion of work within the constraints of time.

Product Functions
Checking the correct input.
Generating the result.
Displaying the print panel.
Calculating the result according to the input.

2.5 Functional Requirement

Input
Initially, the interface takes as input as numbers.
Operation to be performed is selected.

Processing
The inputs are processed and the operation is applied.

Output
Result gets displayed.

//Java Application to create a Student Management System
#CODING:
Login Window
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class Login extends Central implements ActionListener ,KeyListener
{
private static Login ob = null;
private JFrame frame = new JFrame("Application");
private JTextField user;
private JPasswordField pass;
private JLabel us = new JLabel("Username");
private JLabel pa = new JLabel("Password");
private JButton submit = new JButton("Submit");
private JLabel log = new JLabel(" Login Credentials ");
private JButton exit = new JButton("Exit");
int flag=0;
Login()
{
user = new JTextField(20);
pass = new JPasswordField(20);
frame.setLayout(new FlowLayout());
frame.getContentPane().setBackground(new Color(200,222,255));
//frame.setVisible(true);
frame.setLocation(533,250);
frame.add(log);
frame.add(us); frame.add(user);
frame.add(pa); frame.add(pass);
frame.add(submit);
frame.add(exit);
frame.setSize(307,239);
user.grabFocus();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
submit.addActionListener(this); submit.addKeyListener(this);
exit.addActionListener(this); exit.addKeyListener(this);
user.addKeyListener(this); submit.setEnabled(false);
pass.addKeyListener(this);
}
public static Login getLogin()
{
if(ob==null)
{
ob = new Login();
}
return ob;
}
public JFrame getFrame()
{
return frame;
}
public static void main(String args[])
{
new Login();
}
public void submit()
{
if(user.getText().equals(""))
{
JOptionPane.showMessageDialog(null,"Username field is mandatory");
return;
}
if(String.valueOf(pass.getPassword()).equals(""))
{
JOptionPane.showMessageDialog(null,"Password field is mandatory");
return;
}
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
Connection conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","backroom");
Statement stmt = conn.createStatement();
ResultSet resultSet = null;
ResultSetMetaData metaData = null;
String s1 = user.getText();
String s2 = String.valueOf(pass.getPassword());
String str = "select * from Auth where NAME='"+s1+"' and
Pass='"+s2+"'";
resultSet = stmt.executeQuery(str);
if(resultSet.next())
{
frame.dispose();
//First first = new First();
initFirst();
}
else
{
JOptionPane.showMessageDialog(null,"Incorrect Username or
Password. Please try again!");
user.setText("");
pass.setText("");
user.grabFocus();
}
}
catch(ClassNotFoundException ee){}
catch(SQLException eee){}
}

public void actionPerformed(ActionEvent e)
{
JButton btn = (JButton)e.getSource();
if(btn == submit)
{
submit();
}
else if( btn == exit)
{
System.exit(0);
}
}
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode() == 10)
{
Object focus = (Object) frame.getFocusOwner();
if(focus instanceof JTextField)
{
submit.grabFocus();
submit();

}
else if(focus instanceof JButton)
{
if(submit.isFocusOwner() == true)
{
submit();
}
else if( exit.isFocusOwner() == true)
{
System.exit(0);
}
}
}
else
{
if(e.getSource() instanceof JPasswordField)
{
if(!(user.getText().equals("")))
{
submit.setEnabled(true);
}
}
else if(e.getSource() instanceof JTextField)
{
if(!(String.valueOf(pass.getPassword()).equals("")))
{
submit.setEnabled(true);
}
}
}
}
public void keyReleased(KeyEvent e)
{
}
public void keyTyped(KeyEvent e)
{

}
}

Main Window
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Permanent implements ActionListener, KeyListener
{
private JFrame frame = new JFrame();
private JButton addClass = new JButton("Add Class");
private JButton addRecord = new JButton("Add Record");
private JButton showRecord = new JButton("Show Record");
private JButton exit = new JButton("Exit");
private ImageIcon img = new
ImageIcon("C:\\Users\\Shubham\\Desktop\\Project\\teacher.jpg");
private static Permanent ob = null;
Permanent()
{
frame.setLocation(400,150);
frame.setSize(355,475);
frame.setLayout(new FlowLayout());
frame.add(new JLabel(img));
frame.add(addClass);
frame.add(addRecord);
frame.add(showRecord);
frame.add(exit);
addClass.addActionListener(this); addClass.addKeyListener(this);
addRecord.addActionListener(this); addRecord.addKeyListener(this);
showRecord.addActionListener(this); showRecord.addKeyListener(this);
exit.addActionListener(this); exit.addKeyListener(this);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static Permanent getPermanent()
{
if(ob==null)
{
ob = new Permanent();
}
return ob;
}
public JFrame getFrame()
{
return frame;
}
public static void main(String args[])
{
Permanent.getPermanent().getFrame().setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
JButton btn = (JButton)e.getSource();
if(btn == addClass)
{
First.getFirst().getFrame().setVisible(true);
}
else if(btn == addRecord)
{
AddRecord.getAddRecord().getFrame().setVisible(true);
}
else if(btn == showRecord)
{
RecordSearch.getRecordSearch().getFrame().setVisible(true);
}
else if (btn == exit)
{
System.exit(0);
}
}
public void keyTyped(KeyEvent e)
{
}
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==10)
{
if(addClass.isFocusOwner())
{
First.getFirst().getFrame().setVisible(true);
}
else if(addRecord.isFocusOwner())
{
AddRecord.getAddRecord().getFrame().setVisible(true);
}
else if(showRecord.isFocusOwner())
{
RecordSearch.getRecordSearch().getFrame().setVisible(true);
}
else if(exit.isFocusOwner())
{
System.exit(0);
}
}
}
public void keyReleased(KeyEvent e)
{
}
}
Add Record(Window 1)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class AddRecord implements ActionListener,KeyListener,ItemListener
{
private JFrame frame = new JFrame("Add Record");
private static AddRecord ob = null;
private JComboBox jcb1 = new JComboBox();
private JComboBox jcb2 = new JComboBox();
private JComboBox jcb3 = new JComboBox();
private Connection conn;
private Statement stmt;
private JButton cont = new JButton("Continue");
AddRecord()
{
try
{
ResultSet resultSet = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","backroom");
stmt = conn.createStatement();
}catch(Exception e){e.printStackTrace();}
frame.setLocation(533,250);
frame.setLayout(new FlowLayout());
frame.setSize(400,400);
getSubjects();
frame.add(new JLabel("
"));
frame.add(new JLabel("Enter/Select Subject "));
frame.add(jcb1);
frame.add(new JLabel("
"));
frame.add(new JLabel("Enter/Select Branch"));
frame.add(jcb2);
frame.add(new JLabel("
"));
frame.add(new JLabel("Enter/Select Semester"));
frame.add(jcb3);
frame.add(new JLabel("
"));
frame.add(cont);
frame.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
cont.addActionListener(this); cont.addKeyListener(this);
jcb1.addItemListener(this); jcb2.addItemListener(this);
jcb1.grabFocus();
}
public void getSubjects()
{
try
{
ResultSet resultSet = null;
String str = "select distinct subject from subject";
resultSet = stmt.executeQuery(str);
while(resultSet.next())
{
jcb1.addItem((String.valueOf(resultSet.getObject(1))).trim());
}
str = "select distinct branch from subject";
resultSet = stmt.executeQuery(str);
while(resultSet.next())
{
jcb2.addItem((String.valueOf(resultSet.getObject(1))).trim());
}
str = "select distinct semester from subject";
resultSet = stmt.executeQuery(str);
while(resultSet.next())
{
jcb3.addItem((String.valueOf(resultSet.getObject(1))).trim());
}
func();

frame.repaint();
frame.validate();
}catch(Exception e){e.printStackTrace();}
}
public static AddRecord getAddRecord()
{
if(ob==null)
{
ob = new AddRecord();
}
return ob;
}
public String getSubject()
{
return String.valueOf(jcb1.getSelectedItem());
}
public String getBranch()
{
return String.valueOf(jcb2.getSelectedItem());
}
public String getSemester()
{
return String.valueOf(jcb3.getSelectedItem());
}
public static void main(String args[])
{
AddRecord.getAddRecord().getFrame().setVisible(true);;
}
public JFrame getFrame()
{
return frame;
}
public void submit()
{
frame.setVisible(false);
RecordEntry.getRecordEntry().getFrame().setVisible(true);
}
public void itemStateChanged(ItemEvent e)
{
JComboBox j = (JComboBox)e.getSource();
if( j == jcb1)
{
func();
}
}
public void func()
{
try
{
int flag=0;
ResultSet resultSet = null;
String s1 = (String.valueOf(jcb1.getSelectedItem()).toUpperCase());
String str ="select distinct branch,semester from subject where
subject='"+s1+"'";
resultSet = stmt.executeQuery(str);
while(resultSet.next())
{
if(flag==0)
{
jcb2.removeAllItems();
jcb3.removeAllItems();
flag=1;
}
jcb2.addItem((String.valueOf(resultSet.getObject(1))).trim());
jcb3.addItem((String.valueOf(resultSet.getObject(2))).trim());
}
}catch(Exception ee){ee.printStackTrace();}
}
public void actionPerformed(ActionEvent e)
{
JButton btn = (JButton) e.getSource();
if(btn == cont)
{
submit();
}
}
public void keyTyped(KeyEvent e)
{
}
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==10)
{
if(cont.isFocusOwner())
{
submit();
}
}
}
public void keyReleased(KeyEvent e)
{
}
}
Record Entry (Window 2)
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class RecordEntry implements ActionListener , KeyListener
{
int f = 0;
private static RecordEntry ob = null;
private JFrame frame = new JFrame("Enter Student Record");
private JLabel lb[] = new JLabel[11];
private JTextField tf[] = new JTextField[11];
private int counter = 0;
private JButton save = new JButton("Save");
private JButton cancel = new JButton("Cancel");
private JButton reset = new JButton("Reset");
private Connection conn;
private Statement stmt;
public static RecordEntry getRecordEntry()
{
if(ob==null)
{
ob= new RecordEntry();
}
return ob;
}
public Frame getFrame()
{
return frame;
}
public RecordEntry()
{
try
{
ResultSet resultSet = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","backroom");
stmt = conn.createStatement();
}catch(Exception e){e.printStackTrace();}
frame.setLayout(new FlowLayout());
frame.setSize(650,400);
frame.setLocation(533,250);
frame.add(new JLabel(" Student Record Entry Form
"));
frame.add(new JLabel("
"));
frame.add(lb[0] = new JLabel("Name "));
frame.add(tf[0] = new JTextField(20));
frame.add(new JLabel(" "));
frame.add(lb[1] = new JLabel("Roll Number"));
frame.add(tf[1] = new JTextField(20));
frame.add(lb[2] = new JLabel("Subject"));
//getCombo();
frame.add(tf[2] = new JTextField(20));
tf[2].setText(AddRecord.getAddRecord().getSubject());
frame.add(lb[3] = new JLabel(" Branch"));
frame.add(tf[3] = new JTextField(20));
tf[3].setText(AddRecord.getAddRecord().getBranch());
frame.add(new JLabel("
"));
frame.add(new JLabel(" "));
frame.add(new JLabel(" "));
frame.add(lb[6] = new JLabel("Semester"));
frame.add(tf[6] = new JTextField(20));
tf[6].setText(AddRecord.getAddRecord().getSemester());
frame.add(new JLabel(" "));
frame.add(new JLabel(" "));
tf[2].setEditable(false);
tf[3].setEditable(false);
tf[6].setEditable(false);
lb[4] = new JLabel("Attendance");
tf[4] = new JTextField(20);
lb[5] = new JLabel("ClassPerformance");
tf[5] = new JTextField(20);
addMarks();
tf[3]= new JTextField(20);
tf[2]= new JTextField(20);
tf[6]= new JTextField(20);
save.addActionListener(this);
cancel.addActionListener(this);
reset.addActionListener(this);
save.addKeyListener(this); cancel.addKeyListener(this);
reset.addKeyListener(this);
tf[0].grabFocus();
}
public void addMarks()
{
for(int i=0 ; i < getCount(); i++)
{
frame.add(lb[i+7] = new JLabel("Marks Periodical" + (i+1)));
frame.add(tf[i+7] = new JTextField(20));
if(i!=3)
{
frame.add(new JLabel("
"));
}
else
{
frame.add(new JLabel(" "));
frame.add(new JLabel(" "));
frame.add(new JLabel(" "));
}
}
frame.add(new JLabel("
"));
frame.add(new JLabel(" "));
frame.add(lb[4]);
frame.add(tf[4]);
frame.add(new JLabel(" "));
frame.add(lb[5]);
frame.add(tf[5]);
frame.add(new JLabel(" "));
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(save); frame.add(cancel); frame.add(reset);

}
public int getCount()
{
String s1 = AddRecord.getAddRecord().getSubject();
String s2 = AddRecord.getAddRecord().getBranch();

String str = "select np from subject where subject='"+s1+"' and
branch='"+s2+"'";
int res = 0;
try
{
ResultSet resultSet = null;
resultSet = stmt.executeQuery(str);
if(resultSet.next())
{
res = Integer.parseInt(String.valueOf(resultSet.getObject(1)));
}
}catch(Exception e){e.printStackTrace();}
return res;
}
public static void main(String args[])
{
RecordEntry.getRecordEntry().getFrame().setVisible(true);
}
public void submit()
{
try
{
int flag=0;
String s1 =
(String.valueOf(AddRecord.getAddRecord().getSubject())).replaceAll(" ","");
int arr[] = getMarks();
ResultSet resultSet = null;
String str = "create table "+s1+" (name char(30),roll char(30),branch char(30),
sem char(30),subject char(30),np int, m1 int,m2 int,m3 int,m4 int,atten int,cp int)";
stmt.executeUpdate(str);
handle();
}
catch(Exception e)
{
handle();
}

}
public void handle()
{
try
{
String s1 =
(String.valueOf(AddRecord.getAddRecord().getSubject())).replaceAll(" ","");
int arr[] = getMarks();
String str = "select * from "+s1+"";
ResultSet resultSet = stmt.executeQuery(str);
if( resultSet.next())
{
str = "select *from "+s1+" where roll='"+getRoll()+"'";
resultSet = stmt.executeQuery(str);
String getBranch =
(String.valueOf(AddRecord.getAddRecord().getBranch()));
String getSemester =
(String.valueOf(AddRecord.getAddRecord().getSemester()));
String getSubject =
(String.valueOf(AddRecord.getAddRecord().getSubject()));
if(!resultSet.next())
{
String exe = "insert into "+s1+"
values('"+getName()+"','"+getRoll()+"','"+getBranch+"',"+getSemester+",'"+getSubject+"','"+g
etCount()+"',0,0,0,0,0,0)";
stmt.executeUpdate(exe);
System.out.println(arr.length);
for(int i=1 ; i<=arr.length; i++)
{
String ex1 = "update "+s1+" set m"+i+"="+arr[i-
1]+" where roll='"+getRoll()+"'";
stmt.executeUpdate(ex1);
}
exe = "update "+s1+" set atten='"+getAtten()+"',
cp='"+getClassPerf()+"' where roll='"+getRoll()+"'";
stmt.executeUpdate(exe);
}
}
else
{
JOptionPane.showMessageDialog(null,"Roll No Already
exists");
}
}catch(Exception e){e.printStackTrace();}
}
public void actionPerformed(ActionEvent e)
{
JButton btn = (JButton) e.getSource();
if(btn == save)
{
submit();
}
else if(btn == cancel)
{
frame.dispose();
}
else if(btn == reset)
{
for(int i=0; i<7;i++)
{
tf[i].setText("");
}
for(int i=0;i<getCount();i++)
{
tf[i+7].setText("");
}
}
}
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==10)
{
if(save.isFocusOwner())
{
submit();
}
else if(cancel.isFocusOwner())
{
frame.dispose();
}
else if(reset.isFocusOwner())
{
for(int i=0; i< 7;i++)
{
tf[i].setText("");
}
for(int i=0;i<getCount();i++)
{
tf[i+7].setText("");
}
}
}
}
public String getName()
{
return tf[0].getText();
}
public String getRoll()
{
return (tf[1].getText().toUpperCase());
}
public String getBranch()
{
return tf[3].getText();
}
public String getSem()
{
return tf[6].getText();
}
public int getAtten()
{
return Integer.parseInt(tf[4].getText());
}
public int getClassPerf()
{
return Integer.parseInt(tf[5].getText());
}
public String getSubject()
{
return tf[2].getText();
}
public int[] getMarks()
{
int arr[] = new int[getCount()];
for(int i =0;i<arr.length;i++)
{
arr[i] = Integer.parseInt(tf[7+i].getText());
}
return arr;
}

public void keyReleased(KeyEvent e)
{}
public void keyTyped(KeyEvent e)
{}
}


RecordSearch
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
public class RecordSearch implements KeyListener, ActionListener
{
private JFrame frame = new JFrame("Search Student Record");
private static RecordSearch ob = null;
private JLabel lb[] = new JLabel[11];
private JTextField tf[] = new JTextField[11];
private JComboBox jcb = new JComboBox();
private JTextField tt = new JTextField(20);
private Connection conn;
private Statement stmt;
String s1,branch,re;
private int flag=0;
int f=0;
private JButton modify = new JButton("Modify");
private JButton exit = new JButton("Exit");
public RecordSearch()
{
try
{
ResultSet resultSet = null;
Class.forName("oracle.jdbc.driver.OracleDriver");
conn =
DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","backroom");
stmt = conn.createStatement();
}catch(Exception e){e.printStackTrace();}
frame.setVisible(true);
frame.setLocation(533,250);
frame.setSize(640,430);
forJCB();
frame.setLayout(new FlowLayout());
frame.add(new JLabel(" Record Search
Form "));
frame.add(new JLabel("
"));
frame.add(jcb);
frame.add(new JLabel("Enter Roll Number/ Name of Student"));
frame.add(tt);
frame.add(new JLabel(" "));
jcb.grabFocus();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
tt.addKeyListener(this);
}
public void forJCB()
{
String str ="select distinct subject from subject";
ResultSet resultSet = null;
try
{
resultSet = stmt.executeQuery(str);
while(resultSet.next())
{
jcb.addItem((String.valueOf(resultSet.getObject(1))).trim());
}
}
catch(Exception e){e.printStackTrace();}
}
public void reBuild()
{
frame.add(lb[0] = new JLabel("Name "));
frame.add(tf[0] = new JTextField(20));
frame.add(new JLabel(" "));
frame.add(lb[1] = new JLabel("Roll Number"));
frame.add(tf[1] = new JTextField(20));
frame.add(lb[2] = new JLabel("Branch"));
frame.add(tf[2] = new JTextField(20));
frame.add(lb[3] = new JLabel(" Semester"));
frame.add(tf[3] = new JTextField(20));
frame.add(new JLabel("
"));
frame.add(new JLabel(" "));
frame.add(lb[6] = new JLabel("Subject"));
frame.add(tf[6] = new JTextField(20));
frame.add(new JLabel(" "));
lb[4] = new JLabel("Attendance");
tf[4] = new JTextField(20);
lb[5] = new JLabel("ClassPerformance");
tf[5] = new JTextField(20);
for(int i=0 ; i < 4; i++)
{
frame.add(lb[i+7] = new JLabel("Marks Periodical" + (i+1)));
frame.add(tf[i+7] = new JTextField(20));
if(i!=3)
{
frame.add(new JLabel("
"));
}
else
{
frame.add(new JLabel(" "));
frame.add(new JLabel(" "));
frame.add(new JLabel(" "));
}
}
frame.add(new JLabel("
"));
frame.add(new JLabel(" "));
frame.add(lb[4]);
frame.add(tf[4]);
frame.add(new JLabel(" "));
frame.add(lb[5]);
frame.add(tf[5]);
for(int i=0 ; i<11 ; i++)
{
tf[i].setEditable(false);
}
frame.add(new JLabel(" "));
frame.add(modify);
frame.add(exit);
modify.addActionListener(this); modify.addKeyListener(this);
exit.addActionListener(this); exit.addKeyListener(this);
frame.repaint();
frame.validate();
sub();
}
public int getCount()
{
String s1 = (getSubject().toUpperCase());
String str = "select np from subject where subject='"+s1+"'";
int res = 0;
try
{
ResultSet resultSet = null;
resultSet = stmt.executeQuery(str);
if(resultSet.next())
{
res = Integer.parseInt(String.valueOf(resultSet.getObject(1)));
}
}catch(Exception e){e.printStackTrace();}
return res;
}
public void sub()
{
String sub = (String.valueOf(jcb.getSelectedItem()).replaceAll(" ",""));
ResultSet resultSet = null;
String str = "select * from "+sub+" where roll='"+getRoll()+"'";
try
{
resultSet = stmt.executeQuery(str);
if(resultSet.next())
{
String sr[] = new String[12];
for(int i=0;i<12;i++)
{
sr[i]=(String.valueOf(resultSet.getObject(i+1))).trim();
}
for(int i=0;i<4;i++)
{
tf[i].setText(sr[i]);
}
tf[4].setText(sr[10]);
tf[5].setText(sr[11]);
tf[6].setText(sr[4]);
int i=0;
for(i=0;i<getCount();i++)
{
tf[i+7].setText(sr[i+6]);
}
for(;i<4;i++)
{
tf[i+7].setText("-");
}
}
}catch(Exception ee){ee.printStackTrace();}
}
public void keyPressed(KeyEvent e)
{
if(e.getKeyCode()==10)
{
if(tt.isFocusOwner() && tt.getText()!="")
{
if(f==0)
{
f=1;
reBuild();
}
else
{
sub();
}
}
else if(exit.isFocusOwner())
{
frame.setVisible(false);
}
else if(modify.isFocusOwner())
{
if(modify.getText().equals("Modify"))
{
for(int i=0 ; i<11 ; i++)
{
tf[i].setEditable(true);
}
tf[0].grabFocus();
modify.setText("Save");
}
else if(modify.getText().equals("Save"))
{
submit();
for(int i=0 ; i<11 ; i++)
{
tf[i].setEditable(false);
}
modify.setText("Modify");
}
}
}
}
public void submit()
{
try
{
String s1 = (String.valueOf(jcb.getSelectedItem()).replaceAll(" ",""));
int arr[] = getMarks();
String str = "select * from "+s1+"";
ResultSet resultSet = stmt.executeQuery(str);
if( resultSet.next())
{
str = "select *from "+s1+" where roll='"+getRoll()+"'";
resultSet = stmt.executeQuery(str);
if( resultSet.next())
{
String exe = "update "+s1+" set
name='"+getName()+"',roll='"+getRoll()+"',branch='"+getBranch()+"',sem="+getSemester()+",
subject='"+getSubject()+"',np='"+getCount()+"' where roll='"+getRoll()+"'";
stmt.executeUpdate(exe);
for(int i=1 ; i<=arr.length; i++)
{
String ex1 = "update "+s1+" set m"+i+"="+arr[i-
1]+" where roll='"+getRoll()+"'";
stmt.executeUpdate(ex1);
}
exe = "update "+s1+" set atten='"+getAtten()+"',
cp='"+getClassPerf()+"' where roll='"+getRoll()+"'";
stmt.executeUpdate(exe);
}
}
else
{
JOptionPane.showMessageDialog(null,"Roll No Already
exists");
}
}catch(Exception e){e.printStackTrace();}
}
public void actionPerformed(ActionEvent e)
{
JButton btn = (JButton)e.getSource();
if(btn==exit)
{
frame.setVisible(false);
}
else if(btn== modify)
{
if(modify.getText().equals("Modify"))
{
for(int i=0 ; i<11 ; i++)
{
tf[i].setEditable(true);
}
tf[0].grabFocus();
modify.setText("Save");
}
else if(modify.getText().equals("Save"));
{
submit();
for(int i=0 ; i<11 ; i++)
{
tf[i].setEditable(false);
}
modify.setText("Modify");
}
}
}
}




COMPILATION:

Fig 2
RUNNING:

Fig 3

OUTPUTS:


Fig 4


Fig 5

Fig 6
Add Class STEP 1:

Fig 7
STEP 2:

Fig 8
STEP 3:

Fig 9
Step 4:

Fig 10
Record Entry:

Fig 11

Fig 12


Fig 13


Record Search

Fig 14

Fig 15

Fig 16












Refrences

THE COMPLETE REFERENCE JAVA SEVENTH EDITION
BY:-HERBERT SCHILDT
JAVA HOW TO PROGRAM
BY:-DEITEL AND DEITEL
Websites
WWW. W3SCHOOL. COM

WWW.JAVATUTORIAL.COM

Vous aimerez peut-être aussi