Home | | Object Oriented Programming | Important Short Questions and Answers: Java Exception Handling

Chapter: Object Oriented Programming(OOP) : Java Exception Handling

Important Short Questions and Answers: Java Exception Handling

Object Oriented Programming(OOP) - Java Exception Handling - Important Short Questions and Answers: Java Exception Handling

1.  Explain the usage of Java packages.

 

This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.

 

2.     If a class is located in a package, what do you need to change in the OS environment to be able to use it?

 

You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let's say a class Employee belongs to a package com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you'd need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows: c:\>java com.xyz.hr.Employee

 

3.     What's the difference between J2SDK 1.5 and J2SDK 5.0? There's no difference, Sun Microsystems just re-branded this version.

 

4.     What would you use to compare two String variables - the operator == or the method equals()?

 

A. I'd use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.

 

5.     Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?

 

Yes, it does. The FileNoFoundException is inherited from the IOException. Exception's subclasses have to be caught first.

 

6.       Can an inner class declared inside of a method access local variables of this method?

A. It's possible if these variables are final.

 

7.     What can go wrong if you replace && with & in the following code: String a=null; if (a!=null && a.length()>10) {...} A.

 

A single ampersand here would lead to a NullPointerException.

 

8.       What's the main difference between a Vector and an ArrayList A. Java Vector class is internally synchronized and ArrayList is not.

9.       When should the method invokeLater()be used? A

 

. This method is used to ensure that Swing components are updated through the event-dispatching thread.

 

10.  How can a subclass call a method or a constructor defined in a superclass? Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass's constructor For senior

 

11.                        What is Java Streaming?

 

Java streaming is nothing more than a flow of data. There are input streams that direct data from the outside world from the keyboard, or a file for instance, into the computer; and output streams that direct data toward output devices such as the computer screen or a file.

 

12. What are Byte streams?

 

Byte streams provide a convenient means for handling input and output of bytes. Byte streams are used for example when reading or writing binary data.

 

13. What are Character streams?

 

Character streams, provide a convenient means for handling input and output of characters. They use Unicode, and therefore, can be internationalized.

 

14. some Byte Stream supported classes. BufferedInputStream BufferedOutputStream ByteArrayInputStream ByteArrayOutputStream DataInputStream DataOutputStream

15. List some Character Stream supported classes. BufferedReader

BufferedWriter CharArrayReader CharArrayWriter FileReader FileWriter

16. Write note on FileInputStream class.

 

The FileInputStream class creates an InputStream that you can use to read bytes from a file. Its two most common constructors are

 

FileInputStream(String filepath) FileInputStream(File fileobj)

 

17.  Define Multithread Programming.

A multithreaded program contains two or more parts that can run concurrently. Each part

 

of such program is called a thread, and each thread defines a separate path of execution. Thus, multithreading is a specialized form of multitasking.

 

18. What is Synchronization?

 

When two or more threads need access to a shared resource, they need some way to ensure that the resource will be used by only one thread at a time. The process by which this is achieved is called synchronization.

 

The general form of the synchronized statement is synchronized (object){

 

// statements to be synchronized

 

}

 

19. In multithreading, When does a deadlock situation occur?

 

Deadlock situation occurs, when two threads have a circular dependency on a pair of synchronized objects.

 

20. What is the need of Thread Priorities?

 

Thread priorities are used by the thread scheduler to decide when each thread be allowed to run. Higher-priority threads get more CPU time than lower-priority threads.

 

To set a thread’s priority, use the setPriority() method, which is a member of Thread. final void setPriority(int level)

 

21.                What is the difference between String and String Buffer?

a) String objects are constants and immutable whereas StringBuffer objects are not.

 

b) String class supports constant strings whereas StringBuffer class supports growable and modifiable strings


Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Object Oriented Programming(OOP) : Java Exception Handling : Important Short Questions and Answers: Java Exception Handling |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.