You are on page 1of 6

Java Question Paper notes

10 September 2017
18:45

2 marks Questions
QUESTION NO-1
1. Mention any Four Java development tool kits.

2. List any four Java tokens.


Reserved keywords
Identifiers
Literals
Operators
Separators
3. What is 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.
4. What is JDK?
JDK Stands for "JAVA DEVELOPMENT KIT"
JDK comes with a collection of tools that are used for developing and running java programs. E.g.: applet Viewer, java, javac
5. Define Token. List the various types and tokens in Java.
Smallest individual units in a program are known as Tokens.
Types of tokens are:
Reserved keywords
Identifiers
Literals
Operators
Separators
6. Mention any four features of Java. pg(11)
Complied and interpreted.
Platform independent and portable.
Object oriented.
Robust and Secure.
Distributed
Familiar, Simple, Small.
Multithreaded and interactive.
High performance.
Dynamic and Extensible.
7. Why Java is a popular language?
Due its features.

QUESTION NO-2

1. What is command line parameter?


There may be occasions when we may like our program to act in a particular way depending on the input provided at the time of
execution. This is achieved in Java programs by using what are known as
command line arguments.. Command line arguments are parameters that are supplied to the application program at the time or
invoking it for execution
2. What is an object?
Object is an instance of a class. Class is a template or blueprint from which objects are created. So object is the instance(result)
of a class.

2marks questions-answers Page 1


of a class.
Object Definitions:
 Object is a real world entity.
 Object is a run time entity.
 Object is an entity which has state and behaviour.
 Object is an instance of a class.
3. What is the difference between class variable and instance variable?
Instance and class variables are declared inside a class., Instance variables are created when the
objects are instantiated and therefore they are associated with the objects. They take different values
for each object. On the other hand, class variables are global to a class and belong to the entire set of objects that class creates.
Only one memory location is created for each class variable.
4. Mention any four features of Java.
Complied and interpreted.
Platform independent and portable.
Object oriented.
Robust and Secure.
Distributed
Familiar, Simple, Small.s
Multithreaded and interactive.
High performance.
Dynamic and Extensible.
5. What is the role of JAVAC and JDB in Java?
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
6. What is 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.
7. How can one pass command line arguments to a Java program?
Command line arguments are parameters that are supplied to the application program at the time or invoking it for execution. It
may be recalled that Program 3.4 was invoked for execution of the command line as follows:
java Test
Here. we have not supplied any command line arguments. Even if we supply arguments, the program does not know what to do
with them.
We can write Java programs that can receive and use the arguments provided in the command line.
Recall the signature of the main() method used in our earlier example programs:
public static void main (String args[])
As pointed out earlier, args is declared as an array of strings (known as string objects). Any arguments provided in the command
line (at the time of execution) are passed to the array args as its elements. We can simply access the array elements and use
them in the program as we wish. For example, consider the command line
Java Test BASIC FORTRAN C++ Java
This command line contains four arguments. These are assigned to the array args as follows:

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

5. List out any two significance of Wrapper Class.


As pointed out earlier, vectors cannot handle primitive data types like int, float, long, char, and double.. Primitive data

2marks questions-answers Page 2


As pointed out earlier, vectors cannot handle primitive data types like int, float, long, char, and double.. Primitive data
types may be converted into object types by using the wrapper classes contained in the java.lang package. Table 9.4 shows
the simple data types and their corresponding wrapper class types.
6. What are Separators? Give two examples.
Separators are symbols used to indicate where groups of code are divided and arranged. They basically define the shape and
function of our code. Table 3.2 lists separators and their functions.

7. What are Public and Protected Access Specifiers?


Public Access Specifiers
Any variable or method is visible to the entire class in which it is defined. What if we want to make it visible to all the c lasses
outside this class? This is possible by simply declaring the variable or method as public.
Example: public int number;
public void sum( ) { .......... )
A variable or method declared as public bas the widest possible visibility and accessible everywhere. In fact, this is what we
would Like to prevent in many programs. This takes us to the next levels of protection.

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.

2marks questions-answers Page 3


4. What is the difference between error and exception 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. Define class and object.

6. Write general syntax to declare a two dimensional array.


For creating two-dimensional arrays, we must follow the same steps as that of simple arrays. We may create a two-dimensional

2marks questions-answers Page 4


For creating two-dimensional arrays, we must follow the same steps as that of simple arrays. We may create a two-dimensional
array like this:
int myArray[][];
MyArray = new int[3][4];
int myArray[][]= new int[3][4];
7. Does Java support multiple inheritances? Justify.
Yes,Since C++ like implementation of multiple inheritance proves difficult and adds complexity to the language, Java
provides an alternate approach known as interfaces to support the concept of multiple inheritance. Although a Java class
cannot be a subclass of more than one superclass, it can implement more than one interface, thereby
enabling us to create classes that build upon other classes without the problems created by multiple inheritance.

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.

2marks questions-answers Page 5


6. What is Multithreading?
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.
7. What is Package?
Packages are Java's way of grouping a variety of classes and/or interfaces together. The grouping is usually done according to
functionality. ln fact, packages act as "containers" for classes.

2marks questions-answers Page 6

You might also like