Professional Documents
Culture Documents
10 September 2017
18:45
2 marks Questions
QUESTION NO-1
1. Mention any Four Java development tool kits.
QUESTION NO-2
QUESTION NO-3
1. Java is Interpreted and Compiled Language. How?
Compiled and Interpreted
Usually a computer language is either compiled or interpreted. Java combines both these approaches thus making Java a two -
stage system. First. Java compiler translates source code into what is known as bytecode instructions. Bytecodes are not mach ine
instructions and therefore, in the second stage, Java interpreter generates machine code that can be directly executed by the
machine that is running the Java program. We can thus say that Java is both a compiled and an interpreted language.
2. Define a Constructor
It would be simpler and more concise to initialize an object when it is first created. Java supports a special type of method. called
a constructor, that enables an object to initialize itself when it is created.
Constructors have the same name as the class itself. Secondly, they do not specify a return type. not even void. This is because
they return the instance of the class itself.
3. What is the purpose of JDB and JAVAC in Java Development Kit.
JAVAC: The Java compiler, which translates Java source code to bytecode files that the interpreter can understand.
JDB: Java debugger which helps us to find errors in our programs
4. Write naming conventions in Java
protected Access
The visibility level of a "protected" field lies in between the public access and friendly access. That is, the protected modifier
makes the fields visible not only to all classes and subclasses in the same package but also to subclasses in other packages. Note
that non-subclasses in other packages cannot access the "protected" members.
QUESTION NO-4
1. Mention any four features of Java.
Complied and interpreted.
Platform independent and portable.
Object oriented.
Robust and Secure.
Distributed
Familiar, Simple, Small.
Multithreaded and interactive.
High performance.
Dynamic and Extensible.
2. What are the naming conventions used in packages?
NAMING CONVENTIONS
Packages can be named using the standard Java naming rules. By convention, however, packages begin with lowercase letters.
This makes it easy for users to distinguish package names from class names when looking at an explicit reference to a class. We
know that all class names, again by convention, begin with an uppercase letter. For example, look at the following statement:
double y = java.lang.math.sqrt(x):
Java, package ,class, method.
This statement uses a fully qualified class name Math to invoke the method sqrt( ). Note that methods begin with
lowercase letters. Consider another example:
Java.awt.Point pts[ ]:
This statement declares an array of Point type objects using the fully qualified class name.
Every package name must be unique to make the best use of packages. Duplicate names will cause run-time errors. Since
multiple users work on Internet, duplicate package names are unavoidable. Java designers have recognised this problem
and therefore suggested a package naming convention that ensures uniqueness. This suggests the use of domain names as
prefix to the preferred package names.
For example: cbe.psg.mypackage
Here cbe denotes city name and psg denotes organisation name. Remember that we can create a hierarchy of packages
within packages by separating levels with dots.
3. Write the general syntax of array declaration in Java.
QUESTION NO-5
1. What is Java Virtual Machine (JVM)?
Java Virtual Machine:-
It is program that interprets the intimidate java byte code and generates the desired output. It because of byte code and JVM
concepts that programs written in java are highly portable.
2. What is Threading?
Multithreading in java is a process of executing multiple threads simultaneously.
Thread is basically a lightweight sub-process, a smallest unit of processing. Multiprocessing and multithreading, both are used to
achieve multitasking.
But we use multithreading than multiprocessing because threads share a common memory area. They don't allocate separate
memory area so saves memory, and context-switching between the threads takes less time than process.
Java Multithreading is mostly used in games, animation etc.
3. What are Final Variables and Final Methods?
Final Variables and Methods
All methods and variables can be overridden by default in subclasses. If we wish to prevent the subclasses from overriding th e
members, of the superclass, we can declare them as final using the keyword final as a modifier.
Example:
final int SIZE =100;
final void showstatus()I { .......... }
Making a method final ensures that the functionality defined in this method will never be altered in any way. Similarly, the value
of a final variable can never be changed. Final variables, behave like class variables and they do not take any space on individual
objects of the class.
4. What is the difference between Error and Exceptions in Java
An error may produce an incorrect output or may terminate the execution of the program abruptly or even may cause the
system to crash. it is therefore important to detect and manage properly all the possible error conditions in the program so that
the program will not terminate or crash during execution.
Types of Errors
Errors may broadly be classified into two categories:
• Run-time errors
• Compile time errors.
Compile-Time Errors
All syntax errors will be detected and displayed by the Java compiler and therefore these errors are known as compile-time
errors. Whenever the compiler displays an error, it will not create the .class file. It is therefore necessary that we fix all the
errors before we can successfully compile and run the program.
Run-Time Errors
Sometimes. a program may compile successfully creating the .class file but may not run properly. Such programs may
produce wrong results due to wrong logic or may terminate due to errors such as stack overflow.
Exceptions
An exception is a condition that is caused by a run-time error in the program. When the Java interpreter encounters an error
such as dividing an integer by zero, it creates an exception object and throws it (i.e. informs us that an error has occurred ).
The exception handling in java is one of the powerful mechanism to handle the runtime errors so that normal flow of the
application can be maintained.
5. Mention any two built in packages in Java.