400+ TOP JAVA LAB VIVA Questions and Answers Pdf

JAVA LAB VIVA Questions with Answers :-

1.What is JVM?
The Java interpreter along with the run time environment required to run the Java application in called as Java virtual machine(JVM)

2. What is the most important feature of Java?
Java is a platform independent language.

3. What do you mean by platform independence?
Platform independence means that we can write and compile the java code in one platform (eg Windows) and can execute the class in any other supported platform eg (Linux,Solaris,etc).

4. What is the difference between a JDK and a JVM?
JDK is Java Development Kit which is for development purpose and it includes execution environment also. But JVM is purely a run time environment and hence you will not be able to compile your source files using a JVM.

5. What is the base class of all classes?

6. What are the access modifiers in Java?
There are 3 access modifiers. Public, protected and private, and the default one if no identifier is specified is called friendly, but programmer cannot specify the friendly identifier explicitly.

7. What is are packages?
A package is a collection of related classes and interfaces providing access protection and namespace management.

8. What is meant by Inheritance and what are its advantages?
Inheritance is the process of inheriting all the features from a class. The advantages of inheritance are reusability of code and accessibility of variables and methods of the super class by sub classes.

9. What is the difference between superclass and subclass?
A super class is a class that is inherited whereas sub class is a class that does the inheriting.

10. What is an abstract class?
An abstract class is a class designed with implementation gaps for sub classes to fill in and is deliberately incomplete.

11. What are the states associated in the thread?
Thread contains ready, running, waiting and dead states.

12. What is synchronization?
Synchronization is the mechanism that ensures that only one thread is accessed the resources at a time.

13. What is deadlock?
When two threads are waiting each other and can’t precede the program is said to be deadlock.

14. What is an applet?
Applet is a dynamic and interactive program that runs inside a web page displayed by a java capable browser

15. What is the lifecycle of an applet?
init() method – Can be called when an applet is first loaded
start() method – Can be called each time an applet is started.
paint() method – Can be called when the applet is minimized or maximized.
stop() method – Can be used when the browser moves off the applet’s page.
destroy() method – Can be called when the browser is finished with the applet.

16. How do you set security in applets?
using setSecurity Manager() method

17. What is a layout manager and what are different types of layout managers available in java AWT?
A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout and GridBagLayout

18. What is JDBC?
JDBC is a set of Java API for executing SQL statements. This API consists of a set of classes and interfaces to enable programs to write pure Java Database applications.

19. What are drivers available?
a) JDBC-ODBC Bridge driver b) Native API Partly-Java driver
c) JDBC-Net Pure Java driver d) Native-Protocol Pure Java driver

20. What is stored procedure?
Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task. Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters.

21. What is the Java API?
The Java API is a large collection of ready-made software components that provide many useful capabilities, such as graphical user interface (GUI) widgets.

22. Why there are no global variables in Java?
Global variables are globally accessible. Java does not support globally accessible variables due to following reasons:
1)The global variables breaks the referential transparency
2)Global variables creates collisions in namespace.

23. What are Encapsulation, Inheritance and Polymorphism?
Encapsulation is the mechanism that binds together code and data it manipulates and keeps both safe from outside interference and misuse. Inheritance is the process by which one object acquires the properties of another object. Polymorphism is the feature that allows one interface to be used for general class actions.

24. What is the use of bin and lib in JDK?
Bin contains all tools such as javac, appletviewer, awt tool, etc., whereas lib contains API and all packages.

25. What is method overloading and method overriding?
Method overloading: When a method in a class having the same method name with different arguments is said to be method overloading. Method overriding : When a method in a class having the same method name with same arguments is said to be method overriding.

26. What is the difference between this() and super()?
this() can be used to invoke a constructor of the same class whereas super() can be used to invoke a super class constructor.

27. What is Domain Naming Service(DNS)?
It is very difficult to remember a set of numbers(IP address) to connect to the Internet. The Domain Naming Service(DNS) is used to overcome this problem. It maps one particular IP address to a string of characters. For example, www. mascom. com implies com is the domain name reserved for US commercial sites, moscom is the name of the company and www is the name of the specific computer, which is mascom’s server.

28. What is URL?
URL stands for Uniform Resource Locator and it points to resource files on the Internet. URL has four components: http://www. address. com:80/index.html, where http – protocol name, address – IP address or host name, 80 – port number and index.html – file path.

29. What is RMI and steps involved in developing an RMI object?
Remote Method Invocation (RMI) allows java object that executes on one machine and to invoke the method of a Java object to execute on another machine. The steps involved in developing an RMI object are: a) Define the interfaces b) Implementing these interfaces c) Compile the interfaces and their implementations with the java compiler d) Compile the server implementation with RMI compiler e) Run the RMI registry f) Run the application.

30. What is RMI architecture?
RMI architecture consists of four layers and each layer performs specific functions: a) Application layer – contains the actual object definition. b) Proxy layer – consists of stub and skeleton. c) Remote Reference layer – gets the stream of bytes from the transport layer and sends it to the proxy layer. d) Transportation layer – responsible for handling the actual machine-to-machine communication.

31. Why Java?
The programs that we are writing are very similar to their counterparts in several other languages, so our choice of language is not crucial. We use Java because it is widely available, embraces a full set of modern abstractions, and has a variety of automatic checks for mistakes in programs, so it is suitable for learning to program. There is no
perfect language, and you certainly will be programming in other languages in the future.

32. Do I really have to type in the programs in the book to try them out?
Everyone should type in HelloWorld.java, but you can find all of the code in this book (and much more) on this booksite.

33. What are Java’s rules regarding tabs, spaces and newline characters?
There are not many. Java compilers treat them all to be equivalent. For example, we could also write HelloWorld as follows:

public class HelloWorld { public static void main (
String [] args) { System.out.println(“Hello World”) ; } }

But we do normally adhere to spacing and indenting conventions when we write Java programs, just as we always indent paragraphs and lines consistently when we write prose or poetry.

34. What are the rules regarding quotation marks?
Material inside quotation marks is an exception to the rule of the previous question:
things within quotes are taken literally so that you can precisely specify what gets printed. If you put any number of successive spaces within the quotes, you get that number of spaces in the output. If you accidentally omit a quotation mark, the compiler may get very confused, because it needs that mark to distinguish between characters in the string and other parts of the program. To print a quotation mark, a newline, or a tab, use \”, \n, or \t, respectively, within the quotation marks.

35. What is the meaning of the words public, static and void?
These keywords specify certain properties of main() that you will learn about later in the book. For the moment, we just include these keywords in the code (because they are required) but do not refer to them in the text.

36. What happens when you omit a brace or misspell one of the words, like public or
static or main?
It depends upon precisely what you do. Such errors are called syntax errors. Try it out and see.

37. Can a program use more than one command-line argument?
Yes, you can put several, though we normally use only a few. You refer to the second one as args[1], the third one as args[2], and so forth. Note that we start counting from 0 in Java.

38. What Java systems libraries and methods are available for me to use?
There are thousands of them, but we introduce them to you in a deliberate fashion in this book to avoid overwhelming you with choices.

39. How should I format my code? How should I comment my code?
Programmers use coding guidelines to make programs easier to read, understand, and maintain. As you gain experience, you will develop a coding style, just as you develop style when writing prose. Appendix B provides some guidelines for formatting and commenting your code. We recommend returning to this appendix after you’ve written a few programs.

40. What exactly is a .class file?
It’s a binary file (sequence of 0s and 1s). If you are using Unix or OS X, you can examine its contents by typing od -x HelloWorld.class at the command prompt. This displays the results in hexadecimal (base 16). In deference to Java’s name, the first word of every .class file is cafe.

41. How do I get the | symbol on my keyboard?
It’s there. Often it’s above the \ symbol.

42. Java prints out a ton of digits when I System.out.println() a double. How can I format it so it displays only 3 digits after the decimal place?
Use the method System.out.printf() described in Section 1.5.

43. Why does the integer quotient -0/3 yield 0, but the double quotient -0.0/3.0 yields – 0.0?
Java represent integers using something called two’s complement notation, and there is only one representation of 0. (You’ll learn about this in Section 5.1.) Java represents doubles using IEEE specifications, and there are two distinct representations of the number zero, 0 and -0. (You’ll learn about this in Section 9.1.)

44. What happens when I use / and % with a negative numerator?
Try it and see. -47 / 5 = -9 and -47 % 5 = -2. The quotient is always rounded toward zero. To ensure the Euclidean property b * (a / b) + (a % b) = a, the result of the remainder operator can be negative. This convention was inherited from ancestral

languages like FORTRAN and C. Some languages (but not Java) include both remainder and modulo operators because it is often convenient to have a version that returns only nonnegative integers.

45. Can I use % with real numbers?
Yes. If angle is nonnegative, then angle % (2 * Math.PI) converts the angle to be
between 0 and 2 π.

46. How do I print a “?
Since ” is a special character when dealing with strings, you must escape the convention rules by using \”. For example, System.out.println(“The pig said \”Oink Oink\” afterwards”);.

47. OK, so then how do I print a \?
Use “\\”.

48. Why do I need to declare the type of a variable in Java?
By specifying the type, the compiler can alert you of potential errors, say if you try to multiply an integer with a string. For the same reason, when doing physics calculations, it is always a good idea to keep track of the units and make sure they “type check.” For small programs, this may not seem important; for large programs it is crucial. The Ariane 5 rocket exploded 40 seconds after takeoff because of a bug in its software that incorrectly converted a 64 bit real number into a 16 bit integer.

49. Why is the type for real numbers called double?
Historically, the type for floating point numbers was float, but they had limited
accuracy. The type double was introduced as a floating point type with twice as much

50. Is it correct to say that using parentheses can only change
Almost, with one surprising exception. The literal value 2147483648 (2^31) is only permitted as an operand of the unary minus operator, i.e., -2147483648. Enclosing it in parentheses, i.e., -(2147483648), leads to a compile-time error.

Leave a Reply

Your email address will not be published. Required fields are marked *