ajp chapter 1 , 2 and 3 remember level (1 marks...

22
AJP chapter 1 , 2 and 3 Remember Level (1 marks questions) 1. When we invoke repaint() for a java.awt.Component object, the AWT invokes the method: A. paint() B. show() C. draw() D. update() Answer: A 2. What does the following line of code do? TextField text = new TextField(10); A. Creates the object text and initializes it with the value 10 B. Creates text object that can hold 10 columns of text C. Creates text object that can hold 10 rows of text D. The code is illegal Answer: B 3. The setBackground() method is a part of the following class in java.awt package: A. Container B. Applet C. Object D. Graphics 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 5. What are controls or components? a. Controls or components allow users to interact with application b. Controls or components do not allow users to interact with users c. Controls or components allow users to interact with users d. Controls or components allow application to interact with user

Upload: others

Post on 22-May-2020

1.593 views

Category:

Documents


90 download

TRANSCRIPT

Page 1: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

AJP chapter 1 , 2 and 3

Remember Level (1 marks questions)

1. When we invoke repaint() for a java.awt.Component object, the AWT invokes the method:

A. paint()

B. show()

C. draw()

D. update()

Answer: A

2. What does the following line of code do?

TextField text = new TextField(10);

A. Creates the object text and initializes it with the value 10

B. Creates text object that can hold 10 columns of text

C. Creates text object that can hold 10 rows of text

D. The code is illegal

Answer: B

3. The setBackground() method is a part of the following class in java.awt package:

A. Container

B. Applet

C. Object

D. Graphics

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

5. What are controls or components?

a. Controls or components allow users to interact with application

b. Controls or components do not allow users to interact with users

c. Controls or components allow users to interact with users

d. Controls or components allow application to interact with user

Page 2: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

Answer : A

6. What are the subclasses of the Container class?

a. Windows, Panel, ScrollPane

b. ScrollPane, Vector, String

c. Thread, Vector, String

d. Applet, InetAddress, Vector

Answer : A

7. Which object is needed to group Checkboxes to make them exclusive?

A. CheckboxGroup

B. Checkbox

C. RadioButton

D. TextField

Answer: A

8. Which class can be used to represent the Checkbox with a textual label that can appear in a menu?

A. MenuBar

B. MenuItem

C. CheckboxMenuItem

D. Menu

Answer: C

9. Which are various AWT controls from following?

A. Labels, Push buttons, Check boxes, Choice lists.

B. Text components, Threads, Strings, Servelts, Vectors

C. Labels, Strings, JSP, Netbeans, Sockets

D. Push buttons, Servelts, Notepad, JSP

Answer: A

10.JPanel and Applet use ___________________ as their default layout

A. FlowLayout

B. GridLayout

C. BorderLayout

D. GridBagLayout

Answer: A

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

12. Which of these methods cannot be called on JLabel object?

A. setIcon()

Page 3: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

B. getText()

C. setLabel()

D. setBorderLayout()

Answer: D

14. _____________ pane can be used to add component to container

A. GlassPane

B. CotentPane

C. Container

D. All of above

Answer: B

13. Which of the following is not a constructor of JTree

A. JTree(Object obj[])

B. JTree(TreeNode tn)

C. JTree(Vector v)

D. JTree(int x)

Answer: D

14. Swing Components are_______________________

A. Platform dependent

B. Platform Independent

C. Both a & b

D. Platform oriented

Answer: B

Understand Level Questions: (2 marks questions)

Q1. Which components are needed to get above shown output

A. TextField, Label

B. List, Button

C. Choice, Button

D. Button, TextField

Answer: B

Page 4: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

Q2. Which components are needed to get above shown output

A. Menu, MenuItem, MenuBar, Frame

B. List, Label, MenuItem

C. Choice, MenuItem, TextField

D. Label, Frame, Button

Answer: A

Q3. Which components are used in the following output?

Page 5: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

A. Label, TextField, Button

B. Applet, Label

C. Applet, Button

D. Grid Layout, Label, Button

Answer: A

Q4. What is the purpose of JTable?

A. JTable object displays rows of data.

B. JTable object displays columns of data.

C. JTable object displays rows and columns of data.

D. JTable object displays data in Tree form.

Answer: C

Q5. Which method is used to display icon on a component?

A. rollOverIcon( ImageIcon i)

B. setIcon(ImageIcon i)

C. displayIcon(ImageIcon i)

D. removeIcon (ImageIcon i )

Answer: B

Q6. What components will be needed to get following output?

A. Label, TabbedPane, CheckBox

B. TabbedPane, List, Applet

C. Panel, TabbedPane, List

D. Applet, TabbedPane, Panel

Answer: c

Page 6: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

Apply level questions(2 marks questions)

1. Debug the following program

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); } }

a. Error in statement in which JTable is created

b. Error in statement in which JScrollPane is created

c. Error in statement in which applet tag is declared

d. None of the above

Answer: a

2. Debug the given program so as to get the following output

import java.awt.*;

import javax.swing.*;

/*<applet code="test" width=200 height=200>

</applet>*/

public class test extends JApplet

Page 7: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

{

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);

}

}

A. JPanel p2=new JPanel();

JButton b3=new JButton("ELEC.ENGG");

B. JPanel p2=new JPanel();

JPanel p1=new JPanel();

C. /*<applet code="test" width=200 height=200>

</applet>*/

D. jp.addTab("Branch");

jp.addTab("Year");

Answer: B

Page 8: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

3. Observe the following code

import java.awt.*;

import java.applet.*;

public class LayoutDemo5 extends Applet

{

public void init()

{

int i,j,k,n=4;

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>*/

What will be the output of the above program?

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

4. Observe the following code

import java.awt.*; import javax.swing.*; public class test extends JFrame {

Page 9: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

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); } } Choose the correct output.

A.

B.

Page 10: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

C.

D. None of the above

Answer: C

5. Consider the program given below

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

Page 11: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

{ 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); } }

Choose the correct statement to get the following output

A. JComboBox jc=new JComboBox(“Applet Viewer:test”);

B. JComboBox jc=new JComboBox();

C. JComboBox jc=new JComboBox(“cricket”, “football”, “hockey”, “tennis”);

D. None of the above.

Answer: B

6. Read the following code

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);

Page 12: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

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>*/

What will be the color of the string?

A. Red

B. Blue

C. Green

D. Pink

Answer: A

Chapter 3(Remember Level)

7. URL is an acronym for?

a. Uniform Resource Locator b. Unified Resource Locator c. Uniform Restore Locator d. Unified Restore Locator ANSWER: Uniform Resource Locator

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 programs?

- a. ServerSockets

b. httpServer

c. httpResponse

d. None of the above

Page 13: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

ANSWER: ServerSockets

10) Which constructor of DatagramSocket class is used to creates a datagram socket and binds it

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)

11) Which methods are commonly used in ServerSocket class?

a. public OutputStream getOutputStream()

b. public Socket accept()

c. public synchronized void close()

d. None of the above

ANSWER: public Socket accept()

12) Which classes are used for connection-less socket programming?

a. DatagramSocket

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 manipulate

URL in Java?

a. java.net.URL

b. java.net.URLConnection

Page 14: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

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 programs?

a. ServerSockets

b. httpServer

c. httpResponse

d. None of the above

ANSWER: ServerSockets

15) Which package provides core functionality?

a. java.net

b. java.rmi

c. java.lang

d. java.math

Answer Explanation

16) The DatagramSocket and DatagramPacket classes are not used for connection-less socket

programming.

a. True

b. False

ANSWER: False

17) The client in socket programming must know which informations?

a. IPaddress of Server

b. Port number

Page 15: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

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 referred by

the URL

a. True

b. False

ANSWER: True

19) Datagram is basically an information but there is no guarantee of its content, arrival or arrival

time.

a. True

b. False

ANSWER: True

20) What does the java.net.InetAddress class represent?

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

Page 16: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

a. True

b. False

ANSWER: True

22) TCP,FTP,Telnet,SMTP,POP etc. are examples of ?

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 sockets?

a. The server instantiates a ServerSocket object, denoting which port number communication is to occur on

b. The server invokes the accept() method of the ServerSocket class. This method waits until a client connects

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 number

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()

b. public String getHostAddress()

c. public static InetAddress getLocalHost()

d. None of the above

ANSWER: public String getHostName()

Page 17: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

Chapter 3(Understand and Apply)

1. Find missing statement in the following client-server program.

MyServer.java

import java.io.*;

import java.net.*;

public class MyServer {

public static void main(String[] args){

try{

ServerSocket ss=new ServerSocket(6666);

__________________________________

DataInputStream dis=new DataInputStream(s.getInputStream());

String str=(String)dis.readUTF();

System.out.println("message= "+str);

ss.close();

}catch(Exception e){System.out.println(e);}

}

}

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);}

}

}

Page 18: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

a. Socket s=ss.accept();

b. ServerSocket ss=accept();

c. Socket s=new Socket("localhost",3333);

d. None

Answer: a

2. What will be the output of following program:

import java.io.*;

import java.net.*;

public class URLDemo{

public static void main(String[] args){

try{

URL url=new URL("http://www.javatpoint.com/java-tutorial");

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

Page 19: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

Answer : a

3. Find the missing statement in the following code:

import java.io.*;

import java.net.*;

public class URLConnectionExample {

public static void main(String[] args){

try{

URL url=new URL("http://www.javatpoint.com/java-tutorial");

------------------------------------------------------------------

InputStream stream=urlcon.getInputStream();

int i;

while((i=stream.read())!=-1){

System.out.print((char)i);

}

}catch(Exception e){System.out.println(e);}

}

}

a. URLConnection urlcon=new URLConnection();

b. URLConnection urlcon=url.openConnection();

c. URLConnection urlcon=url.getConnection();

d. URLConnection urlcon=openConnection();

Answer: b

4. Find and rectify the error in the following code

//DSender.java

import java.net.*;

public class DSender{

public static void main(String[] args) throws Exception {

DatagramSocket ds = new DatagramSocket();

String str = "Welcome java";

InetAddress ip = InetAddress.getByName("127.0.0.1");

DatagramPacket dp = new DatagramPacket(str.getBytes(), str.length(), ip, 3000);

ds.send(dp);

ds.close();

Page 20: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

}

}

//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);

Page 21: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

b.

byte[] buf = new byte[1024];

c.

DatagramPacket dp = new DatagramPacket(buf, 1024);

d.

DatagramPacket dp = new DatagramPacket(buf);

Page 22: AJP chapter 1 , 2 and 3 Remember Level (1 marks questions)mitpolytechnic.ac.in/downlaods/09_knowledge-bank/03_it/... · 2018-04-18 · AJP chapter 1 , 2 and 3 Remember Level (1 marks

Answer : c