java-based comprehensive title 1

First, the choice

1, a predetermined java code shown below, the runtime will produce () type of exception.

String s = null; 
s.equals(“abc”);

A) ArithmeticException
B) NullPointerExecption
C) IOException
D) ClassNotFoundException

The answer: B
// if the String s = ""; s.equals ( "abc"); is not being given, if S = null String;
s.equals ( "abc"); throws a NullPointerException

2, is given by the java program code fragment, underlined, was added () statement, can compile the code

public void  method1() throws  IOException{}
public   void   method2()________{ method1() }; 

Select two
A) throws IOException
B) throw IOException
C) throws Exception
D) throws RuntimeException

The answer: AC

3, the following exception handling certain sentence structureIncorrect的是( )
A) try{} catch(……){} finally{}
B) try{} catch(……){}
C) try{} finally{}
D)catch(……){} finally{}

Answer: D

4, the program creates a TCP service order is ()
A closed socket
B creates a server socket
C off I / O stream
D thread in the service, to obtain I / O from the socket stream
E to I / O read and write stream to complete the interaction with the customer
receiving socket G client connection request from the server

The answer: BGDECA

5, the following are all thread-safe class is ()
A.ArrayList
B.Vector
C.HashMap
D.Hashtable

The answer: BD
Vector is an old dynamic arrays, a thread synchronization (safety) and low efficiency, is now unsuitable for use.
ArrayList dynamic array is achieved, the scope of its functions, but is not synchronized with Vector (unsafe), it is only array implementation, allows random read element, the element is characterized by slow additions and deletions, look fast.
LinkList list structure is achieved, which allows random access, a class definition list can pass is used as stacks and queues. Order to provide the best access for inserting and removing elements, characterized by additions of elements fast, slow look.

HashMap is not thread-safe, it can not contain duplicate keys, but may contain duplicate values. HashMap allows null key and null value, but does not allow hashtable
HashTable are thread-safe
HashMap Hashtable is a lightweight implementation

6. Thread by () method can sleep for some time, then resume operation.
A. RUN
B. setPrority
C. yield
D. sleep

Answer: D

7, in java, the following options can be stored unordered, unique data is ()
A the ArrayList
B the LinkedList
C the HashMap
D the Set

Answer: D

8, compile and run the following java code, the output is correct ()

public class Test{
   LinkedList list = new LinkedList();
   list.add(“aaa”);
   list.removeFrist(); 
   list.removeLast();
   System.out.println(list.size());
}

A). 1
B) 0
C) operating abnormally
D) abnormality compiled

The answer: C
removeFrist () to remove the first element, list has no element of, removeLast () will throw an error
Exception in the Thread "main" java.util.NoSuchElementException
AT java.util.LinkedList.removeLast (Unknown Source)
AT Test20170424.Test.main (Test.java:10)

9. Choose the correct answer

import java.util.*;
public class TestListSet{
  public static void main(String args[]){
    List list = new ArrayList();
    list.add(“Hello”);
    list.add(“Learn”);
    list.add(“Hello”);
    list.add(“Welcome”);
    Set set = new HashSet();
    set.addAll(list);
    System.out.println(set.size());
  }
}

A) by the compiler is not
B) compiler, runtime exceptions
C) are compiled to run normally output. 3
D) are compiled to run normally, the output 4

Answer: C

10, choose the correct answer

public static Iterator reverse(List list) {
  Collections.reverse(list);
  return list.iterator();
 }
 
public static void main(String[] args) {
  List list = new ArrayList();
  list.add("1"); 
  list.add("2"); 
  list.add("3");
  for (Object obj: reverse(list)) 
  System.out.print(obj + ", ");
}

A). 3, 2,. 1,
B). 1, 2,. 3,
C) compilation fails.
D) run-time error.

Answer: C
// for (types of objects: the collection or array) {}

11, choose the correct answer

import java.util.*;
public class Example {
  public static void main(String[] args) {
    // insert code here
    set.add(new Integer(2));
    set.add(new Integer(1));
    System.out.println(set);
  }
}

Will which statements to be inserted into the line 4 in order to ensure the program output [. 1, 2]
A) the Set SET = new new TreeSet ();
B) the Map SET = new new the HashMap ();
C) the Set SET = new new the SortedSet ();
D) List set = new LinkedList ( );

Answer: A

12, the following statement about the Java Collections FrameworkerrorIt is ()
A) the set of the Java frame and Map Collection includes two
B) described in Collection set, describes the mapping Map
C) and Set List Collection includes two
inner elements disordered Set D), while the inner element ordered List, but the elements are not repeated

Answer: D

13, in the JAVA programming language network, URL class in the java.net package, this class provides many methods used to access a variety of resources URL object, following which the port number in the URL used to get ()

A) getFile()
B) getProtocol()
C) getHost()
D) getPort()

Answer: D

14, the flow of narrative about JavaerrorIs ()
A) flowing in the Java language handles I / O,
B) Conceptually, the byte sequence is a series of flow or sequence of characters
C) introduced the concept of the object of the process stream is such that the different data input output programming easier
D) is a Java stream only non-object-oriented language construct

Answer: D

15, the following statement regarding the File classIncorrectIs:
A) a File object representing the operating system a file or folder
B) can be created using a File object and delete a file
C) can be created using a File object and delete a folder
D) When a File object is garbage when recovered, the corresponding system files or folders are also deleted

Answer: D

16, JAVA language in the socket (the Socket) is a network based on process communication interface, an application is a network communication protocol. It has two main classes, which of the following functions to implement the communication client ()
A) the ServerSocket Class
B) URL Class
C) Socket Class
D) UDP

Answer: C

17, the following methods to create InputStreamReader object which is the right approach? () (Choice two)
A. the InputStreamReader new new (new new the FileInputStream ( "Data"));
B. the InputStreamReader new new (the FileReader new new ( "Data"));
C. the InputStreamReader new new (the BufferedReader new new ( "Data"));
D . new InputStreamReader (System.in);

Answer: the AD
new new the InputStreamReader () must be of type InputStream parameter (or a sub-class types, such as FileInputStream, and e.txt is a file (File), it can only read FileInputStream, rather than using DataInputstream, DataInputstream only read simple type of variable)

18, there is the following code:

public class TestFile{
  public static void main(String args[]){
    File file = new File(“chp13/corejava.txt”);
  }
}

Please select a correct answer :()
A) corejava.txt file is created in the system
B) running on a windows system error, incorrect because the path separator
C) corejava.txt file was not created in the system
D) If corejava .txt file already exists, an exception is thrown

The answer: C
new new File is to create a File object. Does not create the file.
General use file.exists () after the judge determines that the call createFile will create a file does not exist.
Create a directory or file, then use file.mkdir mkdirs

19, (target sequence) have the following code:

import java.io.*;

class Address{
  private String addressName;
  private String zipCode;
  //带参构造方法…
  //get/set 方法…
}

class Worker implements Serializable{
  private String name;
  private int age;
  private Address address;
  //带参构造方法…
  //get/set 方法…
}

public class TestSerializable {
  public static void main(String args[]) throws Exception{
     Address addr = new Address("Beijing", "100000");
     Worker w = new Worker("Tom", 18, addr);
     ObjectOutputStream oout = new ObjectOutputStream(new FileOutputStream("fout.dat"));
     oout.writeObject(w);
     oout.close();
   }
}

Choose the correct answer ()
A) The program compiler error
B) compile normal, run-time exceptions
C) compiler normal, run-time is also normal.
D) None of the above positive solution

The answer: B
// call other class object, the object class must be called together to achieve Serializable.
// So Address class should implement the Serializable interface
Exception in thread "main" java.io.NotSerializableException: Test20170424.Address

20, described below with respect to streamIncorrectIs ()
A) divided by the input flow and output streams
B) the input data stream represents the external read-in program
C) output stream represented by a program written to the external
D) to copy files written by an external external input and independent of output

Answer: D

21, the following code

public class Foo implements Runnable {
       public void run (Thread t) { 
              System.out.println("Running."); 
       }
       public static void main (String[] args) { 
              new Thread(new Foo()).start(); 
       }
} 

Execution result is ()
A) throw a runtime exception
B) programs to run, but no output
C) not Runnable interface implemented method results in a compilation error
after D) running output "Running"

Answer: C

22, the following blocks:

public class MyThread extends Thread {
public static void main(String args[]) {
   MyThread t = new MyThread();
   MyThread s = new MyThread();
   t.start();
   System.out.print("one.");
   s.start();
   System.out.print("two.");
}
   public void run() {
     System.out.print("Thread");
   }
}

The following is the correct option ()
A) fail to compile
B) as a result of the program: one.Threadtwo.Thread
C) result of the program are: one.two.ThreaThread
D) programs operating results uncertain

Answer: D

23, I have the following code

public class Example implements Runnable {
    public void run() {
      while(true) {
      
     }
  }
public static void main(String args[]) {
    Example ex1 = new Example();
    Example ex2 = new Example();
    Example ex3 = new Example();
    ex1.run();
    ex2.run();
    ex3.run();
  }
}

Select the correct answer:

A) code compilation fails because ex2.run () can not obtain the execution
B) the code compiles successfully, there are three threads can run
C) code compilation is successful, there is a runnable threads
D are not) more than correct

Answer: C

24, the following codes

public class Example {
  public static void main(String args[]) {
      Thread.sleep(3000);
      System.out.println(“sleep”);
    }
}

Select the correct answer:

A) compiler errors
B) when an abnormal operation
C) Normal operation of the compiler, the output SLEEP
D) compile and run normally, but no content output

The answer: A
// no exception handling

25, I have the following code

public class Example implements Runnable {
   public static void main(String args[]) {
     Thread t = new Thread(new Example());
     t.start();
}

public void run(int limit) {
   for (int x = 0; x<limit; x++) {
      System.out.println(x);
    }
  }
}

Select the correct answer:
A) a printout, from 0 to limit
B) code compilation fails, removal of implements Runnable, success can compile the code.
C) code compilation fails because there is no proper implement Runnable
D) code compilation fails, if the class is declared abstract class that allows the code to compile successfully.

Answer: C

Second, fill in the blank

1, Java programming multi-threaded applications, there are two ways: one is to create a thread subclasses () class, and the other is to use the Thread class combination () interface to create threads.

Thread、Runnable

2, when a thread is in () state, it is just an empty thread object, the system does not allocate resources for it. A thread being executed may be artificially interrupted, so that the use of the CPU, to suspend their execution, enter () state. In () state of the thread does not have the ability to continue to run.

Create, obstruction, death

3, after a try statement block must be followed () statement block () statement can not block, custom exception class must inherit () class and its subclasses, exception handling mechanism allows the selection process where the abnormality depending on the circumstances, can be captured and processed in (), you can also use throws clause to hand him over () processing.

catch, finally, Exception, try ... catch, the caller

4, in the set () is a key structural mapping () is an ordered set of repeatable, () unordered not be repeated.

Map、List、Set

5, the abnormality into () and abnormal () abnormalities, () with the exception root class class.

Compile, run, Exception

6, each computer on the Internet must be able to uniquely identify it, so the first part is standardized () address, () can determine the network address unique data, () class is used to create server-side communication objects, ( ) class is used to create turbulence in the communication target customers.

IP、URL、ServerSocket、Socket

Third, the Problem

1, the outlined implementation class distinction List ArrayList and the LinkedList.
1.ArrayList is based on an array, LinkedList list based implementation.
2. For random access get and set, ArrayList feel better than LinkedList, because LinkedList to move the pointer.
3. For new and delete operations add and remove, LinedList comparative advantage, because ArrayList to move data.

2, please describe the byte stream and character stream you understand
1. All byte stream are subclasses of InputStream and OutputStream, mainly used in the binary data, which is processed byte by byte.
2. All character stream are subclasses FileReader and FileWriter, mainly used in processing the text data, which is handled by character.

3. RuntimeException RuntimeException brief and non-difference of.
1, RuntimeException abnormal at compile time will not be given a warning, but occurs at runtime, such as type of transformation exception.
2, also known as non compile RuntimeException exceptions, exceptions that occur in the process of writing program, is an exception must be dealt with, such as: Class.forName ( "");

4, multi-threaded brief life cycle
Thread life cycle can be divided into five states:
. 1, New (newborn)
2, READY (READY)
. 3, the Runnable (run): For analytical purposes, it may be divided into: the Runnable and Running.
4, blocked (blocked)
5, Dead (death)
with someone who has the same illness and death, the thread is also beginning to experience (wait), ready to run, suspend and stop five different states. This five states can be controlled by the method of the Thread class

5, outlining your understanding of network communication
The network is connected to the respective physical links isolated host workstation or together to form a data link, so as to achieve the purpose of resource sharing and communication. Information exchange and communication is carried out between people passing through some medium. Communications network is isolated the respective devices connected via a network, for communication between people, people with a computer, the computer and the computer via the exchange of information.

Published 35 original articles · won praise 24 · views 60000 +

Guess you like

Origin blog.csdn.net/thumbs_up_sign_ygj/article/details/104983503