JAVA study notes 1 (basic)

1. Introduction to JAVA

https://blog.csdn.net/phphot/article/details/2171421

Features: simple, object-oriented, cross-platform, multi-threaded, distributed, safe.

1.java is an object-oriented language, real object-oriented, any functions and variables are encapsulated by classes. All Java source code and compiled files exist in the form of classes.

2. The pointer is completely shielded, and the garbage collection mechanism is introduced at the same time, which is safe. ( The memory overhead of any program you write is out of your control.

Because although your program can't manage memory, it will slow down a certain speed, but your program will be very, very safe, because you can't call a null pointer. )

3. Virtual machine cross-platform:

Java is mainly used in all platforms except the windows operating system, such as mobile phones, servers, etc.

2. Basic grammar

1.java symbols include: identifiers, keywords, operators, separators, comments.

Identifier:

    The first character must be a letter, a coin symbol (¥, $, etc.) or an underscore (_);

    Numbers cannot be used at the beginning of identifiers;

    Identifiers cannot be keywords;

    case sensitive.

Keywords:    

  1. abstract : abstract, used in class declarations to indicate that a class cannot be instantiated, but can be inherited by other classes. An abstract class can use abstract methods, abstract methods do not need to be implemented, but need to be implemented in subclasses.
  2. continue : It is used to interrupt the current loop process and restart the execution from the end of the current loop. If there is a label behind it, start execution from the place corresponding to the label.
  3. break : used to change the program execution flow, immediately start execution from the next sentence of the current statement. If it is followed by a label, execution starts at the place corresponding to the label.
  4. for : used to declare a loop. Programmers can specify statements to loop, exit conditions, and initialize variables.
  5. while : Used to define a loop statement that is executed repeatedly. The exit condition of the loop is part of the while statement.
  6. do : used to declare a loop, the end condition of this loop can be set by the while keyword.
  7. static : means static. Used to define a variable as a class variable, the class only maintains a copy of the class variable, no matter how many instances the class currently has; used to define a method as a class method. Class methods are invoked by the class name rather than a specific instance, and can only operate on class variables.
  8. goto : Java makes goto a reserved word in order to avoid potential errors caused by using goto.
  9. package : Used to define a package to organize classes and interfaces with different functions.
  10. synchronized : Used to synchronize code blocks in multithreaded operations.
  11. assert : Indicates an assertion, which is used to check the security of the program during program development. Assets are usually not used during distribution.
  12. if : used to generate a conditional test, if the condition is true, the statement under the if is executed.
  13. else : The statement is executed if the condition of the if statement is not met.
  14. switch : When the condition is equal to a specific value, the switch selection statement can be used when running the selection of certain statements.
  15. case : used to define a branch selection, if a value is the same as the value given in switch, it will start execution from that branch.
  16. default : used in a switch statement block and executed when none of the case statements satisfy the condition.
  17. this : represents an instance of the currently used class, which can be used to access class variables and class methods.
  18. super : A reference to the superclass object of the current object.
  19. boolean : used to define a boolean type of data.
  20. byte : Used to define a byte type.
  21. char : Used to define a character data type.
  22. short : Used to define a short integer data type.
  23. int : used to define an integer data type.
  24. long : Used to define a long integer data type.
  25. float : Used to define a floating point data type.
  26. double : Used to define a double-precision floating-point data type.
  27. private : Indicates private, used to modify methods and variables, indicating that this method or variable can only be used by this class
  28. protected : Indicates protected, used to modify methods and variables, indicating that this method can only be accessed by elements in the same class, subclasses, or classes in the same package.
  29. public : Indicates public, used to modify methods and variables, indicating that the methods and variables can be accessed by all elements in the class.
  30. const : Indicates a constant, used as a reserved word.
  31. native : The interface between the Java program and the C program.
  32. volatile : Used in the declaration of a variable to indicate that the variable is asynchronously modified by several threads running at the same time.
  33. strictfp : The operation is performed according to the floating-point specification IEEE-754, which makes the floating-point operation more accurate, and the results performed by different computing platforms are consistent.
  34. try : Used to define a block of statements that can throw exceptions. If an exception is thrown, an optional catch block handles the exception thrown in the try block. At the same time, an existing finally block is executed regardless of whether an exception is thrown.
  35. catch : Used to declare a block to run when a runtime error or non-runtime exception occurs in the try block.
  36. finally : Used to define a piece of code that will be executed regardless of whether there is an exception or a runtime error in the preceding try statement.
  37. final : Indicates immutable. A final-modified class cannot be subclassed, a final-modified method cannot be overridden, and a final-modified variable cannot change its initial value.
  38. class : used to declare a class.
  39. interface : used to declare an interface.
  40. instanceof : used to test whether the type of the first parameter is the type of the second parameter, or can be coerced to the second parameter.
  41. transient : Variables marked as transient, the state of these variables will not persist when the object is stored. When the object is serialized and stored in the memory, some field data is not expected to be saved. In order to ensure security, these fields can be declared as transient.
  42. extend : optional in the class declaration, used to indicate that the class needs to inherit a class.
  43. implements : Optional in the class declaration, indicating that one or more interfaces are implemented.
  44. enum : Represents an enumeration type in java.
  45. new : used to instantiate an object and allocate memory space to the class.
  46. void : used in a method declaration to indicate that this method does not have any return value.
  47. return : used to end the execution of a method, followed by a value of the type required in the method declaration.
  48. import : Specify a class or an entire package that will be referenced later at the beginning of the source file, so that you don't have to add the package name when using it.
  49. throw : used to throw an exception object or any object that implements the throwable interface.
  50. throws : Used in the declaration of a method to indicate which exceptions are not handled by this method and are handled by the caller of the method.
Notes:

    //: single line comment

    /*Comment section*/: Multi-line comment

    /**Comments section*/: File comments.


The main() method is the entry method of javaApplication.


type of data:



Control character:

\b: backspace

\t: tab

\n: newline

\f: form feed

\r: Enter

Variable declaration: type name variable name 1[, variable name 2][, ​​variable name 3]... Example: int a,b,c;

                Type name variable name 1[=initial value][, variable name2][=initial value]...... Example: int a=1,b=2,c=3;

Member variables: inside the class, outside the method declaration, the role of the entire class.

Local variables: declared inside a method or within a code block of a method, acting on a method or block of code.

Ternary operation:

exprsssion ? statement1:statement2

When the exprsssion value is true, execute statement1, and false execute statement2.


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324531805&siteId=291194637