Java Language Programming Basics Tutorial Exercises Study Questions Reference answers

Source: Internet
Author: User
Tags control characters naming convention

The basic course of Java language programming

Practice Study Questions Reference answers

1th Chapter Java Programming Overview 1.9 Practice Study Questions

1, the Java running platform includes three versions, please select the correct three: ()

A. Java EE B. j2me

C. J2SE D. j2e

Answer: A,b,c

2. The Decompile tool in the Java JDK is: ()

A. Javac B. java

C. Jdb D. Javap

Answer: D

3. The parameter description of the public static void Main method is: ()

A. String args[] B. string[] Args

C. Strings args[] D. String args

Answer: A,b

4, in Java, about the CLASSPATH environment variable is not correct: ()

A. Classpath once set is not modifiable, but you can add a directory to the environment variable.

B. Compilers can search for their own class files.

C. Classpath is a directory listing.

D. It is the interpreter that searches for the respective class file.

Answer: A

5, the compilation Java application source file will produce the corresponding bytecode file, the extension is ()

A.. Java B.. Class

C.. html D.. Exe

Answer: B

6, the development and operation of Java programs need to go through the three main steps for ____________, ____________ and ____________.

7. If a Java applet source program file only defines a class that has a class name of MyApplet, the class MyApplet must be a subclass of the _ _ class and the file name for storing the source program file is ___.

8. If there are 3 classes defined in a Java applet program file, compiling the source program file with Sun's JDK compiler will produce a bytecode file with the same name and an extension of ___.

9, development and running Java programs need to go through which major steps and procedures.

10, Java program is composed of what. Do you have to have a public class in a program? What is the naming convention for Java source files?

11. Write a simple Java application that prints two lines of text in the Command line window: "Hello, very happy to learn Java" and "We are students". The 2nd Chapter Java BASIC programming Structure 2.7 Practice Study Questions

1, from the following options, select three valid identifiers: ()

A. Idolikethelongnameclass B. $byte

C. Const D. _OK

E. 3_case

Answer: A,b,d

2, which of the following is an illegal identifier in Java. ( )

A. $user

B. Point

C. You&me

D. _endline

Answer: C

3, the following does not belong to the Java reserved words are: ()

A. sizeof

B. Super

C. Abstract

D. Break

Answer: A

4. Which of the following Java statements can cause an infinite loop? (      )

I, while (true) i = 0;

II, while (false) i = 1;

III, while (!false) i = 0;

A, only III

B, I and III

C, just I

D, I, II and III

Answer: B

5, the following integer data types, the need for the least memory space is ().

A. Short B. Long

C. int D. Byte

Answer: D

6, the following code execution, the correct output results are: ()

public class Example {

public static void Main (String args[]) {

int l = 0;

do {

System.out.println ("Doing it for L is:" + L);

while (--l > 0);

System.out.println ("Finish");

}

}

A. Doing it for L is 3

B. Doing it for L-is 1

C. Doing it for L is 2

D. Doing it for L is 0

E. Doing it for L? C1

F. Finish

Answer: D,f

7, if there is a definition of int a=1,b=2; Then the value of the expression (a++) + (++B) is: ()

A. 3 B. 4

C. 5 D. 6

Answer: B

8, if there is a definition of int a=9,b=6; Then the value of the A>b is: ()

A. 0 B. 1

C. False D. True

Answer: D

9, assuming that there is a variable definition: int k=7,x=12; Then the expression that makes the value 3 is: ()

A. x%= (k%=5) B. x%= (k-k%5)

C. x%=k-k%5 D. (x%=k)-(k%=5)

Answer: D

10, after the execution of the following code int[] x = new INT[25], the following instructions are correct: ()

A. X[24] is not defined as 0 B. x[24]

C. x[25] is null for 0 D. x[0]

Answer: A

11. The following statement is in the main method of the Java application, and the result of the output is ().

Int[] x={2,3,-8,7,9};

int max=x[0];

for (int i=1;i<x.length;i++) {

if (X[i]>max)

Max=x[i];

}

SYSTEM.OUT.PRINTLN (max);

A. 2 B.-8

C. 7 D. 9

Answer: D

12, set x = 1, y = 2, z = 3, then the value of the expression Y+=z--/++x is ()

A. 3 B. 3.5

C. 4 D. 5

Answer: A

13, Integer array: int[] x={2,33,88,5,10}, then the method Arrays.sort (x) is invoked, and the element values in the array x are sequentially. ( )

A. 88 33 10 5 2

B. 2 5 10 33 88

C. 88 10 2 33 5

D. 5 33 2 10 88

Answer: b

14, the following statements have the wrong is: ()

A. int []a; B. int []b=new int[10];

C. int c[]=new int[]; D. int d[]=null;

Answer: C

15, the following statements have the wrong is: ()

A. int a[][]=new int[5][5]; B. int [][]b=new int[5][5];

C. int []c[]=new int[5][5]; D. int [][]d=new int[5,5];

Answer: D

16, about the following procedure, the correct conclusion is ___.

public class ex4_7{

public static void Main (String args[]) {

int a[]=new int[5];

Boolean b[]=new boolean[5];

System.out.print (a[1]);

System.out.println (b[2]);

}

}

A. The result of the operation is 0false B. Operation result is 1true

C. The program cannot compile D. Can be compiled but the result is uncertain

Answer: A

17, in the Java Basic data type, the char uses the Unicode encoding scheme, each Unicode code occupies the ___ bytes memory space, thus, whether is the Chinese character or the English characters, is occupies the ___ bytes memory space.

18. Set x = 2, the value of the expression (x + +)/3 is ___.

19, if x = 5,y = 10, then the logical values of x < y and x >= y are ___ and ___ respectively.

20, with the definition of the array:

int myintarray[] = {10, 20, 30, 40, 50, 60, 70};

The output after executing the following statements is:.

int myintarray[] = {10, 20, 30, 40, 50, 60, 70};

int s = 0;

for (int i = 0; i < myintarray.length; i++)

if (i% 2 = 1)

s + + myintarray[i];

System.out.println (s);

21, the length of the array object after the array object is created, you can get a change. The subscript of an array element always starts with ___.

22, for the array int[][]t={{1,2,3},{4,5,6}}, T.length equals ______,t[0].length equals ___.

23, given Group A is defined as "int a[]={1,2,3,4,5};", then a[2]=______, the definition of array b is "int b[]=new int[5];", then b[2]=______, array c is defined as "Object []c=new OBJECT[5]; ", then c[2]=______.

24. When you call an array element, you use ___ and ___ to uniquely determine the elements in the array.

25, what is an array. What are the characteristics of the array. What steps are needed to create an array in Java. How to access the first element of an array.

26, the program calculates the square value of the integer of 10~20, and saves the result in an array.

27. Write a program that reads 10 integers from the keyboard into an integer array A and then outputs the 10 integers in reverse order.

28. A person has 5 3 points and 4 5 stamps, please write a program to calculate how many different postage rates can be obtained from 1 or several of these stamps.

29, the analysis of the following procedures to complete the function.

public class Sun {

public static void Main (String args[]) {

Double sum = 0.0;

for (int i = 1; I <= i++)

Sum + + 1.0/(double) I;

System.out.println ("sum=" + sum);

}

}

30. Write a Java application program with a character interface that accepts the 10 integers entered by the user and outputs the maximum and minimum values of the 10 integers.

31, if China's economy to maintain a steady growth rate of 10% per year, please write a program to calculate how much each year, how many years can be achieved to double the total amount.

Class exa4_1{

public static void Main (String args[]) {

int a=0;

Double i=0.10,sum=1;

while (sum<=4) {

Sum= (i+1) *sum;

a++;

System.out.println ("The First" +a+ "year to reach" +sum);

}

SYSTEM.OUT.PRINTLN ("Need" +a+ "the Year realizes twice");

}

}

3rd Chapter class and Object 3.9 practice Study Questions

1, the following about the variables of the narrative which is wrong. ( )

A. An instance variable is a member variable of a class.

B. Local variables defined in a method are created when the method is executed.

C. Instance variables are declared with a keyword static.

D. Local variables must be initialized before they are used.

Answer: C

2. In the Java language, which of the following packages is automatically imported by the compiler. ( )

A. Java.applet B. Java.lang

C. java.io D. java.awt

Answer: b

3. When a member of a class does not use an access modifier, Java considers the access rights of this member to be ().

A. Private B. Protected

c.friendly D.public

Answer: C

4. Which of the following keywords is not used to control access to class members. (     )

A. Public B. Protected

C. Default D. Private

Answer: C

5. Which of the following features is not the main object of object-oriented programming ().

A. Packaging B. Inherited

C. Polymorphism D. Class

Answer: C

6. The access control characters that are not allowed as classes and members of classes are ().

A. Public B. Private

C. Static D. Protected

Answer: C

7, for a class AB without the form of a return value method methods to write method headers, so that the class name AB as a prefix can be invoked, the method header in the form of ().

A, static void Method () B, public void Method ()

C, Final void method () D, abstract void Method ()

Answer: A

8, can be written in the following code section point x is. ( )

Point x

public class interesting{

Do something

}

A. String str;

B. static int pi=3.14;

C. public class myclass{//do the other thing ...}

D. Import java.awt.*;

Answer: D

9, the following about the variables of the narrative which is wrong. ( )

A, the instance variable is a member variable of the class.

B, the local variable defined in the method is created when the method is executed.

C, the instance variable is declared with the keyword static.

D, local variables must be initialized before they are used.

Answer: C

10, which of the following class declarations are correct. ( )

A, abstract final class hi{}

B, abstract private Move () {}

C, protected private number;

D, public abstract class car{}

Answer: D

11. A class is known to be packaged in Packagea, Class B is packaged in Packageb, and Class B is declared public, and a member variable x is declared as protected control mode. Class C is also located in the Packagea package and inherits Class B. The following statement is correct: ()

Instances of Class A and a are not accessible to instances of Class B

B, Class A can access to the X member of an instance of Class B

Instances of Class C and C can access an X member of an instance of Class B

Instances of class D and C cannot be accessed to instances of Class B

Answer: C

12. The following propositions are true: ()

A, all classes must define a constructor.

B, the constructor must have a return value.

C, the constructor can access non-static members of the class.

D, constructors must initialize all data members of the class.

Answer: C

13, in Java, the final keyword on the statement that the correct is ()

A, if you modify a variable, once the value is assigned, it is equal to a constant.

B, if the class is decorated, the class can only be inherited by one subclass.

C, if the method is decorated, the method cannot be overridden in a subclass.

D, if the method is decorated, the class in which the method is located cannot be inherited.

Answer: A,c

14, in Java, the following statement about the package is correct ()

A, the package declaration must be the source file the first sentence code.

B, the package declaration must be immediately following the import statement.

C, only public classes can be placed in the package.

D, you can put classes from multiple source files in the same package.

Answer: A,d

15. The _ _ _ method is a method with only the head of the method, which has no concrete method body and operation implementation, and the method must be defined in the abstract class. The ___ method is a method that cannot be redefined by subclasses of the current class.

16, what is called the overload of the method. The construction method can be overloaded.

17, briefly describe the difference between the instance variable and the class variable.

4th Chapter inheritance, interface and internal class 4.5 practice study Questions

1, Java

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.