1.
What are the different identifier states of a Thread?
The different identifiers of
a Thread are: R - Running or runnable thread, S - Suspended thread, CW - Thread
waiting on a condition variable, MW - Thread waiting on a monitor lock, MS -
Thread suspended waiting on a monitor lock
2.
What is wrapper class Java?
The primitive data types are not objects; they do not belong to any class; they are defined in the language itself. Sometimes, it is required to convert data types into objects in Java language. For example, upto JDK1.4, the data structures accept only objects to store. A data type is to be converted into an object and then added to a Stack or Vector etc. For this conversion, the designers introduced wrapper classes.
Def:
As the name says, a wrapper
class wraps (encloses) around a data type and gives it an object appearance.
Wherever, the data type is required as an object, this object can be used.
Wrapper classes include methods to unwrap the object and give back the data
type. It can be compared with a chocolate. The manufacturer wraps the chocolate
with some foil or paper to prevent from pollution. The user takes the
chocolate, removes and throws the wrapper and eats it.
3.
Write an applet program to change the background color and font.
import java.awt.*;
import java.applet.*;
public class font1 extends Applet
{
public void paint(Graphics g)
{
String
s1=new String("Font & Color Changes");
g.setColor(Color.red);
Font f1=new
Font("Arial",Font.PLAIN,16);
g.setFont(f1);
g.drawString(s1,50,50);
g.setColor(Color.blue);
Font f2=new
Font("Arial",Font.BOLD,20);
g.setFont(f2);
g.drawString(s1,50,150);
g.setColor(Color.green);
Font f3=new
Font("Arial",Font.ITALIC,24);
g.setFont(f3);
g.drawString(s1,50,250);
}
}
4.
Write the difference between C, java and C++.
There is a lot of difference between C++ and Java but there
has been a misconception among several people that both Java and C++ are object
oriented language and there is hardly any difference between the two. Let us
look at the major differences between these 2 languages. Let us look at the
differences between the two languages:
C++ is object based language while Java is a pure
object oriented language.C++ makes use of pointers to address memory locations while Java doesn't allows pointers, rather it manages all the memory handling tasks by itself, thus freeing the user from memory handling complexities and provides security.
In C++, if value of one variable is changed then the change in value of that variable is reflected in other areas also where that variable is used, whereas, Java ensures that if value of one variable has been changed in one area then in other area the change is not reflected.
C++ is confined to a particular system and thus the object code generated by the compiler of C++ can't be used on other machines, whereas, Java is a portable language that allows execution of the code on any machine where JVM (Java Virtual Machine) is installed.
C++ is not a secure language and may contain malicious code, whereas, Java is a secure language that uses a Bytecode verifier to make sure that code doesn't contain malicious code within it.
C++ can't be used on distributed systems and also, it can't be used over the web, whereas, Java can be run on distributed systems and over the web.
In C++ we first include a preprocessor and then proceed to the main function, whereas, in Java no such thing is done, everything is done within the class.
C++ supports multiple inheritance, whereas, java doesn't support multiple inheritance as it leads to ambiguity.
C++ defines GOTO keyword and also supports its usage, whereas, Java has a GOTO keyword but doesn't allow its usage.
Operating overloading is a prominent feature of C++, whereas, Java doesn't support operator overloading.
In C++ garbage collection is done manually, whereas, in Java garbage collection is done automatically.
Java has built-in multithreading process, whereas, C++ has no such process.
In Java you can't have "inline" methods but as an alternative option we have "final" keyword.
In Java you can't specify public, private and protected inheritance as in C++ and the overridden methods in a derived class cannot change the access of the method in the base class.
5.
What is an object referencing? Give a demo program.
class test
{
int a,b;
test(int i,int j)
{
int a=i;b=j;
}
void meth(test o)
{
o.a*=2;
o.b/=2;
}
}
class callbyref
{
public static void main(String args[])
{
test ob=new test(15,20);
System.out.println("Before call,
a ="+ob.a+" b= "+ob.b);
ob.meth(ob);
System.out.println("After call,
a ="+ob.a+" b= "+ob.b);
}
}
|
When an object reference is passed to a method, the
reference itself is passed by use of call – by – value. However, since the
value being passed refers to an object, the copy of that value will still
refer to the same object that it’s corresponding arguments does.
NB:-When a simple type is passed to a method, it is done by
use of call – by – reference.
|
No comments:
Post a Comment