[go: up one dir, main page]

0% found this document useful (0 votes)
71 views18 pages

Object Oriebted LAB (Manual)

Uploaded by

Alishba Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views18 pages

Object Oriebted LAB (Manual)

Uploaded by

Alishba Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 18

Laboratory Workbook

Object Oriented Programming

Name _____________________
Roll No ____________________
Semester ____________________
Marks ____________________
Signature ____________________

Department of Computer Science


Introduction
Object-oriented programming (OOP) is a programming language model organized around
objects rather than "actions" and data rather than logic. Historically, a program has been viewed
as a logical procedure that takes input data, processes it, and produces output data. Object-
oriented programming takes the view that what are really cared about are the objects that is to be
manipulated rather than the logic required to manipulate them.

The first step in OOP is to identify all the objects the programmer wants to manipulate and how
they relate to each other, known as data modeling. Once an object has been identified, it is
generalized as a class of objects which defines the kind of data it contains and any logic
sequences that can manipulate it.

The building of OOP is based on following four pillars.

1. Abstraction
2. Encapsulation.
3. Inheritance.
4. Polymorphism.

Java
Java is a programming language and a platform based on object-oriented programming concepts.
It was first released by Sun Microsystems in 1995.

There are lots of applications and websites that will not work unless Java is being installed, and
more are created every day. Java is high level, fast, secure, and reliable.

From laptops to datacenters, game consoles to scientific supercomputers, cell phones to the
Internet, Java is everywhere!

Java language will be used throughout this workbook to understand OOP.


Content

Lab
Lab Objective
No.

1 Introduction to Java
2 Java Programming Elements
3 Java Control Statement , Operators & Arrays
4 Introducing Classes ,Objects and Strings in java
5 Overloading and Access Control
6 Introducing UML Diagram
7 Inheritance and Polymorphism in Java
8 Use of abstract and final
9 Packages & Interfaces
10 Introducing JavaFx – Java GUI
11 Exploring JavaFx
12 JavaFx Application
13 Exception Handling
14 Generics and Collection
15 Serialization
Lab Details
Marks
Lab No. Lab Objective Signature
Obtained

Introduction to Java
1 Objective: Getting familiar with the Java development kit (JDK).
Running your first Java program using CMD and an IDE.
Student Feedback:

Java Programming Elements


2 Objective:Learning Input/Output handling on Java console.
Understanding variables using primitive and non-primitive data types.
Exploring Java’s built in classes.
Student Feedback:

Java Control Statement , Operators & Arrays


Objective: Understanding the control statements of Java including
3 Loops & if-else. Exploring different operators used in Java and Arrays,
array index, single and multi-dimensional arrays, traversing the array
using loop.
Student Feedback:

Introducing Classes ,Objects & Strings


4 Objective: Understanding concepts of class and object in java.
Implementing a class with members including data, methods and
constructors Also getting familiar with Strings
Student Feedback:

Overloading & Access Control


Objective: Understanding concepts method and constructor
5
overloading. Learn how to provide different access controls on class
members.
Student Feedback:
6 Introducing UML diagram
Objective: Understand the basics of class diagram of UML.

Student Feedback:

Inheritance and Polymorphism in Java


7 Objective: Understanding the concept of inheritance, the superclass
and subclass
Student Feedback:

Use of abstract and final


8 Objective: Understand the abstract method & class and final method
and class.
Student Feedback:

Packages & Interfaces


9
Objective: Understanding the concept packages & interfaces of Java.

Student Feedback:

Introducing JavaFx– Java GUI


Objective: Understand the design principles of graphical user interfaces
(GUIs) using layout managers to arrange GUI components.
10
Understand basic component of JavaFx and their interaction used in
different program of Java, such as Label, Button, Text Box, Combo
Box etc.
Student Feedback:
Exploring JavaFx
12
Objective: Show different JavaFxLayouts and Charts.

Student Feedback:

12 JavaFx Application
Objective: Design a Login page using JavaFx components
Student Feedback:

Exception Handling
13
Objective: Understand how runtime errors are being handled in Java.
Student Feedback:

Collection and Generics


14 Objective: Understand generics and collections in java using
ArrayList , LinkedList and sets
Student Feedback:

Serilization
Objective: File Processing & I/O operations, ObjectInputStream,
15
ObjectOutputStream, Serializable interface, Serializing & Deserializing an
Object
Student Feedback:

Note: Students are advised to write their comments about whether the objective of the lab was achieved in
Student Feedback.
Introduction to Java Lab 1
Objective: Getting familiar with the Java development kit (JDK). Running your first Java program using
CMD and an IDE.

Theory:
What is JDK?
It's the full featured Software Development Kit for Java, including JRE, and the compilers and tools (like Java
Debugger) to create and compile programs.
JRE is required to run Java programs while JDK is required when you have to do some Java programming.

Installing JDK for Windows


1. Download the JDK from Oracle’s website. Choose the right JDK depending upon your system’s
specifications.

Figure 1.1: Download the JDK from Oracle’s website

2. Run the .exe file on your System and follow the steps as given by the installer.
Figure 1.2 Installing JDK

3. Note down the location where j2se has been installed. Java Platform is also called as J2SE (Java 2
Platform Standard Edition)

4. Following screen will appear after successful installation.

Figure 1.3: Successful installation


5. Post installation, you will need to set some environment variables in windows.
6. The path is required to be set for using tools such as javac, java etc.If you are saving the java source
file inside the jdk/bin directory, path is not required to be set because all the tools will be available in
the current directory.But If you are having your java file outside the jdk/bin folder, it is necessary to
set path of JDK.

Setting Java Path

There are 2 ways to set java path:


1. temporary
2. permanent

1. How to set Temporary Path of JDK in Windows

To set the temporary path of JDK, you need to follow following steps:

 Open command prompt


 Copy the path of jdk/bin directory
 Write in command prompt: set path=copied_path
For Example:
set path=C:\Program Files\Java\jdk1.6.0_23\bin

Let's see it in the figure given below:

Figure 1.4: Command Prompt

2. How to set Permanent Path of JDK in Windows

For setting the permanent path of JDK, you need to follow these steps:
 Go to
MyComputer properties -> advanced tab -> environment variables -> new tab of user variable ->
write path in variable name -> write path of bin folder in variable value -> ok -> ok -> ok

Figure 1.5: Advance System Settings - Windows

 Click on environment variables

Figure 1.6: Set Environment Variables


 Select Path variable and click on Edit button.

Figure 1.7: Set Path Variable

 Copy the path of the bin folder of the JDK and paste it in the variable value field of the path
variable. So add ";C:\Program Files\Java\jdk1.7.0_02\bin" in the path string.

Figure 1.8: Edit System Variable

 Click OK... to finish.


 Now your permanent path is set. You can now execute any program of java from any drive.

Note:
The PATH environment variable is a series of directories separated by semicolons (;) and is notcase-
sensitive. Microsoft Windows looks for programs in the PATH directories in order, from left to right.
The new path takes effect in each new command window you open after setting the PATH variable.
Lab Task:

Write a simple program in java, compile and run it using cmd.

1. Open notepad and type the content.

public class HelloWorld {  

public static void main(String args[]){  
System.out.println(“Hello World!!”);
}  
}

2. Save it as HelloWorld.java. Naming is strictly case-sensitive; make sure you type as it is given above.
3. Now open a command prompt and change to the directory where you have saved HelloWorld.java
4. Enter SET CLASSPATH.
5. Press enter; this sets the classloader path to search for class files in the current directory.
6. Type the command javac to compile your code. If the compilation is successful, you would not be
shown any errors.
javac HelloWorld.java
Type the command java HelloWorld and press enter. Please note that you did not include any
extension such as .java or .class to the class name you wish to run.
javaHelloWorld
7. You would get nice output greeting “Hello World!!”

What is an IDE?

An integrated development environment (IDE) is a software application that provides comprehensive


facilities to computer programmers for software development. An IDE mayconsist of a source code editor;
build automation tools,compiler and a debugger.

There are different IDE’s used for Java development including NetBeans and Eclipse.

Before starting to develop the complex programs, you need an IDE. In this workbook we will be using
Eclipse IDE for code writing, compilation and execution.

Install Eclipse IDE


Download Eclipse form its official website and install it on your system by following the instruction provided
by the installer.

Figure 1.9: Download Eclipse IDE

After installation, open eclipse. You will see the welcome screen.

Figure 1.10: Welcome Screen of Eclipse

Write a simple program in java, compile and run it using IDE.

 Create new project in eclipse. Click on file menu, select Project, then select Java Project and click
Next. You will see the following screen. Give your project a name and click Finish.
Figure 1.11: Creating new project in Eclipse

 Now right click on your project available in project explorer and create new class.
Figure 1.12: Add new Class

 A window similar to one shown below will appear. Enter the class name and check the checkbox for
public static void main (String[] args). Click finish.

Figure 1.13: Creating new Class

 A java file will open with some added code. Just add the following line inside the main()
method.System.out.println("Hello World!!");
Figure 1.14: Adding Java Code

 Save the file.


 Now compile and execute this code. In Eclipse compilation and Execution performs by clicking the
button highlighted in the image below.

Figure 1.15: compile& Execute

 The output of this code will be generated in the console window present below.
Figure 1.16: Console Output

Lab Assignment:
1. Write a simple java program with command-line argument in java that prints your bio data
including:
name, father name, roll number i.d, department, subject, date, zodiac.

public class Biodata {  

public static void main(String args[]){  
System.out.println(“My name is Miss Javeria, Barkat,3456, computer science,
oop lab, 14th july, caprocorn”);
}  
}

You might also like