top of page

JAVA 2 marks

 

1. What is java?

Java is a programming language and a platform. Java is a high level, robust, secured and object-oriented programming language. Platform: Any hardware or software environment in which a program runs, is known as a platform. Since Java has its own runtime environment (JRE) and API, it is called platform.

 

 2. List any five features of Java?

Some features include Object Oriented, Platform Independent, Robust, Interpreted, Multi-threaded

 

 3.What is meant by variables?

Variable is name of reserved area allocated in memory.

 

4.Types of Variable

There are three types of variables in java

local variable

instance variable

static variable

 

5. What is meant by local Variable?

 A variable that is declared inside the method is called local variable

 

 6.What is an Object?

 Object is an instance of a class. It has state,behaviour and identity. It is also called as an instance of a class.

 

 7. What is meant by abstraction?

Abstraction defines the essential characteristics of an object that distinguish it from all other kinds of objects. Abstraction provides crisply-defined conceptual boundaries relative to the perspective of the viewer. Its the process of focussing on the essential characteristics of an object. Abstraction is one of the fundamental elements of the object model.

 

8.What is meant by Encapsulation?

Encapsulation is the process of compartmentalising the elements of an abtraction that defines the structure and behaviour. Encapsulation helps to separate the contractual interface of an abstraction and implementation

 

9. What is meant by instance Variable?

A variable that is declared inside the class but outside the method is called instance variable . It is not declared as static.

 

10.What is Static variable?

 A variable that is declared as static is called static variable. It cannot be local.

 Example to understand the types of variables

class A

{

int data=50;

//instance variable

static int m=100;

//static variable

void method()

{ int n=90;

//local variable

}//end of class

 

11.What are the Data Types in Java?

In java, there are two types of data types

primitive data types

non-primitive data types

 

12.What is Type Conversion and Casting?

If the two types are compatible, then Java will perform the conversion automatically. For example, assign an int value to a long variable. For incompatible types we must use a cast. Casting is an explicit conversion between incompatible types.

 

13. How many conditions in Java's Automatic Conversions?

An automatic type conversion will be used if the following two conditions are met:

1. The two types are compatible.

2. The destination type is larger than the source type.

 

14.Define Arrays

An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed.

 

int a[]=new int[14];

 

15.Define class.

A class--the basic building block of an object-oriented language such as Java--is a template that describes the data and behavior associated with instances of that class.

When you instantiate a class you create an object that looks and feels like other instances of the same class.

class HelloWorldApp

{

public static void main(String[] args)

{

System.out.println("Hello World!");

//Display the string.

} }

 

16. Define Constructor?

Constructor in java is a special type of method that is used to initialize the object. Java constructor is invoked at the time of object creation. It constructs the values i.e. provides data for the object that is why it is known as constructor.

 

17. What are the Types of java constructors?

There are two types of constructors

1. Default constructor (no-arg constructor)

2. Parameterized constructor

 

18. What is meant by garbage collection?

Java garbage collection is the process by which Java programs perform automatic memory management. Java programs compile to bytecode that can be run on a Java Virtual Machine, or JVM for short. When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program. Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory. Java garbage collection is an automatic process. The programmer does not need to explicitly mark objects to be deleted. The garbage collection implementation lives in the JVM.

 

19. Define Method Overloading .

If a class have multiple methods by same name but different parameters, it is known as Method Overloading. If we have to perform only one operation, having same name of the methods increases the readability of the program.

 

20.What is recursion?

Java supports recursion. Recursion is the process of defining something in terms of itself. As it relates to java programming, recursion is the attribute that allows a method to call itself. A method that calls itself is said to be recursive.

 

21.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 nonauthorized classes.

 

22.What is method overloading and method overriding?

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.

 

23.What gives java it’s “write once and run anywhere” nature?

All Java programs are compiled into class files that contain bytecodes. These byte codes can be run in any platform and hence java is said to be platform independent.

 

24.Define arithmetic operators in java?

Arithmetic operators perform the same basic operations you would expect if you used them in mathematics (with the exception of the percentage sign). They take two operands and return the result of the mathematical calculation. Java has five arithmetic operators: + to add two numbers together or concatenate two Strings. - to subtract one number from another. * to multiply one number by another. / to divide one number by another. % to find the remainder from dividing one number by another

 

25. What does Inheritance mean?

Inheritance is a mechanism wherein a new class is derived from an existing class. In Java, classes may inherit or acquire the properties and methods of other classes.A class derived from another class is called a subclass, whereas the class from which a subclass is derived is called a superclass. A subclass can have only one superclass, whereas a superclass may have one or more subclasses.

 

26.What is finalize() method?

Finalize () method is used just before an object is destroyed and can be called just prior to garbage collection.

 

27.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.

 

28. What is an Abstract Class?

Abstract class is a class that has no instances. An abstract class is written with the expectation that its concrete subclasses will add to its structure and behaviour, typically by implementing its abstract operations.

 

29.What is an Interface?

Interface is an outside view of a class or object which emphaizes its abstraction while hiding its structure and secrets of its behaviour

 

30. What is stream?

A stream is a sequential and contiguous one-way flow of data.Java does not differentiate between the various types of data sources or sinks (e.g., file or network) in stream I/O.

 

31.Mention the stream I/O operations.

Stream I/O operations involve three steps:

1. Open an input/output stream associated with a physical device (e.g., file, network, console/keyboard), by constructing an appropriate I/O stream instance.

2. Read from the opened input stream until "end-of-stream" encountered, or write to the opened output stream (and optionally flush the buffered output).

3. Close the input/output stream.

 

32. What is Byte Stream?

Java byte streams are used to perform input and output of 8-bit bytes as FileInputStream and FileOutputStream.

 

33. Define character stream.

The Java platform stores character values using Unicode conventions. Character stream I/O automatically translates this internal format to and from the local character set.

 

34.Define AppletClass.

Applet class contains several methods to control over the execution of applet.All applets are subclasses of Applet.

 

35.What is SocketClass?

Socket Class is designed to connect to server sockets and initiate protocol exchanges.

bottom of page