Docsity

Programming in java language, Lecture notes of Java Programming

Toggle sidebar
bg1
MAIT/CSE 1 | P a g e
LAB MANUAL OF
JAVA PROGRAMMING
DEPARTMENT OF COMPUTER SCIENCE &
ENGINEERING
ETCS-357
Maharaja Agrasen Institute of Technology, PSP area,
Sector – 22, Rohini, New Delhi – 110085
(Affiliated to Guru Gobind Singh Indraprastha University,
New Delhi)
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Programming in java language and more Lecture notes Java Programming in PDF only on Docsity!

LAB MANUAL OF

JAVA PROGRAMMING

DEPARTMENT OF COMPUTER SCIENCE &

ENGINEERING

ETCS-

Maharaja Agrasen Institute of Technology, PSP area,

Sector – 22, Rohini, New Delhi – 110085

(Affiliated to Guru Gobind Singh Indraprastha University,

New Delhi)

INDEX OF THE CONTENTS

    1. Introduction to the lab manual
    1. Lab requirements (details of H/W & S/W to be used)
    1. List of experiments
    1. List of Advance programs
    1. Projects to be allotted
    1. Format of lab record to be prepared by the students.
    1. Marking scheme for the practical exam
    • exercises & expected viva questions. 8. Details of the each section of the lab along with the examples,

2. LAB REQUIREMENTS

For Java Programming

J2SDK 1. Java Compatible Web Browser

This Compiler has no special hardware requirements as such. Any System with a minimum 256 MB RAM and any normal processor can use for this lab.

JAVA PROGRAMMING LAB Paper Code: ETCS- Paper: Java Programming Lab

List of Experiments: (As prescribed by G.G.S.I.P.U)

  1. Create a java program to implement stack and queue concept.
  2. Write a java package to show dynamic polymorphism and interfaces.
  3. Write a java program to show multithreaded producer and consumer application.
  4. Create a customized exception and also make use of all the 5 exception keywords.
  5. Convert the content of a given file into the uppercase content of the same file.
  6. Develop an analog clock using applet.
  7. Develop a scientific calculator using swings.
  8. Create an editor like MS-word using swings.
  9. Create a servlet that uses Cookies to store the number of times a user has visited your servlet.
  10. Create a simple java bean having bound and constrained properties.

NOTE:- At least 8 Experiments out of the list must be done in the semester.

  1. Modify experiment 1 to have a constructor in class circle to initialize its variables.
  2. Modify experiment 2 to show constructor overloading.
  3. WAP to display the use of this keyword.
  4. Write a program that can count the number of instances created for the class. Week 4
  5. WAP that implements method overloading.
  6. WAP that shows passing object as parameter.
  7. WAP that illustrates method overriding
  8. Write a program to show that the value of non static variable is not visible to all the instances, and therefore cannot be used to count the number of instances.
  9. WAP to illustrate simple inheritance

Week 5

  1. WAP illustrating a super class variable a referencing as sub class object.
  2. WAP illustrating all uses of super keywords.
  3. Create an abstract class shape. Let rectangle and triangle inherit this shape class. Add necessary functions.
  4. Write an application that creates a package p1. Add some classes in it.
  5. Write an application that uses the package p1 created in the program 21. Week 6
  6. Write an application that creates an ‗interface‘ and implements it.
  7. Write an application to illustrate Interface Inheritance.
  8. Write an application that shows the usage of try, catch, throws and finally.
  9. Write an application that shows how to create a user-defined exception. Week 7
  10. Write an application that executes two threads. One thread displays ―An‖ every 1000 milliseconds and other displays ―B‖ every 3000 milliseconds. Create the threads by extending the Thread class.
  11. Write an application that shows thread synchronization.
  12. Write an application that displays deadlock between threads.
  13. Write an application that shows thread priorities. Week 8
  14. Write an Applet that displays ―Hello World‖ (Background color-black, text color-blue and your name in the status window.)
  15. Write a program that displays the life cycle of an Applet.
  16. Write an Applet displaying line, rectangle, rounded rectangle, filled rectangle, filled rounded rectangle, circle, ellipse, arc, filled arc and polygon, all in different colors
  17. Write an Applet that displays a counter in the middle of applet. Week 9
  18. Write an Applet that displays a counter in the middle of applet. The counter starts from zero and keeps on incrementing after every second.
  19. Write an Applet that draws a dot at a random location in its display area every 200ms. Any existing dots are not erased. Therefore dots accumulate as the applet executes. 40.Write an Applet that illustrates how to process mouse click, enter, exit, press and release events. The background color changes when the mouse is entered, clicked, pressed, released or exited.
  1. Write an Applet that displays your name whenever the mouse is clicked. Week 10
  2. Use adapter classes to write an Applet those changes to cyan while the mouse is being dragged. At all other times the applet should be white.
  3. Use inner classes to write an Applet those changes to cyan while the mouse is being dragged. At all other times the applet should be white.
  4. Use anonymous classes to write an Applet those changes to cyan while the mouse is being dragged. At all other times the applet should be white. Week 11 Q45 Basic File handling program in java with reader/writer. Q46. Write a program that read from a file and write to file. Week 12 Q47. Write RMI based client-server programs. Week 13 Q48. Write programs of database connectivity using JDBC-ODBC drivers.

5. PROJECTS TO BE ALLOTED (Beyond the syllabus prescribed by G.G.S.I.P.U)

Students will be divided into a group of four/five and projects are allotted to those groups. This project is to be submitted at the end of the semester along with a project report by the individual student.

List of projects given to the students is summarized as below:

 Dx Ball Game  Moving ball with Java Script  Checker Board game with Java Script  Digital Image Processing  Library Management System  Global Defender Game  Brick Game  Rapid Roll Game  Tic Tack Toe

Students can select project work of their own choice subject to the permission of concern faculty.

NOTE : The project is to be made in Java Language preferably.

6. FORMAT OF THE LAB RECORD TO BE PREPARED BY THE STUDENTS 1. The front page of the lab record prepared by the students should have a cover page as displayed below.

NAME OF THE LAB Font should be (Size 20‖, italics bold, Times New Roman)

Faculty name Student name Font should be (12‖, Times Roman) Roll No.: Semester: Group: Font should be (12‖, Times Roman)

Maharaja Agrasen Institute of Technology, PSP Area, Sector – 22, Rohini, New Delhi – 110085 Font should be (18‖, Times Roman)

PROJECT DETAILS

1. TITLE :

2. MEMBERS IN THE PROJECT GROUP :

3. PROJECT REPORT ATTACHED :

a) YES b) NO

  1. SOFT COPY SUBMITTED : a) YES b) NO Signature of the lecturer Signature of the student

( ) ( )

  1. Each practical which student is performing in the lab should have the following details : a) Topic Detail b) AIM c) Algorithm d) Source Code e) Output f) Viva questions
  2. Project report should be added at last page.

7. MARKING SCHEME FOR THE PRACTICAL EXAMS

There will be two practical exams in each semester.

 Internal Practical Exam  External Practical Exam

INTERNAL PRACTICAL EXAM

It is taken by the concerned lecturer of the batch.

MARKING SCHEME FOR THIS EXAM IS :

Total Marks: 40

Division of 40 marks is as follows

  1. Regularity: 25  Performing program in each turn of the lab  Attendance of the lab  File
  2. Viva Voice: 10
  3. Project: 5

NOTE: For the regularity, marks are awarded to the student out of 10 for each experiment performed in the lab and at the end the average marks are giving out of 25.

8. DETAILS OF THE EACH SECTION ALONG WITH EXAMPLES, EXERCISES & EXPECTED VIVA QUESTIONS

Java Programming

THIS SECTION COVERS:

1. Console Based Programming

2. OOP’s Based Programming

3. AWT and Event Handling

4. Java DataBase Connectivity (JDBC)

5. Socket Programming and RMI

6. Java Native Interface (JNI)

7. Collection Interface

JAVA PROGRAMMING ENVIRONMENT (AN INTRODUCTION)

Anyone who is learning to program has to choose a programming environment that makes it possible to create and to run programs. Programming environments can be divided into two very different types: integrated development environments and command-line environments. All programming environments for Java require some text editing capability, a Java compiler, and a way to run applets and stand-alone applications. An integrated development environment, or IDE, is a graphical user interface program that integrates all these aspects of programming and probably others (such as a debugger, a visual interface builder, and project management). A command-line environment is just a collection of commands that can be typed in to edit files, compile source code, and run programs.

Command line environment is preferable for beginning programmers. IDEs can simplify the management of large numbers of files in a complex project, but they are themselves complex programs that add another level of complications to the already difficult task of learning the fundamentals of programming.

Java was developed at Sun Microsystems, Inc., and the primary source for information about Java is Sun's Java Web site, http://java.sun.com/. At this site, one can read documentation on-line and you can download documentation and software. The documentation includes the Java API reference and the Java tutorial.

The current version of Java on the Sun site is version 1.4. It is available for the Windows, Linux, and Solaris operating systems. One can download the "J2SE 1.4 SDK." This is the "Java 2 Platform Standard Edition Version 1.4 Software Development Kit." This package includes a Java compiler, a Java virtual machine that can be used to run Java programs, and all the standard Java packages. The JRE is the "Java Runtime Environment." It only includes the parts of the system that are needed to run Java programs. It does not have a compiler.

Text Editors

To use a command-line environment for programming good text editor is needed. A programmer's text editor is a very different thing from a word processor. Most important, it saves work in plain text files and it doesn't insert extra carriage returns beyond the ones you actually type. A good programmer's text editor will do a lot more than this. Here are some features to look for:

 Syntax coloring. Shows comments, strings, keywords, etc., in different colors to make the program easier to read and to help you find certain kinds of errors.  Function menu. A pop-up menu that lists the functions in your source code. Selecting a function from this will take you directly to that function in the code.  Auto-indentation. When you indent one line, the editor will indent following lines to match, since that's what you want more often than not when you are typing a program.  Parenthesis matching. After typing a closing parenthesis the cursor jumps back to the matching parenthesis momentarily so one can see where it is. Alternatively, there might be a command that will highlight all the text between matching parentheses. The same thing works for brackets and braces.  Indent Block and Unindent Block commands. These commands apply to a highlighted block of text. They will insert or remove spaces at the beginning of each line to increase or decrease the indentation level of that block of text. When you make changes in your program, these commands can help you keep the indentation in line with the structure of the program.  Control of tabs. Don‘t use tab characters for indentation. A good editor can be configured to insert multiple space characters when tab key is pressed.

There are many free text editors that have some or all of these features. Jedit ,a programmer's text editor written entirely in Java. It requires Java 1.3 or better. It has many features listed above, and there are plug-ins available to add additional features. Since it is written in pure Java, it can be used on any operating system that supports Java 1.3. In addition to being a nice text editor, it shows what can be done with the Swing GUI. Jedit is free and can be downloaded from http://www.jedit.org.

On Linux, use nedit. It has all the above features, except a function menu. Under Linux, it is likely that nedit is included in distribution, although it may not have been installed by default. It can be downloaded from http://www.nedit.org/ and is available for many UNIX platforms in addition to Linux. Features such as syntax coloring and auto-indentation are not turned on by default. One can configure them in the Options menu. Use the "Save Options" command to make the configuration permanent. Of course, as alternatives to nedit, the Gnome and KDE desktops for Linux have their own text editors.

Using the Java SDK

After installing Sun's Software Development Kit for Java, one can use the commands "javac", "java", and "appletviewer" for compiling and running Java programs and applets. These commands must be on the "path" where the operating system searches for commands.

Make a directory to hold Java programs. Create program with a text editor, or copy the program to be compiled into program directory

If program contains more than a few errors, most of them will scroll out of the window. In Linux and UNIX, a command window usually has a scroll bar that can be used to review the errors. In Windows 2000 to 2010/NT/XP (but not Windows 95/98), one can save the errors in a file which can be viewed later in a text editor.

The command in Windows is

javac SourceFile.java >& errors.txt

The ">& errors.txt" redirects the output from the compiler to the file, instead of to the DOS window. It is possible to compile all the Java files in a directory at one time. Use the command "javac *.java".

After compiled class files are made, run application or applet. For running a stand-alone application -- one that has a main () routine -- use the "java" command from the SDK to run the application. If the class file that contains the main () routine is named Main. class, then run the program with the command: