Vidyalelo
Java Programming · all questions

Input Output
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

77

Questions

4/4

Page

Pick an option on a question to see the right answer and solution.

Which of these methods are used to read in from file?

Select an option to see the answer and solution.

Which of these values is returned by read() method is end of file (EOF) is encountered?

Select an option to see the answer and solution.

Which of these exception is thrown by close() and read() methods?

Select an option to see the answer and solution.

Which of these methods is used to write() into a file?

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.io.*;
class filesinputoutput
{
    public static void main(String args[])
    {
        InputStream obj = new FileInputStream("inputoutput.java");
        System.out.print(obj.available());
    }
}

Note: inputoutput.java is stored in the disk.

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.io.*;
public class filesinputoutput
{
  public static void main(String[] args)
    {
 String obj  = "abc";
       byte b[] = obj.getBytes();
       ByteArrayInputStream obj1 = new ByteArrayInputStream(b);
       for (int i = 0; i < 2; ++ i)
       {
           int c;
           while((c = obj1.read()) != -1)
           {
             if(i == 0)
               {
                 System.out.print(Character.toUpperCase((char)c));
                   obj2.write(1); 
             }
           }
           System.out.print(obj2);
       }
    }
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.io.*;
class Chararrayinput
{
    public static void main(String[] args)
    {
  String obj  = "abcdef";
        int length = obj.length();
        char c[] = new char[length];
        obj.getChars(0, length, c, 0);
        CharArrayReader input1 = new CharArrayReader(c);
        CharArrayReader input2 = new CharArrayReader(c, 0, 3);
        int i;
        try
        {
while((i = input2.read()) != -1)
            {
                System.out.print((char)i);
            }
        } 
        catch (IOException e)
        {
            e.printStackTrace();
  }
}
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.io.*;
class Chararrayinput
{
    public static void main(String[] args)
    {
  String obj  = "abcdefgh";
        int length = obj.length();
        char c[] = new char[length];
        obj.getChars(0, length, c, 0);
        CharArrayReader input1 = new CharArrayReader(c);
        CharArrayReader input2 = new CharArrayReader(c, 1, 4);
        int i;
        int j;
        try 
        {
while((i = input1.read()) == (j = input2.read()))
            {
                System.out.print((char)i);
            }
        } 
        catch (IOException e)
        {
            e.printStackTrace();
  }
}
}

Select an option to see the answer and solution.

Which of these functions is called to display the output of an applet?

Select an option to see the answer and solution.

Which of these methods can be used to output a string in an applet?

Select an option to see the answer and solution.

Which of these methods is a part of Abstract Window Toolkit (AWT) ?

Select an option to see the answer and solution.

Which of these modifiers can be used for a variable so that it can be accessed from any thread or parts of a program?

Select an option to see the answer and solution.

Which of these operators can be used to get run time information about an object?

Select an option to see the answer and solution.

What is the Message is displayed in the applet made by the following Java program?
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet
{
    public void paint(Graphics g)
    {
        g.drawString("A Simple Applet", 20, 20);    
    }
}

Select an option to see the answer and solution.

What is the length of the application box made by the following Java program?
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet
{
    public void paint(Graphics g)
    {
        g.drawString("A Simple Applet", 20, 20);    
    }
}

Select an option to see the answer and solution.

What is the length of the application box made the following Java program?
import java.awt.*;
import java.applet.*;
public class myapplet extends Applet
{
    Graphic g;
    g.drawString("A Simple Applet", 20, 20);    
}

Select an option to see the answer and solution.

What will be the output of the following Java program?
import java.io.*;
class Chararrayinput
{
    public static void main(String[] args)
    {
  String obj  = "abcdefgh";
        int length = obj.length();
        char c[] = new char[length];
        obj.getChars(0, length, c, 0);
        CharArrayReader input1 = new CharArrayReader(c);
        CharArrayReader input2 = new CharArrayReader(c, 1, 4);
        int i;
        int j;
        try
        {
while((i = input1.read()) == (j = input2.read()))
            {
                System.out.print((char)i);
            }
        } 
        catch (IOException e)
        {
            e.printStackTrace();
  }
}
}

Select an option to see the answer and solution.