Java Basic Learning 02 (Simple Java Program)

Source: Internet
Author: User

Simple Java program One, the goal of completion
1. 理解java程序的基本组成2. 如何对程序代码进行注释3. java标识符的命名规则4. 了解java中的关键字5. 使用java定义变量或声明变量
Second Simple Java program
public class TestJava{    public static void main(String [] args){        //操作一个简单的范例,输出和乘方        int num = 10;                               //定义一个整型变量        num = 30;                                   //修改变量        System.out.println("num的内容是:"+num);     //输出内容        System.out.println("num*num="+num*num);     //输出乘方  }}
Comments
//单行注释(Java编译器会忽略掉这部分信息)int num; //定义一个整数/**多行注释多行注释*//***文档注释(这种方法注释的内容会被解释成程序的正式文档,*并能包含在如:javadoc之类工具生成的文档中*/
Identifier
Java中的包、类、方法、参数和变量的名字由任意顺序的大小字母、数字、下划线(_)、和美元符号($)组成,但标识符不能以数字开头,也不能是java中的保留关键字。
Key words

Variables and constants
1.变量:    利用声明的方式将内存中的某个内存块保留下来以供程序使用。可以用来存放数据,使用变量之前必须先声明它的数据类型。例如:声明一个可以存放整型的变量num(int num;//声明num为整型变量)2.常量:    就是一个固定的值,是不可改变的.例如:数字1,2就是整型常量。
Three, the main points
1. java程序的入口是由主方法开始的2. java的基本组成是类,使用public class和class都可以声明一个类,public class 类名称必须与文件名一致,class可以与文件名不一致,但是执行时必须执行生成后的*.class文件。3. System.out.println()是在标准输出设备-显示器上进行输出操作,可使用println和print两种方法。println输出之后加入换行,print没有换行。

Java Basic Learning 02 (Simple Java Program)

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.