正在加载图片...
Appendix ava Primer In this appendix,we present a primer for people who are unfamiliar with the Java language.This introduction is intended to allow you to develop the Java skills necessary to understand the programs in this text.It is not a complete Java reference;for a more thorough coverage of Java,consult the Bibliographical Notes.We do not assume that you are familiar with object-oriented principles, such as classes,objects,and encapsulation,although some knowledge of these topics would be helpful.If you are already familiar with C or C++,the transition to Java will be smooth,because much Java syntax is based on C/C++. E.1 Basics In this section,we cover basics such as the structure of a basic program,control statements,methods,classes,objects,and arrays. E.1.1 A Simple Program A Java program consists of one or more classes.One class must contain the main()method.(A method is equivalent to a function in C/C++.)Program execution begins in this main method.Figure E.1 illustrates a simple program that outputs a message to the terminal.The main()method must be defined as public static void main(String args[]),where String args[]are /* The first simple program */ public class First f public static void main(String args[]){ /output a message to the screen System.out.println("Java Primer Now Brewing!"); Figure E.1 A first Java program. 1E Appendix Java Primer In this appendix, we present a primer for people who are unfamiliar with the Java language. This introduction is intended to allow you to develop the Java skills necessary to understand the programs in this text. It is not a complete Java reference; for a more thorough coverage of Java, consult the Bibliographical Notes. We do not assume that you are familiar with object-oriented principles, such as classes, objects, and encapsulation, although some knowledge of these topics would be helpful. If you are already familiar with C or C++, the transition to Java will be smooth, because much Java syntax is based on C/C++. E.1 Basics In this section, we cover basics such as the structure of a basic program, control statements, methods, classes, objects, and arrays. E.1.1 A Simple Program A Java program consists of one or more classes. One class must contain the main() method. (A method is equivalent to a function in C/C++.) Program execution begins in this main method. Figure E.1 illustrates a simple program that outputs a message to the terminal. The main() method must be defined as public static void main(String args[]), where String args[] are /* The first simple program */ public class First { public static void main(String args[]) { // output a message to the screen System.out.println("Java Primer Now Brewing!"); } } Figure E.1 A first Java program. 1
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有