[Java foundation] basic grammar

Java Code Base Specification

  • Case sensitive : Java is case-sensitive, which means that the identifier Hello and hello are different.
  • Class Name : For all classes, the class name first letter should be capitalized. If the class name composed of several words, the first letter of each word should be capitalized, such as MyFirstJavaClass.
  • Method name : All method name should begin with a lowercase letter. If the method name contains several words, each word is capitalized later.
  • Source File name : source file name must be the same as the class name. When saving files, you should use the class name as the file name to save (Remember that Java is case-sensitive), the file name extension is .java. (If the file name and class name are not the same will result in a compilation error).
  • Method main entrance : All Java programs started by the public static void main (String args [ ]) method.
  • Blank lines, or lines of annotated : Java compiler will be ignored.

 

Java identifier

All components of the Java name is required. Class names, method names and variable names are called tags.
About Java identifiers, the following points should be noted:
  • All identifiers should begin with a letter (AZ or az), the dollar sign ($) or an underscore (_)
  • After the first character can be any combination of characters
  • Keywords can not be used as an identifier
  • Identifiers are case sensitive
  • Legal identifier, for example: age, $ salary, _value, __ 1_value
  • Illegal identifier example: 123abc, -salary

 

Java keywords

Java reserved words are listed below. These reserved words can not be used to name constants, variables, and any identifiers.

Keyword

description

abstract

Abstract method of the abstract class modifiers

assert

Assertion conditions are satisfied

boolean

Boolean data type

break

Label or code segments out of the loop

byte

8-bit signed data type

case

A conditional switch statement

catch

And try to capture with the exception information

char

16-bit Unicode character data type

class

The definition of class

const

Unused

continue

The remaining portion of the loop is not executed

default

Default branch switch statement

do

Loop, the loop body is executed at least once

double

64-bit double precision floating point

else

Branch executed when if condition is not satisfied

enum

Enumerated type

extends

It indicates a class is a subclass of another class

final

Represents a value can not be changed after the initialization of the
representation can not be rewritten, or a class can not have subclasses

finally

To complete code execution and design, mainly to the robustness and integrity of the proceedings, whether there are abnormal code execution.

float

32-bit single precision floating point

for

for loop

goto

Unused

if

Conditional statements

implements

Represent a class implements an interface

import

Importing classes

instanceof

Test whether an object is an instance of a class

int

32-bit integer

interface

Define an interface, an abstract type, only of methods and constants

long

64-bit integer

native

It represents a non-implemented method java code

new

Allocating a new instance of the class

package

A series of related classes package

private

Represents private fields, or methods, can only be accessed from within the class

protected

It indicates that the field can only access class or subclass
subclasses, or other classes in the same package

public

It represents the total property or method

return

Method returns a value

short

16-bit digital

static

It represents the class level definition, shared by all instances

strictfp

Floating-point comparison using strict rules

super

It represents a base class

switch

Select Statement

synchronized

Code blocks represent the same time can only be accessed by one thread

this

It denotes the current instance of call
or call another constructor

throw

Throw an exception

throws

Definition method may throw an exception

transient

Do not modify the sequence of the field

try

It represents a block of code to be done and finally with exception handling or exception is thrown indicating whether the code is executed in the finally

void

Marking method does not return any value

volatile

标记字段可能会被多个线程同时访问,而不做同步

while

while循环

 

Java注释

在Java的编写过程中我们需要对一些程序进行注释。

除了自己方便阅读,更为别人更好理解自己的程序,所以我们需要进行一些注释,可以是编程思路或者是程序的作用,总而言之就是方便自己他人更好的阅读。

Java注释有三种

(1)单行注释:// ...

(2)多行注释:/* ... */

(3)文档注释:/** ... */

以下小程序,分别展示了三种注释方法。

/**
  * First Program
  * @author Administrator
  *
  */
public class HelloWorld {
    /*
     * 打印字符串 Hello World
     */
    public static void main(String[] args) {
        System.out.println("Hello World"); // 打印 Hello World
    }
}

 

Guess you like

Origin www.cnblogs.com/deityjian/p/11408804.html