0

Java Basics

Description: Concept based questions Java Basics
Number of Questions: 15
Created by:
Tags: Concept based questions Java Basics
Attempted 0/15 Correct 0 Score 0

Which of the following statements is/are valid to create a server socket?

  1. ServerSocket s1 = new ServerSocket(25);

  2. ServerSocket s1 = new ServerSocket(8000);

  3. ServerSocket s1 = new ServerSocket(80);

  4. Both (1) and (3)

  5. ServerSocket s1 = new ServerSocket(21);


Correct Option: B
Explanation:

To establish a server, you need to create a server socket and attach it to a port, which is where server listens for the connections. The port numbers are ranged from 0 to 65536, but port numbers 0 to 1024 are reserved for privileged services.The syntax to create a server socket is: ServerSocket objectname = new ServerSocket(port);

Which of the following exceptions is thrown by the Java compiler when we try to create a server socket on a port which is busy?

  1. Java.net.BindException

  2. Java.net.BusyPortException

  3. Java.net.UnknownHostException

  4. Java.net.PortNotFoundException

  5. Java.net.PortBusyException


Correct Option: A
Explanation:

In Java network programming, the server creates a server socket on which it listens to the connections of the client. The syntax to create a server socket is: ServerSocket objectname = new ServerSocket(port);

In Java network programming, which of the following statements is/are used by the client to request a connection to the server?

  1. Socket s1 = new Socket(“130.12.23.24”,8000);

  2. Socket s1 = new Socket(130.12.23.24,8000);

  3. Socket s1 = new Socket(“darke.armstrong.edu”,8000);

  4. Only 1 and 3

  5. 1, 2 and 3


Correct Option: D
Explanation:

This is the correct choice.

Which of the following methods is used to get the number of columns in a table?

  1. getColumnCount()

  2. getColCount()

  3. getCols()

  4. getColsCount()

  5. getColumns()


Correct Option: A
Explanation:

This is the correct answer.

In Java network programming, which of the following methods is/are defined in “InetAddress” class?

  1. getHostName();

  2. getHostAddress();

  3. getHostType();

  4. Both (1) and (3)

  5. Both (1) and (2)


Correct Option: E
Explanation:

This is a correct choice.

Which of the following methods is used to get the maximum number of columns that we can create in a table in Java database programming?

  1. getMaxColumnsInTable()

  2. getMaxCols()

  3. getMaxColsInTable()

  4. getMaxColumns()

  5. getCols()


Correct Option: A
Explanation:

This is the correct answer.

Which of the following is correct about the given statement?


Colour c1 = new Colour(284,60,189);

  1. A new colour will be created.

  2. runtime Exception

  3. Parameters are not enough.

  4. Compile time error : cannot find method colour

  5. Compile time error : Colour is abstract cannot create an object


Correct Option: B
Explanation:

This is the correct answer.

Which of the following methods is/are present in DatabaseMetadata interface in Java database programming?

  1. getUserName()

  2. getMaxTableNameLength()

  3. getMaxColumnsInTable()

  4. Only 2 and 3

  5. 1, 2 and 3


Correct Option: E
Explanation:

This is the correct answer.

Which of the following methods is present in ResultSetMetadata interface?

  1. getDriverVersion()

  2. getDriverMajorVersion()

  3. getDriverName()

  4. getUserName()

  5. getColumnCount()


Correct Option: E
Explanation:

This is the correct answer.

In Java networking, when a client socket cannot find a server, which of the following exceptions is thrown?

  1. Java.net.BindException

  2. Java.net.UnknownHostException

  3. Java.net.ServerNotFoundException

  4. Java.net.UnknownServerException

  5. Java.net.NoServerFoundException


Correct Option: B
Explanation:

The syntax to create a socket by client to find a server is: Socket s1 = new Socket(“server name”,portnumber);

Which of the following methods is/are used by the web browser to control the applet?

class BitShift
 {
 public static
void main(String [] args)
 {
 int x = 0x80000000;
 System.out.
print(x + " and ");
 x = x >>> 31;
 System.out.
println(x);
 }
 }

  1. Wait()

  2. Destroy()

  3. Dead()

  4. Both (1) and (3)

  5. Both (1) and (2)


Correct Option: D
Explanation:

This option is correct.

Which of the following methods will be used to execute the above SQL query in Java database programming?

String s = Select firstname, lastname from Employee;

  1. executeQuery(s);

  2. executeUpdate(s);

  3. executeStatement(s);

  4. executeString(s);

  5. execute(s)


Correct Option: A
Explanation:

This is the correct answer.

Which of the following methods cannot be invoked from the instance of frame class in AWT?

public class If2
{
 static boolean b1, b2;
 public static void main(String [] args)
 {
 int x = 0;
 if ( !b1 ) /* Line 7 */
 {
 if ( !b2 ) /* Line 9 */ { b1 = true;
 x++; if ( 5 > 6 )
 {
 x++;
 }
 if ( !b1 ) x = x + 10;
 else if ( b2 = true ) /* Line 19 */ x = x + 100;
 else if ( b1 | b2 ) /* Line 21 */ x = x + 1000;
 }
 } System.out.println(x);
 }
 }

  1. setLocation(int, int)

  2. setVisible(Boolean)

  3. setSize(int, int)

  4. setDefaultCloseOperation(int)

  5. Pack()


Correct Option: D
Explanation:

This is the correct answer.

Which of the following methods is not necessary to define a class if it implements the windowListener interface?

public void test(int x)
{
int odd = 1;
if(odd)
{
System.out.println("odd");
}
else
{
 System.out.println("even");
 }
 }

  1. windowMoved()

  2. windowClosing()

  3. windowIconified()

  4. windowActivated()

  5. windowDeiconified()


Correct Option: A
Explanation:

This option is correct.

Which of the following event types is invalid in Java?

class Equals
 {
 public static
void main(String [] args)
 {
 int x = 100;
 double y = 100.1;
 boolean b = (x = y);
 /* Line 7 */ System.out.println(b);
 }
}

  1. FocusEvent

  2. ComponentEvent

  3. AdjustmentEvent

  4. WindowEvent

  5. ExceptionEvent


Correct Option: E
Explanation:

This is the correct choice.

- Hide questions