The syntax of Java is basically the same as that of C #, after all, it is an object-oriented programming language. The following is a list of Java's unique and I do not learn in C # knowledge of grammar
First, Java is an interpreted language
Second, Java modifier
1. Access Control modifiers
Default,public,protected,private
2. Non-access control modifiers
static method, cannot use non-static variable of class, static variable, no matter how many objects a class instantiates, its static variable has only one copy. Static variables are also known as class variables. A local variable cannot be declared as a static variable.
Final
Final variable: The final variable can be explicitly initialized and initialized only once. A reference to an object that is declared final cannot point to a different object. But the data in the final object can be changed. This means that the final object reference cannot be changed, but the value inside can be changed. (??? The final modifier is typically used with the static modifier to create a class constant.
Final method: The final method can inherit from the quilt class, but cannot be modified by the quilt class. The primary purpose of declaring the final method is to prevent the content of the method from being modified.
Final class: The final class cannot be inherited, and no class can inherit any of the attributes of the final class.
Abstract
Abstract class: An abstraction class cannot be used to instantiate an object, and the sole purpose of declaring an abstract class is to augment the class in the future. A class cannot be both abstract and final decorated. If a class contains an abstract method, the class must be declared as an abstract class, or a compilation error will occur. Abstract classes can contain both abstract and non-abstract methods. Abstract classes can contain no abstract methods.
Abstract method: An abstraction method is a method that does not have any implementation, and the specific implementation of the method is provided by the subclass. Abstract methods cannot be declared final and static.
The method of synchronized:synchronized keyword declaration can only be accessed by one thread at a time.
Transient: When a serialized object contains an instance variable that is transient decorated, the Java Virtual Machine (JVM) skips that particular variable. The modifier is included in the statement that defines the variable, which is used to preprocess the data type of the class and variable. (??? )
Volatile:volatile-Modified member variables force the value of the member variable to be re-read from shared memory each time it is accessed by the thread. Also, when a member variable changes, the thread is forced to write the value of the change back to the shared memory. So at any moment, two different threads always see the same value for a member variable.
Third, other grammar
1. Java Enhanced for Loop
JAVA5 introduces an enhanced for loop that is primarily used for arrays.
For (Declaration statement: expression) { //code sentence}
String [] Names ={"James", "Larry", "Tom", "Lacy"}; for (String name:names) { System.out.print (name); System.out.print (","); }
2. Java Number & Math class
The built-in data types for number are: Byte, int, long, double, and so on
The wrapper classes for the built-in data types are: Integer, Long, Byte, Double, Float, short
Java's math contains properties and methods for performing basic mathematical operations, such as elementary exponents, logarithms, square roots, and trigonometric functions.
3. StringBuffer and StringBuilder class
Unlike the String class, objects of the StringBuffer and StringBuilder classes can be modified more than once, and no new unused objects are produced.
The StringBuilder method is not thread-safe (cannot be accessed synchronously). Since StringBuilder has a speed advantage over StringBuffer, it is recommended to use the StringBuilder class in most cases. However, in cases where the application requires thread safety, the StringBuffer class must be used.
4. Java Date Time
The Java.util package provides a date class to encapsulate the current date and time. The date class provides two constructors to instantiate a Date object.
The first constructor initializes an object with the current date and time. Date( )
The second constructor receives a parameter that is the number of milliseconds since January 1, 1970. Date(long millisec)
(1) Format date using SimpleDateFormat:
Import Java.util.*;import java.text.*;p ublic class Datedemo {public static void Main (String args[]) { Date dnow = New Date (); SimpleDateFormat ft = new SimpleDateFormat ("E yyyy. Mm.dd ' at ' hh:mm:ss a zzz '); System.out.println ("Current Date:" + Ft.format (Dnow));} } Current date:wed 2016.11.09 at 08:23:19 AM UTC
(2) formatting dates with printf
(3) Parse string as time
The SimpleDateFormat class has some additional methods, especially parse (), which attempts to parse a string according to the formatted storage of a given SimpleDateFormat object.
Import Java.util.*;import java.text.*;p ublic class Datedemo {public static void Main (String args[]) { SimpleDateFormat ft = new SimpleDateFormat ("Yyyy-mm-dd"); String input = Args.length = = 0? "1818-11-11": args[0]; System.out.print (input + "parses as"); Date T; try { t = ft.parse (input); System.out.println (t); } catch (ParseException e) { System.out.println ("unparseable using" + ft);}}}
(4) Calendar class
The function of the calendar class is much more powerful than the date class and is more complex in implementation than the date class.
The Calendar class is an abstract class that implements the object of a particular subclass when it is actually used, and the process of creating the object is transparent to the programmer and only needs to be created using the GetInstance method.
The month of calender starts at 0, but the date and year are starting from 1
Calendar C = calendar.getinstance ();//default is the current date//Create a Calendar object representing June 12, 2009 Calendar C1 = Calendar.getinstance (); C1.set (2009, 6-1, 12);
Acquisition of Calendar class object information
Calendar C1 = calendar.getinstance ();//Get year int = C1.get (calendar.year);//Get month int months = C1.get (calendar.month) + 1 ;//obtain date int date = C1.get (calendar.date);
5. Java Hibernation (sleep)
Sleep () causes the current thread to go to a standstill (blocking the current thread), letting the CPU use it, and the purpose is to keep the current thread from hogging the CPU resources obtained by the process for a certain amount of time for other threads to execute.
Import java.util.*; public class Sleepdemo {public static void Main (String args[]) { try { System.out.println (new Date () + "\ n") ; Thread.Sleep (1000*3); Hibernate 3 seconds System.out.println (new Date () + "\ n"), } catch (Exception e) { System.out.println ("Got an exception! "); } }}
My Java Learning notes-grammar