Professional Documents
Culture Documents
Answer: A
Answer: B
Answer : D
4. Which of the following methods can be used to remove java.awt.Componenr object from
display?
A. hide()
B. disappear()
C. remove()
D. delete()
Answer: C
A. MenuBar
B. MenuItem
C. CheckboxMenuItem
D. Menu
Answer: C
11. Which of the following is true about AWT and Swing Component
A. AWT Components Create a process where as Swing Component create a thread
B. AWT Components Create a thread where as Swing Component create a process
C. Both AWT and Swing Component create a process
D. Both AWT and Swing Component create a thread
Answer: A
Answer: A
Answer: A
Answer: C
A. rollOverIcon( ImageIcon i)
B. setIcon(ImageIcon i)
C. displayIcon(ImageIcon i)
D. removeIcon (ImageIcon i )
Answer: B
Answer: c
Apply level questions(2 marks questions)
import java.awt.*;
import javax.swing.*;
/*
<applet code="JTableDemo" width=400 height=200>
</applet>
*/
public class JTableDemo extends JApplet
{
public void init() {
Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
final String[] colHeads = { "emp_Name", "emp_id", "emp_salary" };
final Object[][] data = {
{ "Ramesh", "111", "50000" },
{ "Sagar", "222", "52000" },
{ "Virag", "333", "40000" },
{ "Amit", "444", "62000" },
{ "Anil", "555", "60000" },
};
JTable table = new JTable(data);
int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
JScrollPane jsp = new JScrollPane(table, v, h);
contentPane.add(jsp, BorderLayout.CENTER);
}
}
Answer: a
import java.awt.*;
import javax.swing.*;
/*<applet code="test" width=200 height=200>
</applet>*/
public class test extends JApplet
{
public void init()
{
Container c=getContentPane();
JTabbedPane jp=new JTabbedPane();
JButton b1=new JButton("COMP.TECH");
p1.add(b1);
JButton b2=new JButton("INFO.TECH");
p1.add(b2);
JButton b3=new JButton("ELEC.ENGG");
p1.add(b3);
JButton b4=new JButton("FIRST");
p2.add(b4);
JButton b5=new JButton("SECOND");
p2.add(b5);
JButton b6=new JButton("THIRD");
p2.add(b6);
jp.addTab("Branch",p1);
jp.addTab("Year",p2);
c.add(jp);
}
}
setLayout(new BorderLayout());
Panel p1=new Panel();
Panel p2=new Panel();
p1.setLayout(new FlowLayout());
p1.add(new TextField(20));
p1.add(new TextField(20));
p2.setLayout(new GridLayout(5,3));
p2.add(new Button("OK"));
p2.add(new Button("Submit"));
add(p1,BorderLayout.EAST);
add(p2,BorderLayout.WEST);
}
}
/*<applet code=LayoutDemo5.class width=300 height=400>
</applet>*/
A. The output is obtained in Frame with two layouts: Frame layout and Flow Layout.
B. The output is obtained in Applet with two layouts: Frame layout and Flow Layout.
C. The output is obtained in Applet with two layouts: Frame layout and Border Layout.
D. The output is obtained in Applet with two layouts: Border layout and Flow Layout.
Answer: D
import java.awt.*;
import javax.swing.*;
public class test extends JFrame
{
public test()
{
super("Login Form");
Container cpane=getContentPane();
cpane.setLayout(new FlowLayout());
JLabel l1=new JLabel("Name");
JLabel l2=new JLabel("Password");
JTextField t1=new JTextField(20);
JTextField t2=new JTextField(20);
JButton b1=new JButton("Login");
JButton b2=new JButton("Cancel");
cpane.add(l1);
cpane.add(t1);
cpane.add(l2);
cpane.add(t2);
cpane.add(b1);
cpane.add(b2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String args[])
{
test obj=new test();
obj.setVisible(true);
obj.setSize(200,200);
}
}
A.
B.
C.
Answer: C
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.applet.*;
/*
<applet code="test" width=300 height=100>
</applet>
*/
public class test extends JApplet
{
public void init()
{
Container co = getContentPane();
co.setLayout(new FlowLayout());
JComboBox jc=new JComboBox();
jc.addItem("cricket");
jc.addItem("football");
jc.addItem("hockey");
jc.addItem("tennis");
co.add(jc);
}
}
Answer: B
import java.applet.*;
import java.awt.*;
import java.awt.event.*;
public class test extends Applet
{
Font f;
Color c;
public void init()
{
f=new Font("Times New Roman",Font.ITALIC,48);
setFont(f);
c=new Color(255,000,000);
setForeground(c);
}
public void paint(Graphics g)
{
g.drawString("Hello",100,250);
}
}
/*<applet code =test width =90 height=50></applet>*/
Answer: A
8. URL stands for Uniform Resource Locator and represents a resource on the
World Wide Web, such as a Web page or FTP directory.
- Published on 15 Jul 15
a. True
b. False
ANSWER: True
9. Which class is used to create servers that listen for either local client or remote client progr
- a. ServerSockets
b. httpServer
c. httpResponse
d. None of the above
ANSWER: ServerSockets
10) Which constructor of DatagramSocket class is used to creates a datagram socket and bind
with the given Port Number?
- Published on 15 Jul 15
a. DatagramSocket(int port)
b. DatagramSocket(int port, InetAddress address)
c. DatagramSocket()
d. None of the above
ANSWER: DatagramSocket(int port, InetAddress address)
b. DatagramPacket
c. Both A & B
d. None of the above
ANSWER: Both A & B
13) Which method of URL class represents a URL and it has complete set of methods to manip
URL in Java?
a. java.net.URL
b. java.net.URLConnection
c. Both A & B
d. None of the above
ANSWER: java.net.URL
14) Which class is used to create servers that listen for either local client or remote client prog
a. ServerSockets
b. httpServer
c. httpResponse
d. None of the above
ANSWER: ServerSockets
b. java.rmi
c. java.lang
d. java.math
Answer Explanation
16) The DatagramSocket and DatagramPacket classes are not used for connection-less socke
programming.
a. True
b. False
ANSWER: False
a. IPaddress of Server
b. Port number
c. Both A & B
d. None of the above
ANSWER: Both A & B
18) The URLConnection class can be used to read and write data to the specified resource ref
the URL
a. True
b. False
ANSWER: True
19) Datagram is basically an information but there is no guarantee of its content, arrival or arri
time.
a. True
b. False
ANSWER: True
a. Socket
b. IP Address
c. Protocol
d. MAC Address
ANSWER: IP Address
21) The flush() method of PrintStream class flushes any uncleared buffers in memory
a. True
b. False
ANSWER: True
a. Socket
b. IP Address
c. Protocol
d. MAC Address
ANSWER: Protocol
23) Which steps occur when establishing a TCP connection between two computers using soc
a. The server instantiates a ServerSocket object, denoting which port number communication is to occ
b. The server invokes the accept() method of the ServerSocket class. This method waits until a client c
to the server on the given port
c. After the server is waiting, a client instantiates a Socket object, specifying the server name and port
to connect to
d. All of the above
ANSWER: All of the above
24) In InetAddress class which method returns the host name of the IP Address?
a. public String getHostName()
MyClient.java
import java.io.*;
import java.net.*;
public class MyClient {
public static void main(String[] args) {
try{
Socket s=new Socket("localhost",6666);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
dout.writeUTF("Hello Server");
dout.flush();
dout.close();
s.close();
}catch(Exception e){System.out.println(e);}
}
}
a. Socket s=ss.accept();
b. ServerSocket ss=accept();
c. Socket s=new Socket("localhost",3333);
d. None
Answer: a
System.out.println("Protocol: "+url.getProtocol());
System.out.println("Host Name: "+url.getHost());
System.out.println("Port Number: "+url.getPort());
System.out.println("File Name: "+url.getFile());
}catch(Exception e){System.out.println(e);}
}
}
a) Protocol: http
Host Name: www.javatpoint.com
Port Number: -1
File Name: /java-tutorial
b)
Protocol: http
Host Name: www. java-tutorial.com
Port Number:0
File Name: /java-tutorial
c) Protocol: https
Host Name: www. java-tutorial.com
Port Number:
File Name: /java-tutorial
d) Protocol: http
Host Name: javatpoint
Port Number:0
File Name: /java-tutorial
Answer : a
//DReceiver.java
import java.net.*;
public class DReceiver{
public static void main(String[] args) throws Exception {
DatagramSocket ds = new DatagramSocket(3000);
byte[] buf = new byte[1024];
DatagramPacket dp = new DatagramPacket(1024);
ds.receive(dp);
String str = new String(dp.getData(), 0, dp.getLength());
System.out.println(str);
ds.close();
}
}
a.
ds.send(dp);
b.
c.
d.
DatagramPacket dp = new DatagramPacket(buf);
Answer : c