Q.20 (a) Give the output for the following code:
String myString = "Welcome to Java";
System.out.println (myString.concat("Session"));
System.out.println (myString.length());
System.out.println (myString.replace("to","2"));
Ans: Welcome to Java Session
15
Welcome 2 Java
(b) Expand the term OOP.
Ans: Object Oriented Programming
Q.21 (a) Name any two educational websites that provide online courses for free, in collaboration with various universities across the globe.
Ans: coursera.org and edx.org provide high quality online courses for free, in collaboration with various universities across the globe.
(b) What is a project?
Ans: A project is a task that is undertaken to create a unique product, service, or result.
(c) The process of development of web based applications is broadly categorized in four phases. List down the Phases in a Web Application Project.
Ans: The process of development of web based applications is broadly categorized in four phases. During the development process, one needs to follow the following four main phases of development:
i) Requirements Definition Phase
ii) Design Phase
iii) Implementation Phase
iv) Testing Phase
Q.22 (a) Consider the following co and answer the following questions:
static int MyMethod(int N)
{ return (N*N); }
public static void main(String[] args) { System.out.println(MyMethod(7)); }
i) Name the user defined method.
Ans: MyMethod
ii) What will be the output on executing the above code?
Ans: 49
(b) What is exception handling in Java? Explain the terms try and catch in exception handling.
Ans: Exception Handling in Java: Exception handling is a mechanism in Java that handles runtime errors so that the normal flow of the program can continue or terminate properly. It prevents the program from crashing when an error occurs.
try: It contains the code that may cause an exception. Java monitors this block for errors.
catch: It handles the exception that occurs in the try block and prevents the program from terminating abruptly.
Q.23 (a) What are Arrays? Give an example.
Ans: Arrays are variables that can hold more than one value, they can hold a list of values of the same type.
One way to declare an array is :
marks = new double[5];
(b) Write Java code to do the following:
i) Create an array Marks that stores values 78,65,85,91,82
Ans: double[] Marks = {78,65,85,91,82};
ii) To print all the values of the array Marks using a loop.
Ans: for (int i = 0; i< 5; i++)
System.out.println(Marks[i]);
iii) Display the average stored in the array Marks.
Ans: System.out.println((Marks[0] + Marks[1]+ Marks[2]+ Marks[3] +Marks[4])/5);
Q.24 Consider the following tables - TRAIN and PASSENGER:
Table: TRAIN
| TID |
TName |
Boarding |
Destination |
Cost |
| 305 |
VandeBharat |
New Delhi |
Katra |
2500 |
| 206 |
Shatabdi |
Mumbai |
Delhi |
3500 |
| 307 |
Superfast |
Lucknow |
Chennai |
4500 |
| 208 |
HolidayExpress |
Goa |
Delhi |
2000 |
Table: PASSENGER
| PID |
TID |
Name |
DOT |
| P108 |
307 |
Gagandeep Singh |
14-10-2022 |
| P209 |
206 |
Rahat Ali |
01-01-2023 |
| P110 |
305 |
Cristopher |
10-12-2022 |
| P677 |
208 |
Diksha Luther |
11-09-2019 |
| P555 |
307 |
Nira Kadam |
06-11-2020 |
| P211 |
208 |
Ritam Ahuja |
17-12-2021 |
Write SQL queries for the following:
(a) To display the count of passengers travelling by each train
Ans: Select count(Name),TName from Train, Passenger where Train.TID=Passenger.TID group by TName;
(b) To add a new record in the table TRAIN:
(12471, “Garib Rath”, “New Delhi”, “Mumbai”, 1105)
Ans: Insert into Train values (12471, “Garib Rath”, “New Delhi”, “Mumbai”, 1105);
(c) To display TName, Name and Boarding of all passengers.
Ans: Select TName, Name, Boarding from Train, Passenger where Train.TID=Passenger.TID;
(d) To display details of all trains whose cost is between 3000 and 5000.