《Java程序设计教程》第一章习题

  1. 谁是Java语言的创始人?James Gosling.

  2. Java语言有哪些优点和缺点?

    优点:简单性;对互联网络的良好支持;面向对象更彻底;平台无关性/可移植性;鲁棒性;安全性;多线程性。

    缺点:程序在开发过程中越来越庞大;解释执行,执行效率低。

  3. 如何建立起Java的开发环境?

    (1)下载J2SE安装程序;(2)运行J2SE安装程序,安装J2SE;(3)设置环境变量运行路径(path)和类路径(classpath);(4)下载J2SE的在线帮助文档。

  4. 请简述环境变量path和classpath的作用。

    path: 记录各个运行程序所在的路径,系统根据这个变量的值来查找运行程序。

    classpath: 记录当前路径和J2SE类库所在的路径,这是J2SE需要的一个环境变量。

  5. Java程序可以分成哪几种,分别是什么?

    两种:应用程序(Application)和小应用程序(Applet)。

  6. 查看Java在线帮助文档,列举出System.out.println和System.out.print的不同点。

    PrintStream docs

    print doc println doc
    public void println() Terminates the current line by writing the line separator string. The line separator string is defined by the system property line.separator, and is not necessarily a single newline character ('\n').
    public void print(boolean b) Prints a boolean value. The string produced by String.valueOf(boolean) is translated into bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of the write(int) method. public void println(boolean x) Prints a boolean and then terminate the line. This method behaves as though it invokes print(boolean) and then println().
    public void print(char c) Prints a character. The character is translated into one or more bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of the write(int)method. public void println(char x) Prints a character and then terminate the line. This method behaves as though it invokes print(char) and then println().
    public void print(int i) Prints an integer. The string produced by String.valueOf(int) is translated into bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of thewrite(int) method. public void println(int x) Prints an integer and then terminate the line. This method behaves as though it invokes print(int) and then println().
    public void print(long l) Prints a long integer. The string produced by String.valueOf(long) is translated into bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of the write(int) method. public void println(long x) Prints a long and then terminate the line. This method behaves as though it invokes print(long) and then println().
    public void print(float f) Prints a floating-point number. The string produced by String.valueOf(float) is translated into bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of the write(int) method. public void println(float x) Prints a float and then terminate the line. This method behaves as though it invokes print(float) and then println().
    public void print(double d) Prints a double-precision floating-point number. The string produced by String.valueOf(double) is translated into bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of the write(int) method. public void println(double x) Prints a double and then terminate the line. This method behaves as though it invokes print(double) and then println().
    public void print(char[] s) Prints an array of characters. The characters are converted into bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of the write(int)method. public void println(char[] x) Prints an array of characters and then terminate the line. This method behaves as though it invokes print(char[\]) and then println().
    public void print(String s) Prints a string. If the argument is null then the string "null" is printed. Otherwise, the string’s characters are converted into bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of the write(int) method. public void println(String x) Prints a String and then terminate the line. This method behaves as though it invokes print(String) and then println().
    public void print(Object obj) Prints an object. The string produced by the String.valueOf(Object) method is translated into bytes according to the platform’s default character encoding, and these bytes are written in exactly the manner of the write(int) method. public void println(Object x) Prints an Object and then terminate the line. This method calls at first String.valueOf(x) to get the printed object’s string value, then behaves as though it invokes print(String) and then println().
  7. 试编写一个Java程序,在控制台窗口输出如下信息:

    *******************************
    **  Practice makes perfect
    *******************************
    
    public class PrintSomething {
        public static void main(String args[]) {
            System.out.println("*******************************");
            System.out.println("**  Practice makes perfect");
            System.out.println("*******************************");
        }
    }
    
  8. 试编写一个Java程序,在一个网页上显示习题7输出的内容。

    import java.awt.Graphics;
    import javax.swing.JApplet;
    
    public class J_HelloApplet extends JApplet {
        public void paint(Graphics g) {
            g.clearRect(0, 0, getWidth(), getHeight());
            g.drawString("*******************************", 10, 20);
            g.drawString("**  Practice makes perfect", 10, 40);
            g.drawString("*******************************", 10, 60);
        }
    }
    
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>print something</title>
    </head>
    <body>
        <applet code="J_HelloApplet.class" width="200" height="40"></applet><br />
    </body>
    </html>
    

    img

  9. 请简述编写Java程序的具体步骤。

    3个基本步骤:(1)编辑。采用编辑器编写Java源程序;(2)编译。通过编译命令将.java文件转换为.class文件;(3)执行。输入执行命令,执行Java程序。

  10. 请简述习题7和习题8程序在Java虚拟机中的执行过程。

    JVM执行字节码的过程由一个循环组成,不停地加载程序,进行合法性和安全性检测,以及解释执行,直到程序执行完毕(包括)异常退出。JVM首先从.class文件中加载字节码到内存中;接着在内存中检测代码的合法性和安全性;然后解释执行通过检测的代码,再交给相应的计算机执行。如果加载的代码不能通过合法性或安全性检测,则JVM执行相应的异常处理程序。JVM不停地重复这个过程直到程序执行结束。

猜你喜欢

转载自blog.csdn.net/ShadowBurn/article/details/86986512
今日推荐