Elective - Introduction To Java Programming - Learning Guide
Elective - Introduction To Java Programming - Learning Guide
Contents
Program Overview........................................................................................................................ 3
Learning Objectives ..................................................................................................................... 3
Software and Hardware Requirements ........................................................................................ 3
Week-wise Learning Plan ............................................................................................................. 4
Week 1 - Introduction to Computer Basics & Software Engineering Fundamentals .................. 4
1.1 Topics and Duration ........................................................................................................ 4
1.2 Learning Reference ......................................................................................................... 6
1.3 Hands-On ......................................................................................................................... 7
Week 2 - Software Engineering Fundamentals & OOP................................................................ 8
2.1 Topics & Duration ............................................................................................................ 8
2.2 Learning Reference ......................................................................................................... 9
2.3 Hands-On ........................................................................................................................10
Week 3 - OOP & HTML, CSS and JavaScript ..............................................................................11
3.1 Topics and Duration .......................................................................................................11
3.2 Learning Reference ........................................................................................................11
3.3 Hands-On ........................................................................................................................12
Week 4 - HTML, CSS and JavaScript ..........................................................................................15
4.1 Topics and Duration .......................................................................................................15
4.2 Learning Reference ........................................................................................................15
4.3 Hands-On ........................................................................................................................16
Week 5 - HTML, CSS and JavaScript ..........................................................................................18
5.1 Topics and Duration .......................................................................................................18
5.2 Learning Reference ........................................................................................................19
5.3 Hands-On ........................................................................................................................21
Week 6 - HTML, CSS and JavaScript & RDBMS Concepts and SQL..........................................25
6.1 Topics and Duration .......................................................................................................25
6.2 Learning Reference ........................................................................................................26
6.3 Hands-On ........................................................................................................................27
Week 7 - RDBMS Concepts and SQL ..........................................................................................31
Page 2
Program Overview
Introduction of the collaboratively designed elective will significantly help the CS-IT & Non-CS-IT
students to be industry aligned and leverage IT as a competitive edge in their career while working in
their own discipline or specialization
Learning Objectives
RAM 8 GB
Note: The software suggested above are free and can be downloaded from Internet.
WEEK 10
WEEK 11
WEEK 12
WEEK 13
WEEK 14
WEEK 15
WEEK 1
WEEK 2
WEEK 3
WEEK 4
WEEK 5
WEEK 6
WEEK 7
WEEK 8
WEEK 9
RDBMS
Introduction to HTML, Concepts and
Softw are
Computer OOP & CSS, and SQL
Engineering HTML, CSS, RDBMS Introduction to Programming
Basics & HTML, JavaScript
Fundamentals and Concepts & Introduction
Softw are
&
CSS, and
JavaScript
& RDBMS
and SQL to Java
Engineering JavaScript Concepts Programming
OOP
Fundamentals and SQL
Java
Learning Practice
Topics Sub-Topics
Duration Duration
Introduction to Computer Basics
Computer, Hardware, CPU,
Introduction to Computer Monitor, Keyboard/mouse, Memory
30
Basics - RAM, Storage, Software, OS,
Application, Saving a file, Files and
Page 5
folders
Home and Office Networks,
Networking Types and Structures,
Wired vs Wireless Networks,
Basics of Network Networking Topologies, 30
Networking Topology- Physical vs
Logical, Peer to Peer, Client
Server, Network Size
Network Addressing, Classes of
Networking Levels and IPv4, Public and Private IP
30
Layers and Protocols Addresses, What is a Protocol?
What is a Protocol Suite?
IP protocol, DHCP (Dynamic Host
Protocol Stacks,
configuration Protocol), DNS
Networking and Internet 30
(domain Name Service), General
Service
Networking Physical Component
Software Engineering Fundamentals
Software Requirement,
Overview of Requirement Problem Recognition, Evaluation 120
Analysis and Synthesis, Modeling,
Specification, Review
Structured Programming,
Overview of Software
Functional Programming, 90
Implementation
Programming style, Software
Documentation, Software
Implementation Challenges
Link# 3
https://www.pcmag.com/encyclopedia/term/storage-vs-
memory
Link# 1
Objectives of Software Design, https://www.geeksforgeeks.org/introduction-of-software-
Software Design Concepts, Different design-process-set-2/
levels of Software Design, Software
Design Process, Architectural Link# 2
Design https://www.geeksforgeeks.org/software-engineering-
software-design-process/
Link# 3
https://www.geeksforgeeks.org/software-engineering-
architectural-design/
1.3 Hands-On
N/A
Page 8
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Page 9
Abstraction, Encapsulation
Link# 1
Page 10
https://www.c-sharpcorner.com/blogs/encapsulation-vs-
abstraction
2.3 Hands-On
Objectives
180 Minutes
Create a Java class called Ban kAcco u nt which represents a bank account,
having as attributes: acco untNumber (numeric type), n ame (name of the
account owner as string type), balance.
Create a co n str uctor with parameters: acco un tNumber , n ame , b alance.
Create a d e p o sit() method which manages the deposit actions.
Create a with d r awal() me th od which manages withdrawals actions.
Create a b an kF ees() method to apply the bank fees with a percentage of
5% of the balance account.
Create a d isp lay() method to display account details.
Give the complete code for the Ban kAcco u nt class.
Page 11
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Link# 1
Inheritance, Polymorphism
https://www.guru99.com/c-sharp-inheritance-polymorphism.html
Link# 1
World Wide Web, IoT, Web https://www.w3schools.com/whatis/
Programming, Web
Framework, HTML, CSS and Link# 2
JavaScript https://internetofthingsagenda.techtarget.com/definition/Internet-
of-Things-IoT
3.3 Hands-On
Objectives
After completing these exercises, you will be able to:
Work with class inheritance in Java program
Implement the polymorphic characteristics of an object
60 Minutes
Create a Java class Person with attributes: name and age of type string.
Create a display() method that displays the name and age of an object created via the
Person class.
Page 13
Create a child class Student which inherits from the Person class and which also has
a section attribute.
Create a method displayStudent() that displays the name, age and section of an object
created via the Student class.
Create a student object via an instantiation on the Student class and then test the
displayStudent method.
Objectives
120 Minutes
Problem Description:
Create a website with the following information and structure using HTML5:
Use these tags: <header>, <nav>, <aside>, <article>, <section>, <time>, <footer>.
Here logo image, news, announcements used can be any suitable data
Note:
-City is drop down list with multiple city names
-Name, mobile number, address are mandatory fields. If any of these field is empty, after clicking
submit button, it should show like this.
Page 15
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Link# 4
https://www.tutorialrepublic.com/html-reference/html5-event-
attributes.php
Link# 5
https://www.w3schools.com/tags/tag_iframe.ASP
Link# 1
What is CSS, Why use CSS, https://www.w3schools.com/css/css_intro.asp
Inline Style, CSS Style Tags,
Linking to CSS, Style Link# 2
Override Precedence https://www.w3docs.com/snippets/css/how-to-override-css-
styles.html
4.3 Hands-On
Objectives
Page 17
180 Minutes
Prerequisites
Problem Description:
Problem Description:
Sample Output:
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Link# 3
https://javascript.info/variables
Link# 4
https://javascript.info/comments
5.3 Hands-On
Objectives
180 Minutes
Prerequisites
Problem Description:
Problem Description:
For this Application, use the existing application TelephoneComplaint.html created in folder
Telephone under section 4.3
Modify the HTML page to include the below validations in JavaScript
1. Subscriber Name is required and should have max length of 10.
2. validate Email to have @ and. symbol.
3. Registered Mobile number should be 10 digits
Detailed Complaint Description box should be disabled initially, and when user chooses Other
option in Nature of Complaint, Description box should get enabled and get disabl ed when a
subscriber changes the Nature Of Complaint to something else. (Disconnection Problem/Phone
Dead).
Hint: Use onchange event and write JS Code in function enableDisableTextBox(this) to
enable/disable description box. This refers to the option currently selected
Complaint raised date should be current date and shouldn’t be changed, it should be readyonly
and the date should be populated as soon as the form loads in browser.
Hint: write code in JS function getDate() to load current date.
Invoke this function using window.onload.
Open the application in browser or in LiveServer with URL as
http://127.0.0.1:5500/TelephoneComplaint.html
Page 23
Problem Description:
Zip codes consist of 5 consecutive digits. Given a string, write a JavaScript function
isValid(zipCode) to determine whether the input is a valid zip code.
A valid zip code is as follows:
Must only contain numbers (no non-digits allowed).
Must not contain any spaces.
Must not be greater than 5 digits in length
Examples:
isValid("59001") ➞ true
isValid("853a7") ➞ false
isValid("393939") ➞ false
Page 25
A group of friends have decided to create a secret code which will be used to login their
application. This code will be the first letter of their names, sorted in alphabetical order and count
of group members.
Create a function that takes in an array of names and returns the secret code.
Examples:
findCode(["Adam", "Sarah", "Malcolm"]) ➞ "AMS3"
Note
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
https://www.geeksforgeeks.org/plsql-introduction/
Link# 1
INSERT, UPDATE, https://docs.oracle.com/en/database/oracle/oracle-
DELETE database/12.2/tdddg/dml-and-transactions.html#GUID-40EE6F61-
F008-4F37-8256-D31A2DE49DC9
6.3 Hands-On
Objectives
90 Minutes
Prerequisites
Problem Description:
7. Define following functions in dom.js such that when window loads, it invokes func tion
getBold_items().
8. getBold_items() gets all the bold tags with tagname strong and stores it.
Page 28
9. highlight() iterates all stored bold tags and changes color to red.
10. return_normal() makes all highlighted words dark once the mouse is moved out from
hyperlink
11. Open the html application in browser or run in LiveServer with URL
http://127.0.0.1:5500/dom.html
Sample Output:
Problem Description:
<ul id="menu">
<li>Homepage</li>
<li>Services</li>
<li>About</li>
<li>Contact</li>
</ul>
Problem Description:
As items are entered, it gets added as below with the option to delete
90 Minutes
Page 30
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Link# 1
https://www.techonthenet.com/oracle/select.php
Link# 2
https://www.techonthenet.com/oracle/from.php
Link# 3
https://www.techonthenet.com/oracle/comparison_operators.php
Link# 4
https://www.techonthenet.com/oracle/where.php
Link# 5
https://www.techonthenet.com/oracle/order_by.php
Link# 9
https://www.techonthenet.com/oracle/in.php
Link# 10
https://www.techonthenet.com/oracle/isnull.php
Link# 11
https://www.techonthenet.com/oracle/isnotnull.php
Link# 12
https://www.techonthenet.com/oracle/like.php
Link# 13
https://www.techonthenet.com/oracle/regexp_like.php
Page 33
Link# 14
https://www.techonthenet.com/oracle/not.php
Link# 15
https://www.techonthenet.com/oracle/alias.php
7.3 Hands-On
Objectives
180 Minutes
Page 34
Write a query to display the names of the departments in block number 3 in ascending order.
Page 35
Write a query to display the block number and number of departments in each block and give an
alias as NO_OF_DEPT. Sort the result based on NO_OF_DEPT in descending.
Joins & Subqueries Oracle INNER JOIN, Oracle LEFT 240 120
JOIN, Oracle RIGHT JOIN,
Page 37
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
SELECT clause,
Oracle correlated Subquery
with the EXISTS operator
Link# 1
https://www.techonthenet.com/oracle/views.php
Views & Index
Link# 2
https://www.techonthenet.com/oracle/indexes.php
8.3 Hands-On
Objectives
Write a query to display the subjectname, code and staff name who handles that subject, ordered
by code in ascending order.
Page 40
Write a query to display list of staff name, subject name handled and maximum mark scored in
that subject. Give an alias to the maximum mark as max_mark. Sort the result based on maximum
mark in descending
Page 41
Write a query to create a view for those salesmen belongs to the city New York.
Refer the following schema
Create an index named customer_name for the cust_name column of the customer table
Refer the following schema
Page 42
Sequence, Synonym
About Synonyms, Creating
Synonyms, Using Synonyms in
30 30
DML Statements, Dropping
Synonyms
Introduction to Java
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Introduction to Java
Features of Java, Java
Runtime Environment,
Developing software in Link# 1
Java
https://www.javatpoint.com/features-of-java
Link# 2
https://www.ibm.com/cloud/learn/jre
9.3 Hands-On
Objectives
120 Minutes
Write a PL/SQL query to create an ascending sequence called id_seq, starting from 10,
incrementing by 10, minimum value 10, maximum value 100.
Create a new table called tasks with the below DDL query
CREATE TABLE tasks(
id NUMBER PRIMARY KEY,
Page 44
Create a synonym called stocks for the inventories table and use it in place of the actual table
name in the select query.
Page 45
Create a new user called super with a password super@123 and grant all privileges to
the super user. Later query the super user’s privileges.
Introduction to Java
Objectives
60 Minutes
Write a Java program to print 'Hello' on screen and then print your name on a separate line.
Sample Output 1:
Hello
Alex.
Write a Java program to divide two numbers and print on the screen.
Sample Input 1:
50/3
Sample Output 1:
16
Learning Practice
Topics Sub-Topics
Duration Duration
Introduction to Java Programming
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Link# 3
https://www.geeksforgeeks.org/java-assignment-operator-with-
examples/
10.3 Hands-On
Objectives
180 Minutes
Write a Java program to Print “Hello World” 5 times using for loop.
Sample Output 1:
Hello World
Hello World
Hello World
Hello World
Hello World
Sample Input 1:
Sample Output 1:
After Swapping:
First Number : 6
Second Number : 5
Sample Output 1:
0,1,1,2,3,5,8,13,21,34
Sample Output 1:
Area is = 176.71458676442586
Write a Java program to convert temperature from Fahrenheit (ex 212) to Celsius degree
Sample Input 1:
Page 48
Sample Output 1:
212.0 degree Fahrenheit is equal to 100.0 in Celsius
Learning Practice
Topics Sub-Topics
Duration Duration
Introduction to Java Programming
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Link# 2
https://www.geeksforgeeks.org/constructors-in-java/
Link# 3
https://www.programiz.com/java-programming/static-keyword
Page 49
11.3 Hands-On
Objectives
180 Minutes
Create class ProductTwoNum with two integer values and computes their product by calling the
instance method int computeProd(int num1, int num2).
Sample Input 1
Num1 : 20
Num2 : 3
Sample Output 1
The product of 20 and 3 is 60.
Write a program to print the area of two rectangles having sides (4,5) and (5,8) respectively by
creating a class named ‘Rectangle’ with a method named ‘rectangleArea’ which returns the area
and length and breadth passed as parameters to its constructor.
Sample Output 1
Print the area of the Rectangle
Problem Description:
Smith has library of magazines. He wants to maintain information of magazines. Write a java
program for this. Create a class Magazine with the following attributes:
id, title, author, price
Methods:
Page 50
Parameterized constructor
displaydetails() to display the details of the magazines
discountedPrice() : pass the discount percent, calculate the discount on price and return
the amount to be paid after discount
Magazine
-id:int
-title:String
-author:String
-price:double
+displayDetails():void
+discountedPrice(discountPercentage):double
Sample Input 1
Problem Description:
Alina has to keep track of customers data who are buying products from her shop. For this create
a class Customer with the following attributes:
customerId, customerName, contactNo, paymentDone
Methods:
Parameterized constructor
display customer details
return the payment done by a customer (getter)
Page 51
Customer
-customerId:int
-customerName:String
-contactNo:String
-paymentDone:double
+displayDetails():void
+getPaymentDone():double
Here, attributes are private variables and methods are public. Write parameterized constructor
with parameter names as:
Customer(customerId,customerName,contactNo,paymentDone)
Create class Main, create 3 customers object, and perform the following operations
Create two separate functions for above 2 tasks within Main class as
Main
+displayTotalPayment():void
+highestPaymentDone():void
Sample Input 1
Sample Output 1
Total payment done is 2260 Rs.
Highest payment done customer details:
Customer Id: 22
Customer Name: Manju
Contact number: 7654389129
Payment done: 1200
Page 52
Learning Practice
Topics Sub-Topics
Duration Duration
Introduction to Java Programming
120 30
Wrapper Classes, Using
Scanner Class
Strings String Handling functions 180 90
Array One dimensional array, Array of 120 60
Objects, Using varargs, Using
Arrays class
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Strings Link# 1
http://www.corejavaguru.com/java/strings/stringfunctions
Link# 2
https://www.edureka.co/blog/java-string
Arrays Link# 1
https://www.geeksforgeeks.org/arrays-in-java/
Link# 2
https://www.geeksforgeeks.org/array-class-in-java/
Link# 3
Page 53
https://www.geeksforgeeks.org/variable-arguments-varargs-in-
java/
12.3 Hands-On
Objectives
180 Minutes
Sample Input 1
Enter String: Malayalam
Sample Output 1
Given String is palindrome
Sample Input 2
Enter String: Test
Sample Output 2
Given String is not palindrome
Problem Description:
Write a java program with method checkEnding() that takes two strings and returns true if the first
string ends with the second string, otherwise return false.
Sample Input 1
checkEnding(“abc”,”bc”);
Sample Output 1
true
Sample Input 2
checkEnding(“samurai”,”pi”);
Sample Output 2
False
Page 54
Problem Description:
Write a Java program to calculate the average value of array elements.
Sample Output 1
Average value of the array elements is: 7.0
Problem Description:
Write a Java program to find the maximum and minimum value of an array.
Sample Output 1
Original Array: [25, 14, 56, 15, 36, 56, 77, 18, 29, 49]
Maximum value for the above array = 77
Minimum value for the above array = 14
Learning Practice
Topics Sub-Topics
Duration Duration
Introduction to Java Programming
Collections Collection basics, Set, HashSet, 420 180
Map, HashMap, List, Array List
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
13.3 Hands-On
Objectives
180 Minutes
Problem Description:
Write a Java program to create a new array list, add some elements (string) and print out the
collection.
Sample Output 1:
[Red, Green, Orange, White, Black]
Problem Description:
Sample Output 1:
Red
White
Pink
Yellow
Black
Green
Problem Description:
Declare an ArrayList called numList to hold values of Integer type. Write code such that the
duplicate values are removed.
Sample Input 1
[1,2,3,2,1,4,5,6,6,7,8,8]
Sample Output 1
[1,2,3,4,5,6,7,8]
Page 56
Problem Description:
Write a program to store only unique elements of Employee type in the collection, the uniqueness
of employee must be identified by the employeeId, the employee must have other properties like
name, salary & designation. Print all the employees stored in the collection.
Hint: Use Set<Employee> set = new HashSet<Employee>(); to store the employee
object
Sample Output 1
Employee Id = 100, Name = Alex, Salary = 25000, Designation = Manager
Employee Id = 101, Name = Bruce, Salary = 15000, Designation = Tester
Problem Description:
Use the comparator and sort the employee’s id in ascending and descending order and print the
employees in both ascending & descending order
Hint: Use List<Employee> list = new ArrayList<Employee>(); to store the employee and
Collections.sort(list, comparatorType1) & Collections.sort(list, comparatorType2) to sort the
elements in ascending & descending order, here comparatorType1 & comparatorType2
are instances of Comparator<Employee> implementation that sorts the employeeId in
ascending & descending order respectively.
Expected Output:
Page 57
Ascending Order:
Employee Id = 100, Name = Alex, Salary = 25000, Designation = Manager
Employee Id = 101, Name = Bruce, Salary = 15000, Designation = Tester
Employee Id = 102, Name = Amith, Salary = 20000, Designation = Developer
Descending Order:
Employee Id = 102, Name = Amith, Salary = 20000, Designation = Developer
Employee Id = 101, Name = Bruce, Salary = 15000, Designation = Tester
Employee Id = 100, Name = Alex, Salary = 25000, Designation = Manager
Learning Practice
Topics Sub-Topics
Duration Duration
Introduction to Java Programming
JDBC Basics, JDBC architecture, 420 180
JDBC JDBC Drivers. Process SQL with
JDBC
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
https://docs.oracle.com/javase/tutorial/jdbc/basics/processingsqlstatements.html
14.3 Hands-On
Objectives
180 Minutes
Problem Description:
}
} while(option != 4);
//other codes
}
Problem Description:
Define a Java Class Main and in main method write code to load driver and establish connection
with database.
Using proper SQL Query, retrieve all student records whose branch is Computers and Percentage
above 85 and print in the form as below
Sample Output
studentId studentName Branch Percentage
103 Ram Computers 90
105 Shyam Computers 86
Learning Practice
Topics Sub-Topics
Duration Duration
Introduction to Java Programming
Page 60
Note: Blue colored text under Sub-Topics in the above table indicates that faculty has to
demonstrate based on those and make students practice, samples provided for faculty’s reference
under the Hands-On section.
Link# 2
https://howtodoinjava.com/jdbc-tutorials
15.3 Hands-On
Objectives
180 Minutes
Problem Description:
item based on id. The item has to be an Employee with properties like id, name, salary
and designation. Employee properties must be initialized dynamically
Problem Description:
Write the menu driven program using JDBC which will have following options
a. Store
b. Display by id
c. Delete by id
d. Update salary by id
e. Exit
The menu should repeat until you enter exit, however the other options must perform
operation like storing in the database, displaying the item based on the id, deleting the
item based on id, updating the salary of the item based on id. The item has to be an
Employee with properties like id, name, salary and designation. Employee properties
must be initialized dynamically and also program must ask the id dynamically to
perform display and delete and for update id and salary must be dynamic.
class DBOperations {
// connection method to reuse the db-connection
public static Connection establishConnection() {
// load the driver & establish the connection using datasource informations
// return the connection object
}
public void store(Employee employee) {
// use insert query and store all the values of employee into the database
}
public Employee fetchById(int id) {
// use select query and fetch the result for the matching id
// store the result by initializing employee instances & return to main
// return null if id is not found
}
public int updateSalary(int id, double salary) {
// use update query & update the salary based on the id
// return 1 if updated else -1 if id is not found
}
public int deleteById(int id) {
// use delete query and delete the record by id
// return 1 on successful deletion
// return -1 if id not found
}
// main method can be inside DBOperations or in separate class
public static void main(String[] args) {
// other codes
// create object of DBOperations to call the methods based on options
//scanner to take input from keyboard
Scanner scanner = new Scanner(System.in);
int option = 0;
//other codes
//menu options
do {
System.out.println("1: Store");
System.out.println("2: Display by id");
System.out.println("3: Delete by id");
System.out.println("4: Update salary by id");
System.out.println("5: Exit");
System.out.println("Enter options:-");
int option = scanner.nextInt();
switch(option) {
// write cases for the options
// call methods of DBOperations for appropriate cases
Page 63
}
} while(option != 5);
//other codes
}
Expected Output:
1: Store
2: Display by id
3: Delete by id
4: Update salary by id
5: Exit
Enter options:
1
Enter id
100
Enter name
Harish
Enter salary
28000
---- Stored Successfully -----
1: Store
2: Display by id
3: Delete by id
4: Update salary by id
5: Exit
Enter options:
2
Enter id of the employee
100
--- Fetching records for 100 ----
Name: Harish
Salary: 28000
1: Store
2: Display by id
3: Delete by id
4: Update salary by id
5: Exit
Enter options:
/* Try other options which does operation on database */