Lab Manual Oop Fymca Mgmu 20 21
Lab Manual Oop Fymca Mgmu 20 21
Lab Manual Oop Fymca Mgmu 20 21
Laboratory Manual
For
FY MCA Part-1
Department of MCA
Department of MCA JNEC, MGM University
This manual is intended for the First year students of MCA in the subject of
Object Oriented Programming using JAVA.
This manual typically contains practical/Lab Sessions related JAVA
Programming covering various aspects related the subject to enhanced
understanding.
Students are advised to thoroughly go through this manual rather than only
topics mentioned in the syllabus as practical aspects are the key to
understanding and conceptual visualization of theoretical aspects covered in
the books.
FORWARD
As you may be aware that MGM has already been awarded with ISO 9001-
2015 certification and it is our endure to technically equip our students
taking the advantage of the procedural aspects of ISO 9001-2015
Certification.
Faculty members are also advised that covering these aspects in initial stage
itself, will greatly relieved them in future as much of the load will be taken
care by the enthusiasm energies of the students once they are conceptually
clear.
Principal
Institute Vision
To create self-reliant, continuous learner & competent technocrats imbued with
human values.
=========================================================================================
Institute Mission
Imparting quality technical education to the students through participative
teaching –learning process.
Developing competence amongst the students through academic learning and
practical experimentation.
Inculcating social mindset and human values amongst the students.
=========================================================================================
Department Vision
Build a strong technical teaching and learning environment that responds swiftly
to the challenges and needs of the current industry trends.
=========================================================================================
Department Mission
PROGRAM OUTCOMES
PO No. Program Outcome Description
Engineering knowledge: Apply the knowledge of mathematics, science, engineering
PO 1 fundamentals, and an engineering specialization to the solution of complex engineering
problems.
Problem analysis: Identify, formulate, review research literature, and analyze complex
PO 2 engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.
Design / Development of solution: Design solutions for complex engineering problems and
design system components or processes that meet the specified needs with appropriate
PO 3
consideration for the public health and safety, and the cultural, societal, and environmental
considerations.
Conduct investigation of complex problems: Use research-based knowledge and research
PO 4 methods including design of experiments, analysis and interpretation of data, and synthesis of
the information to provide valid conclusions.
Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
PO 5 engineering and IT tools including prediction and modeling to complex engineering activities
with an understanding of the limitations.
The engineer & society: Apply reasoning informed by the contextual knowledge to assess
PO 6 societal, health, safety, legal and cultural issues and the consequent responsibilities relevant
to the professional engineering practice.
Environment & sustainability: Understand the impact of the professional engineering
PO 7 solutions in societal and environmental contexts, and demonstrate the knowledge of, and
need for sustainable development.
Ethics: Apply ethical principles and commit to professional ethics and responsibilities and
PO 8
norms of the engineering practice.
Individual & team work: Function effectively as an individual, and as a member or leader in
PO 9
diverse teams, and in multidisciplinary settings.
Communication: Communicate effectively on complex engineering activities with the
engineering community and with society at large, such as, being able to comprehend and
PO 10
write effective reports and design documentation, make effective presentations, and give and
receive clear instructions.
Life long learning: Recognize the need for, and have the preparation and ability to engage in
PO 12
independent and life-long learning in the broadest context of technological change.
Lab Outcomes
Write object oriented programs
LO1
LO4 Write an applications that have an event-driven graphical user interface using the
standard Java libraries &access database with JDBC .
SUBJECT INDEX
1. Make entry in the Log Book as soon as you enter the Laboratory.
2. All the students should sit according to their roll numbers starting from
their left to right.
3. All the students are supposed to enter the terminal number in the log
book.
5. All the students are expected to get at least the algorithm of the
program/concept to be implemented.
2. Students should be taught for taking the printouts under the observation of
lab teacher.
Algorithm:
Declare and define a class. Define main method.
Declare variables and initialize variables.
Implement different operators in Java for e.g. Arithmetic, logical,
conditional etc. with the help of variables.
Print all the values of variables, by using basic syntax of Java language.
Output:
Exercises:
1) Write a java program that prints all real solutions to the quadratic
equation ax2+bx+c=0. Read in a, b, c and use the quadratic formula.
2) Write a program for addition of two using command line arguments.
Source code:
import java.util.Scanner;
public class ifdemo
{
public static void main(String args[])
{
int num1, num2, num3;
System.out.println("Enter three integers: ");
Scanner in = new Scanner(System.in);
num1=in.nextInt();
num2=in.nextInt();
num3=in.nextInt();
if (num1 > num2 && num1 > num3)
System.out.println("The largest number is: "+num1);
else if (num2 > num1 && num2 > num3)
System.out.println("The largest number is: "+num2);
else if (num3 > num1 && num3 > num2)
System.out.println("The largest number is: "+num3);
else
System.out.println("The numbers are same.");
}
}
Output:
Exercise:
Source code:
int n = 10, t1 = 0, t2 = 1;
System.out.print("First " + n + " terms: ");
Output:
Exercise:
Problem Stmt: Write a program to make the first letter of a String capital
Source Code:
class string{
public static void main(String[] args) {
// create a string
String name = "mgmuniversity";
String n1=name;
// create two substrings from name
// first substring contains first letter of name
// second substring contains remaining letters
String firstLetter = name.substring(0, 1);
String remainingLetters = name.substring(1, name.length());
}
}
Output:
Exercise:
WAP Program to determine whether a given string is palindrome
WAP to count the total number of vowels and consonants in a string
WAP to perform string operations
Source Code:
public class sort {
public static void main(String[] args) {
//Initialize array
int [] arr = new int [] {5, 2, 8, 7, 1};
int temp = 0;
//Displaying elements of original array
System.out.println("\nElements of original array: ");
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i] + " ");
}
//Sort the array in ascending order
for (int i = 0; i < arr.length; i++) {
for (int j = i+1; j < arr.length; j++) {
if(arr[i] > arr[j]) {
temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
}
System.out.println();
//Displaying elements of array after sorting
System.out.println("\nElements of array sorted in ascending order: ");
Output:
Exercise:
//withdraw method
void withdraw(float amt)
{
if(amount<amt){
System.out.println("Insufficient Balance");
}
else
{
amount=amount-amt;
System.out.println(amt+" withdrawn");
}
}
//method to check the balance of the account
void checkBalance(){System.out.println("Balance is: "+amount);}
//method to display the values of an object
void display(){System.out.println(acc_no+" "+name+" "+amount);}
}
a1.display();
a1.checkBalance();
a1.deposit(40000);
a1.checkBalance();
a1.withdraw(15000);
a1.checkBalance();
}
}
Output:
Exercise:
WAP using class & object for calculating area of circle, area of
rectangle, area of triangle using menu driven
Write a program to create a room class, the attributes of this class is roomno,
roomtype, roomarea and ACmachine. In this class the member functions are
setdata and displaydata.
Output
Exercise:
WAP Program to illustrate the use of static variable (Count ) which is shared
with all objects.
WAP to get the cube of a given number using the static method
WAP to demonstrate use of Static Block
class Myclass
{ public static void main(String[] args)
{
Employee emp = new Employee();
Employee emp2 = new Employee("MGM");
Employee emp3 = new Employee("JNEC", 12234);
}
}
Output:
Exercise:
WAP to illustrated Constructor overloading using This keyword
WAP to illustrated final keyword in constructor
Output:
Exercise:
WAP to illustrate use of hierarchical inheritance
WAP to illustrate use of Hybrid Inheritance
WAP to illustrate use of Super Keyword
Output:
Exercise:
Write a java program to create an abstract class named Shape that contains
two integers and an empty method named print Area (). Provide three classes
named Rectangle, Triangle and Circle such that each one of the classes
extends the class Shape. Each one of the classes contains only the method
print Area () that prints the area of the given shape
Output:
Create an outer class with a function display, again create another class
inside the outer class named inner with a function called display and call the
two functions in the main class.
catch(InterruptedException e)
{System.out.println(e);}
System.out.println(i);
}
}
public static void main(String args[]){
TestSleepMethod1 t1=new
TestSleepMethod1();
TestSleepMethod1 t2=new
TestSleepMethod1();
t1.start();
t2.start();
}
}
Output:
Exercise:
Write a Java program that creates three threads. First thread displays “Good
Morning” every one second, the second thread displays “Hello” every two
seconds and the third thread displays “Welcome” every three seconds.
WAP to illustrate priority of a Thread
WAP to illustrate garbage Collection
Output:
Exercise:
Write a program that creates a user interface to perform integer divisions.
The user enters two numbers in the text fields, Num1 and Num2. The
division of Num1 and Num2 is displayed in the Result field when the
Divide button is clicked. If Num1 or Num2 were not an integer, the program
would throw Number Format Exception. If Num2 were Zero, the program
would throw an Arithmetic Exception Display the exception in a message
dialog box.
WAP to illustrate Finally Block
WAP to illustrate Throws Keyword
//FirstApplet.html
<html>
<body>
<Applet code="FirstApplet.class" width="1000" height="600">
</Applet>
</body>
</html>
Output:
Exercise:
WAP for painting in Applet
WAP ti display image in Applet
}
}
Output:
Exercise:
WAP for digital clock in Applet
WAP for draw Smiley face
//Tes.html
<html>
<head><title>Register</title></head>
<body>
<applet code="Tes.class" width=230 height=300></applet>
</body>
</html>
Output:
Exercise:
WAP to illustrate Mouse Listener Event
WAP to create login form for User
WAP free hand drawing Tool
Write a java program to create an abstract class named Shape that contain an
empty method named numberOfSides(). Provide three classes named
Trapezoid, Triangle and Hexagon such that each one of the classes extends
the class Shape. Each one of the class contains only the method
numberOfSides() that shows the number of sides in the given geometrical
figures.
queue.remove();
queue.poll();
System.out.println("after removing two elements:");
Iterator<String>
itr2=queue.iterator();
while(itr2.hasNext()){
System.out.println(itr2.next());
} } }
Output:
Exercise:
WAP to illustrate use of TreeSet Class
WAp to illustrate HAshMap class
Output:
Exercise:
WAP for string writer
Output:
Exercise:
WAP to store and retrieve student photo and details from DB
WAP to store and retrieve a file from DB
Submission:
Document Standard:
A] Page Size A4-Size
B] Running text Justified text
C] Spacing 1.5 line
D] Page Layout and Margins (Dimensions in Cms)