JNTU
JNTU MCA 2021 JAVA PROGRAMMING Previous Question Paper (February - 2021 - R13)
Answer any five questions
All questions carry equal marks
Main
Discuss about for-each loop on Java.
Answer
The for-each loop, also known as the enhanced for loop, was introduced in Java 5 to provide a cleaner, more readable syntax for iterating over elements in arrays or collections. It eliminates the need for an explicit index variable or an iterator, thereby reducing the risk of off-by-one errors.
The syntax of the for-each loop is as follows:
// statements to be executed
}
In this structure, the type must match the data type of the elements stored in the array or collection. During each iteration, the variable is automatically assigned the value of the current element, allowing direct access to the data without needing to reference an index.
Key characteristics and limitations include:
- It is read-only regarding the collection structure; you cannot modify the collection (e.g., add or remove elements) while iterating, as this will throw a ConcurrentModificationException.
- It is ideal for scenarios where the index of the element is not required. If the index is necessary for logic (such as updating specific array positions), a traditional for loop remains the appropriate choice.
- It works with any class that implements the Iterable interface, making it highly versatile for all Java Collection Framework types like ArrayList, HashSet, and LinkedList.
Example usage:
int[] numbers = {10, 20, 30, 40};
for (int num : numbers) {
System.out.println(num);
}This approach simplifies code maintenance and improves readability, making it the preferred choice for simple traversal operations in Java applications.
Describe class and constructor with an example program.
Answer
A class is a user-defined blueprint or prototype from which objects are created. It represents a set of properties or methods that are common to all objects of one type. A constructor is a special member method that is invoked automatically when an object of a class is created. It has the same name as the class and does not have a return type.
class Student {
String name;
// Constructor
Student(String n) {
name = n;
}
void display() {
System.out.println("Name: " + name);
}
}
public class Main {
public static void main(String[] args) {
Student s = new Student("Alice");
s.display();
}
}What is method overloading? Explain in detail with example.
Answer
Sign in to view the complete answer paper.
Define interface? Explain multiple inheritance concept and implement in Java.
Answer
Sign in to view the complete answer paper.
What is run time polymorphism? Implement it in Java with an example.
Answer
Sign in to view the complete answer paper.
Describe inner class in detail.
Answer
Sign in to view the complete answer paper.
Define Socket and Server Socket classes.
Answer
Sign in to view the complete answer paper.
Write Java program for client and server communication using Socket.
Answer
Sign in to view the complete answer paper.
Describe File Output and File Input Streams.
Answer
Sign in to view the complete answer paper.
Write a Java program to copy one file into another file.
Answer
Sign in to view the complete answer paper.
Write a Java program to handle multiple exceptions in Java.
Answer
Sign in to view the complete answer paper.
Illustrate and explain keyboard event handling mechanism in Java.
Answer
Sign in to view the complete answer paper.