Java Road - basic computer, constants, variables

Byte 1
Byte your typical minimum storage unit of the computer. Computer store any data bytes are stored in the form, right-click the file attributes, we can see the byte size of the file.
8 'bit (binary digit) 0000-0000 expressed as 1 byte, 1 byte write or 1 B.
B =. 1 'bit. 8
1024 B. 1 KB =
1024 KB. 1 MB =
1024 MB. 1 = GB
1024 GB. 1 = the TB

2.DOS operating system command

Command Prompt cmd operation symbol
letter switching command letter name:
View the current dir folder
into the folder command cd folder name
to exit Folder command cd ..
Exit to disk root directory cd \
clear screen cls
exit cmd exit

3.Java virtual machine --JVM
the JVM (Java Virtual Machine): Java Virtual Machine, referred JVM, is a hypothetical computer to run all Java programs, a Java program
execution environment, is one of the most attractive features of Java
. We write Java code that are run on JVM.
Cross-platform: any running software must be run on the operating system, and our software written in Java can run on any operating system
on the system, this feature is called cross-platform Java language features. This feature is implemented by the JVM, we wrote a program run on JVM, and JVM
on the operating system.

 

 

As shown, Java virtual machine itself does not have cross-platform capabilities, each operating system has a different version of the virtual machine.


4.JRE and the JDK
the JRE (Java Runtime Environment): Java program is run-time environment that contains JVM and runtime required core class libraries.
JDK (Java Development Kit): is a Java Development Kit, contains tools JRE and developers use.
We want to run an existing Java programs, you can simply install the JRE.
We want to develop a new Java program, you must install the JDK.

5.HelloWorld entry procedures
program development steps illustrate
the development environment has been set up and ready to develop our first Java program up.
Java developers a three-step: write, compile, run.

 

 

 

The first helloworld program

public class HelloWorld {
    public static void main(String[] args){
        System.out.println("hello,world!");
    }
}

 

Compiling and running are two different things
compilation: refers to the translation we write Java source files into JVM class files know, in the process, javac compiler will check us
whether programs written in error, an error will prompt out, If no errors will compile successfully.
Run: refers to the class file to the JVM to run, this time the JVM to execute the program we write.


About the main method
main methods: the main method is called. Was written in a fixed format can not be changed. The main method is the entry point or the start of a program, whether we write more than
a small program, JVM at run time, the main method will begin from here.

 

 

Add Comment comment
Comment: The code is explained and illustrated. Its purpose is to allow people to more easily understand the code. Add comments to the code, it is very necessary
to be, it does not affect compile and run the program.

Java has single-line and multi-line comments:
  single-line comments begin with // wrap the end of
  multi-line comments with / * begin with * / End

 

// This is my first program 
public  class the HelloWorld { 
     // contents of the second line is the same years of writing, on behalf of the main method
     // starting point of this line represents the execution of 
    public  static  void main (String [] args ) {
         / * 
        this will not 
        affect the operation of the program 
        will not! 
        * / 
        // third row represents printout statements (in fact, the screen display) 
        System.out.println ( "i AM chris" ); 
    } 
}

 

Keywords: refers to the program, Java has defined the word has a special meaning.
HelloWorld case, the keyword appears there are public, class, static, void, etc., these words have been well defined Java, are all lowercase letters , notepad ++ in special colors.
Keyword more, not rote, where you can learn where to remember.

Identifier: refers to the program, we own custom content. For example, the name of the class, method names and variable names, etc., are identifiers.
HelloWorld case, there appears identifier class name HelloWorld.

Naming rules: mandatory requirement
identifiers can contain 26 letters (case sensitive), 0-9, $ (dollar sign) and _ (underscore).
Identifiers can not begin with a number.
Identifiers can not be keywords.


Naming convention: soft recommended
class name specification: capitalize the first letter of each word capitalized behind (large camel).
Specification method name: the first letter lowercase, behind each word capitalized (small camel).
Variable name specification: the first letter lowercase, behind each word capitalized (small camel).

constant:

public  class ConstantDemo {
     public  static  void main (String [] args) {
         // output integer constant 
        System.out.println (123 );
         // output decimal constant 
        System.out.println (0.125 );
         // output character constants 
        System. Out.println ( 'A' ); # single quote! The middle two single quotes must have one and only one character! Can not have two
         // output Boolean constants 
        System.out.println ( to true );
         // string literals 
        System.out.println ( "Hello the Java" ); # represents the contents inside the intermediate type string is not empty 
} 

empty constants can not print! ! ! !

 

 

6. Data type classification

Java data types are divided into two categories:
basic data types include: integers, floating point, character, Boolean.
Reference data types: comprising: string, array class, arrays, interfaces, lambda

four eight basic data types:

 

 

 

 Notes:
1. The string is not a basic type, but reference types

2. The float may only be an approximation, not an exact value

3. The data range is not necessarily related to the number of bytes

4. The default type float which is double, if we use a float, it is necessary to add a suffix F

5. If the default is shaped as a long int types must use if plastic, the need to add a suffix L

 

7. The definition of variables

Variable definition format consists of three elements: data type, variable name, data values.
Format: data type data variable name = value;

 

public class HelloWorld{
    public static void main(String[] args){
        int numl = 3;
        System.out.println(numl);
        System.out.println("=================");
        byte num2 = 29;
        System.out.println(num2);
        float num3 = 2.5F;
        System.out.println(num3);
    }
        
}

 

 

Note:
  variable name: a brace in the same range, the variable name can not be the same. Otherwise it will error
  variable assignment: defined variables, no assignment can not be used.
  For float and long types, letter suffix F and L can not lose
  variables If byte, or short type, then the data values can not exceed the scope of the right of the left of the type of

  Variables can not be used more than exceed the scope of the range - - -> Scope: Starting line defined variables, until the braces directly owned up

 

public class HelloWorld{
    public static void main(String[] args){
        int numl = 3;
        System.out.println(numl);
        System.out.println("=================");
        byte num2 = 29;
        System.out.println(num2);
        float num3 = 2.5F;
        System.out.println(num3);
        int x = 1, y = 2, z = 3;
        System.out.println(x);
        System.out.println(y);
        System.out.println(z);

    }
    
}

 

Guess you like

Origin www.cnblogs.com/caixiaowu/p/12631995.html