assigni&ii

3
Assignment I Basics of JAVA Q-1 Explain why JAVA is known as platform Independent/Neutral Language? [02] Q-2 How is JAVA strongly associated with the Internet? [02] Q-3 Explain: [12] 1) Method Overloading 2) Final Class 3) Final Variables & Methods 4) Abstract Methods & Classes Q-4 Explain JDK. [02] Q-5 Explain syntax of main in JAVA and Why it is part of class? [04] Q-6 Is it necessary to have same name of class and source file in JAVA Program? [03] Assignment II Packages, Interfaces, Exceptions & Multithreading Q-1 Why are arrays easier to use compared to a bunch of related variables? [02] Q-2 Find errors, if any, in the following code segment: [02] int m; int x[ ] = int [10]; int [.]y = int [11]; for(m=1;m<=10;++m) x[m] = y[m] = m; x = y = new int[20]; for(m=1;m<10;++m) system.out.printn(x[m]) Q-3 How does String class differ from the StringBuffer class? [02]

Upload: ravi00013

Post on 30-Apr-2017

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: AssignI&II

Assignment I

Basics of JAVA

Q-1 Explain why JAVA is known as platform Independent/Neutral Language? [02]Q-2 How is JAVA strongly associated with the Internet? [02]Q-3 Explain: [12]

1) Method Overloading 2) Final Class3) Final Variables & Methods4) Abstract Methods & Classes

Q-4 Explain JDK. [02]Q-5 Explain syntax of main in JAVA and Why it is part of class? [04]Q-6 Is it necessary to have same name of class and source file in JAVA Program? [03]

Assignment II

Packages, Interfaces, Exceptions & MultithreadingQ-1 Why are arrays easier to use compared to a bunch of related variables? [02]Q-2 Find errors, if any, in the following code segment: [02]

int m;int x[ ] = int [10];int [.]y = int [11];

for(m=1;m<=10;++m)x[m] = y[m] = m;

x = y = new int[20];

for(m=1;m<10;++m)system.out.printn(x[m])

Q-3 How does String class differ from the StringBuffer class? [02]Q-4 What is a vector? How is it different from an array? [02]Q-5 What are applications of wrapper classes? [02]Q-6 What are differences and similarities between an interface and class? [02]Q-7 What is a package? State advantages/benefits of organizing classes into package. Write down steps for designing/creating a package. [04]Q-8 Is the following code legal? [01]

try { } finally { }

Q-9 What exception types can be caught by the following handler? [01]catch (Exception e) { }

What is wrong with using this type of exception handler?

Page 2: AssignI&II

Q-10 Is there anything wrong with the following exception handler as written? Will this code compile? [02]

try {

} catch (Exception e) { } catch (ArithmeticException a) { }

Q-11 Compile and run BadThreads.java: [05]public class BadThreads {

static String message;

private static class CorrectorThread extends Thread {

public void run() { try { sleep(1000); } catch (InterruptedException e) {} //Key statement 1: message = "Mares do eat oats."; } }

public static void main(String args[]) throws InterruptedException { (new CorrectorThread()).start(); message = "Mares do not eat oats."; Thread.sleep(2000); //Key statement 2: System.out.println(message); }}

The application should print out "Mares do eat oats." Is it guaranteed to always do this? If not, why not? Would it help to change the parameters of the two invocations of Sleep? Describe two ways to change the program to enforce such a guarantee.