This document is a training report submitted by Shubham Saini, student of The Technological Institute of Textile & Sciences, to fulfill requirements for a Bachelor of Technology degree in Information Technology. The report details a 6-week training completed at Gyan Techno Solution in Rohtak, Haryana from June 25 to July 30, 2013. The report includes an introduction to Java, descriptions of projects worked on during the training, and declarations, acknowledgements, and certificates.
This document is a training report submitted by Shubham Saini, student of The Technological Institute of Textile & Sciences, to fulfill requirements for a Bachelor of Technology degree in Information Technology. The report details a 6-week training completed at Gyan Techno Solution in Rohtak, Haryana from June 25 to July 30, 2013. The report includes an introduction to Java, descriptions of projects worked on during the training, and declarations, acknowledgements, and certificates.
This document is a training report submitted by Shubham Saini, student of The Technological Institute of Textile & Sciences, to fulfill requirements for a Bachelor of Technology degree in Information Technology. The report details a 6-week training completed at Gyan Techno Solution in Rohtak, Haryana from June 25 to July 30, 2013. The report includes an introduction to Java, descriptions of projects worked on during the training, and declarations, acknowledgements, and certificates.
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){} }