DIT UNIVERSITY DEHRADUN
Schoolof Computing
Quz 2, ODD SEM 2024-25
Course Qode: cSN203 Course Name: tntroduction to Java Programming Program: BTech CSE/T
Duration: Hour Total Marks: 20
Attempt any &questions:
Can an terface extend any cBass or interface? Compare abstract class and interface with help of a code.
(1+4 marks]
What is the difference between StringBuilder and StringBuffer class? Develop a java program to illustrate
super keyword, which refers to super-class instance. (2+3 marks)
Q3) Wite a Java program to create a class called Animal with instance varlables name and color. Implement a
parameteried constructor that takes name and color as parameters and initializes the instance variabies,
print the vakves of the variables. Write a java program to demonstrate the constructor overloading.
[2.5+2.5=5 marks]
Q4) Analyze the following codes. If any error is found, mention it with reason, otherwise write the output:
[1+2+2=5 marks]
a. class Main {
public static void main(String argsl]) {
int m;
System.out.println(m);
b. interface Book
{char type=C;
pubic cass Nyclass {public static void main(String!] args)
{System.out.printin(new Book().type): }}
c. public cass Mainf
public static void main(String (largs
String strl= "Hello"; String str2 = new String("Hello");
System.out.printin(strl == str2): } ,ue
Qs) Analyze the following codes. tf anyerror is found, mention it with reason,otherwise write the output:
[1+2+2=5 marks])
a. intl] array =new intl}{1, 2, 3, 4, 5};
System.out.printin(arraylarray.length -1):
b. dass Myclass{ public Myclass() `ystem.out.println("lam constructor"); })
public class Main{ Myclass m = new Mycass():
public static void main(Stringl)args) {System.out.printin("Hello World!"); }}
c. int) Mtyarray = (1, 2, 3, 4, S}:
intl] SecondArray = Myarray:
SecondArray[0} = 10,
System.out.printin(Myarray[0)):
--END OF PAPER ----
Paper Code: CSN 203 / CSF203
Printed Page 1 of 2
DIT UNIVERSITY DEHRADUN
B.TECH (CSE) MID TERM EXAMINATION, ODD SEM 2024-25 (SEM D)
Roll No. 2 3 2 3
Subject Name: Introduction to Java Programming
Time: 2 Hours
Total Marks: 50
Nete: No student is allowed to lesave the examination hall before the completion of the
exam.
SECTIONA :Attempt any four questions from the following : [4 x 5= 20]
Explain the term inheritance and its types. Why multiple inheritance is not supported in java using
classes? Compare and contrast method overloading and method overriding.
[S Marks]
Q.2) Explain what is the effect of using final keyword with a) variable, b) method, c) class in java. Explain
the use of volatile keyword in java. [5 Marks]
Describe the significance of enum in java. Develop a java program for switch cases using
enumerated values for weekdays (e.g., MONDAY, TUESDAY and so on ). Don't use integer values
(like 0 for SUNDAY, 1 for MONDAY and so on). (5 Marks]5
Q.4) Examine the following codes. If any error is found, mention with reason, otherwise write the
output: [5 Marks: 1+2+2]
a. pubic ciass AB{
public static void main(String[] args)
{ if (true)
break; }}
b. public class Myclass{
public static void main(String[] arr){ } Syatan
public static void main(String arr) 0 } Dale
c. class Myclass { eloh
public static void main(String args[]) bl and b2
{Boolean bl = "TRUE"; Boolean b2 ="FALSE"; boolean b= b1 && b2;
System.out.printin(b); }}
Q.5) Examine the following codes. If any error is found, mention with reason, otherwise write the
output: (5 Marks: 1+2+2)
a. class Myclass
{static void staticMethod()
{System.out.printin(" lam static method");
public cass MainClass
{ publicstatic void main(Stringl] args)
{Myclass first = null;
first.staticMethod(): }}
b. System.out.printf("%6s\n", "Welcome Friends"):
System.out.printf(""%6b\n",(6> 12));
slalenent loA
Paper Code: CSN 203 / CSF203 Printed Page 2 of 2
c. for (int i= 1; i <4; it+){
for (intj = 1; j<4; jt+) {
if (i *j> 2)
break;
System.out.printIn{i * ):
System.out.printin(i);
SECTION B:Attempt any three questions from the following: (3 x 10= 301
Q.6) Develop a java program to count the occurrence of numbers that reads the integers between 1
and 50 and counts the occurrences of each. Assume the input ends with 0.
Here is a sample run of the program: (10 Marks] g
Enter the integers between 1 and 100: 25 654323 43 20
2 occurs 2 times
3 occurs 1 time
4occurs 1 time
5 occurs 2 times and so on.
Note that if a number occurs more than one time, the plural word "times" is used
in the output
Q} a. Develop ajava code for calculator to accept an expression as a string with operands and
operator and performing corresponding calculations. For example, 3+4 and 3 + 4 are acceptable
expressions. Here is a sample run: [5 Marks] s2
a Adminstrator: Command Prompt
Axercise>java Exe r c i e 1 0 26
rce>jaa Exerc ise 10 26
Eexercise>java Exercise1926
eXercse>java
e Exerc ise10 26
c :he xerc ise>
b. Explain what is the effect of using static keyword with a) variable, b) method in
java. [5 Marks5
Q.8) (a) Write a Java program for binary search by using method with array as argument.
(5 Marks]
(b) Develop a Java program to sort and print a string in alphabeticalorder. (take string as
input from user) (S Marks]
Q.9) a. Write a program tha promptsthe user to enter aletter and check whether the letteris a
vowel or consonant. Here is a sample run: [S Marks]5
Enter a letter: B Enter a letter grade: a Enter a letter grade: #
B is a consonant a is a vowel #is an invalid input
b. Write a javacode that prompts the user toenter an integer from
1to 10and displays a pyramid, as shown in the following sample run: [5 Marks],
Enter the number of lines: 5 1
212
32123
432 1 23 4
5432 1 2345
---END OF PAPER ----
DIT UNIVERSITY DEHRADUN
School of Computing
QUIZ 1,ODD SEM 2024-25
Course Code: CSN203 Course Name: Java Programming Program Name: CSE
Duration: 1Hour Total Marks: 20 h
Attempt any 4 questions:
Q.1) Explain the significance of execution engine of JVM tomake java programs as platform
Explain in detaii the specific roles of JDK, JRE and JVM. independent.
$Q.2) a. Execute the following code when the value of x is = 4 and value of y is 3 and compute the output:
if ((x<3 || y> 2))
System.out.println("first case");
else
System.out.printin("'second case");
b. Compute the output of the following code snippet:
int varl = 0;
int var2 = 2;
while ((var2 != 0) && (var1/ var2) >= 0))
{varl = var1 + 1; var2 = var2 - 1; }
System.out.print(var1+" "+var2):)
Q3) Demonstrate by writing a program whether two floating-point numbers are same up to three decimal
places. Take the numbers as input from user.
SQ.4) a. Compute the output/error of the following code snippet:
{int x = 5;
{ int y =6;
System.out.print(x +""+ y); }
System.out.printin(x +""+ y): }
b. Compute the output/error of the following code snippet:
for (int k = 0; k< 20; k+=2) {
if(k %3 == 1)
System.out.printin(k + " "); }
3,Q5) What is the value ofy after evaluating the following expressions, when y= 18:
a. ytt=t+y+ y-- t --y; x b. -- y= --y- -y -y--i
C. y*=y+5; d. y=y%2 +++y - --;
[4 x5 =20)
--END OF PAPER
Printed Page 1 of2
Paper Code: CSN 203/CSF203/CS211
DIT UNIVERSITY DEHRADUN
B. TECH (CSE), END TERM EXAMINATION, ODD SEM 2024-25 (SEM II)
BSc(Phy,Math, Stats)
Roll No. 2 3 2 2
Subject Name: Introduction to Java Programming
Total Marks: 100
Time: 3 Hours
Note: No student is allowed to leave the examination hall before the completion of the exam.
mixed with answers from other section.
Answers from a section must be written together and must not be
SECTION 1: Attempt any five questions in SECTION 1: [5 x 8= 40j
hierarchy with in detail
Q.1.1) Elaborate the significance of Throwable in java. Explain exception handling
with help of diagram. [2+6 marks]
constructors. In the same code. demonstrate
Q.1.2) a. Develop a java code for a class with three parametrized
the constructor chaining using this(). [3marks]
help of suitable
b. Explain the difference between method overloading and method overriding with the
example. [5 marks]
otherwise write the
Q.1.3) Analyze the following codes. If any error is found, mention it with reason,
output: [2*4 =8 marks]
class Test class Main {
{public static void main(Stringl] args) public static void main(String args[]) {
{try { int a[]= {1, 2, 3, 4}; try {throw 10;
{System.out.printin (a[10]; ) } catchlint e) {
catch (Exception e) {} System.out. printIn("Got the Exception
catch(ArraylndexOutOfBoundsException + e); }}}
e) {} }}
public class Main { String str = "Hellow":
public static void main(String] args) System.out.printin(str.indexOf();
String str = "Java"; str.concat("
Programming");
System.out.printin(str); }}
Q14) a. Write a program that meets the following requirements:
a. Creates an array with 20 randomly chosen integers.
b. Prompts the user to enter the index of the element of array, then displays the corresponding
element value along with highest and lowest integer number of array.
[4 marks)
b. Develop a java code for functioning of following methods of StringBuilder:
append(), insert(), delete(),reverse(),replace(),capacity() [4 marks]
QS) Let s1 be " Welcome " and s2 be " welcome", Write the code for the following
statements: (2*4=8 marks)
(a) Check whether s1 is equal to s2 and assign the result to a Boolean variable isEqual.
(b) Check whether s1 is equal to s2, ignoring case, and assign the result to a
Boolean variable isEqual.
(c) Assign the first character of s1 to a char variable x.
(d) Create a new string s3 that combines s1 with s2.
Paper Code: CSN 203/CSF203/CS211
Printed Page 2 of 2
Q.1.6) a. Write a java program that finds the nunber of occurrences of a
specified character in a string using
following: [4 marks]
public static int count( String st, char c) For example, count("Anand",'a') returns 2.
b. Write a java program using nested for loop to print following pattern:
1
(4 marks]
131
13931
13927931
SECTION 2: Attempt any four questions in SECTION 2:
[4x 15= 60]
Q.2.1) a. Create arecursive method to return the number of uppercase letters in an array of
characters,
You need to define the following two methods.
public static int count(char[] chars)
publicstatic int count(char[]chars, int h)
Write the code that prompts the user to enter a list of characters in one line and displays the
number of uppercase letters in the list. 17 marks]
b. Develop a program that reads integers, finds the largest of them, and counts íts occurrences.
Assume that the input ends with number 0.
Suppose that you entered 1838 88 0; the program finds that the largest is 8 and the occurrence
count for 8 is 4. |8 marks]
Q.2.2) a. Develop a program to create an abstract class called Shape2d that has two data members of type
double and two abstract methods area() and display(). Create twoderived classes Rectangle and
Triangle. In both classes define the method area() to compute the area of that shape and return it
as a double value and define the method display() to display the value of the data members with
appropriate caption and the calculated area. Create a class calledShape2 dDemo and provide main
method to instantiate the objects of Rectangle and Triangle for demonstration of the above classes.
[8 marks]
b. Design an interface called Shape with methods draw() and getArea(). Further design two classes
called Circle and Rectangle that implements Shape to compute area of respective shapes. What is
marker interface? [6+1 marks]
Q.2.3) a. Develop a java program which reads a 3-by-4 matrix and displays the sum of each
column. Here is sample run:
[8marks]
1.5 2 3 4 Sum of the elements at column 0 is 16.5
5.5 6 7 8 Sum of the elements at column 1 is 9.0
9.5 1 3 1 Sum of the elements at column 2 is 13.0
Sum of the elements at column 3 is 13.0
eb. Write a java program to illustrate the working of merges sort [7 marks]
Q.2.4) a. What are the advantages and disadvantages of cloning? Writea java code for cloning of an
object using Object.clone(). Supedee)
[2+6-8 marks]
b. Compare and contrast the throw and throws with the help of code.
(7 marks]
Q.2.5) a. Write the binarytoDec(String binaryString) method to convert a binary string into a
decimal
number. Implement the binarytoDec method to throw a NumberFormat Exception if the
not a binary string. string is
[8 marks]
b. Write a program that causes the JVM tothrow an
[7 marks]
OutOfMemoryError and catches,handles it.
---END OF PAPER ----