Vous êtes sur la page 1sur 5

-Subject: JAVA Programming

Subject Code: BSIT – 42


Assignment: TB

1) How are data and methods organized in an object-oriented


program?
Ans:-
In object-oriented programming, data and method are organized by
defining them within class.
Therefore data and methods are called member variables and method.
And with the help of these members the structure and behavior of a
class is define when is possessed by a set of object of that class In
object-oriented programming not any variables or method can be
standalone, they have to defined within the body of the class.

2) Why is Java known as platform-neutral language & How is


Java more secured than other languages?
Ans:-
An application is a program that you can execute from any operating
system prompt. Stand-alone applications can either be window-based
applications or console applications. Window-based applications
have a graphical user interface .They use features that are supported
by platforms like Microsoft Windows, Macintosh, Motif, and OS/2.
Console applications are character-based applications that do not
have a graphical user interface. A stand-alone application uses the
resources of a single computer. Networked applications can use
resources that are available over a network. Distributed applications
can access objects that execute across many computers over a
network.
JAVA is secure because program traveling over the Internet to your
computer could carry a virus. Due to the strong type-checking done
by Java on the user’s computer, any changes made to the program are
tagged as errors and the program will not execute. Type-checking
involves checking the code to find out any changes made to the
original code. Java is, therefore, secure.

3) What is multithreading? How does it improve the performance


of JAVA?
Ans:-
A process that is made of only one thread is said to be single-
threaded. A single-threaded application can perform only one task at
a time. In such a situation, you wait for one task to complete so that
another can start. A process run at the same time, perform different
tasks, and interact with each other.
Java has built-in support for threads. A major portion of the Java
architecture is multithreaded. In Java programs, the most common
use of threads is to allow an applet to accept input from a user and
simultaneously display animation in another part of the screen. Any
application that requires two tasks to be accomplished at the same
time is probably a great candidate for multithreading.

4)What is the task of the main method in a Java program?


Ans:-
The Java runtime environment has to access the main ( ) method to
execute a program. Therefore, the main ( ) method should be declared
public. The main ( ) method should be declared static because it has
to exist before any object of the class is created. The command line
parameter is a string type variable – main (string args [ ]).

5) List the eight basic data types used in Java. Give examples.
Ans:-
1 byte – 8-bit
2 short -- 16-bit
3 int` -- 32-bit
4 long -- 64-bit
5 float -- 32-bit
6 double -- 64-bit
7 char -- 16-bit
8 Boolean -- 1-bit

6) What is type casting? Why is it required in programming?


Ans:-
Casting means assigning a value of one type to a variable of another
type If the two types are compatible, the java technology performs
the conversation Automatically. For example, an int value can always
be assigned to a long Variable. Where information would be lost in
an assignment, the compiler requires that you confirm the assignment
with a typecast. This can be done, for example, by “squeezing” a long
value into an int variable. Explicit casting is done like this:
Long bigvalue=99L
Int small=(int)(bigvalue);

7) IN what ways does a switch statement differ from an if


statement?
Ans:-
As if statement can be used to make decisions based on range of
values or condition, whereas a switch statement can make decision
based only on a single integer value. Also, the value provided to
each case statement must be unique.

8) Compare in terms of their functions, the following pairs of


statement

a. while and do…………while


b. while and for
c. break and continue
Ans:-
a. while and do…………while
While ( )
{
}

The statement (s) with in while look shall executed again and again
till the conditions is TRUE.
The conditions shall be checked before entering the look – if true
the statement within look shall be executed if not the statement
after the loop shall be executed.

Do{
} while ( )
In the do while () loop, The statement within the loop executed
once, without checking the conditions.
After executing the statement within the loop the conditions shall
be checked .
If condition the true the statement within loop shall be executed
again.
If false control out of loop.

b. while and for


In the while statement, the loop body is executed only when the
condition stated in the statement is true.
Java provides the for statement as an efficient alternative to the
while statement.the for statement creates a loop in which a set of
statement is repeatedly executed until the specified condition
become false.

c. break and continue


We can force immediate termination of loop, by passing the conditional
expression and any remaining code in the body of the loop.
The continue statement stops the current iteration of a loop and
immediately starts the next iteration of the same loop. When the
current iteration of a loop stops, the statements after the continue
statement in the loop are not executed.

9) What is class? How does it accomplish data hiding?


Ans:-
Class is a template that defines a particular type of object. Classes
contain all the features of a particular set of objects. We can use the
class definition to create objects of that of class type, that is, to create
objects that incorporate all the features belonging to that class.
10) What are objects? How are they created from a class?
Ans:-
As with real world of object, softwhere object have state and
behavior. in programming terms the state of an object is determined
by its data (Variables); the behavior by its methods. Thus a softwhere
object combines data and methods into one unit.
The creating object to a class is two step process –
1. decleare a variable of class type. this variable
does not define an object instead it is a simply a
variable that can refer to an object.
2. physical copy of the object is created and
assigned to that variable.