Noob (Java Tutorial)

Source: Internet
Author: User
Tags class definition modifiers

1. Three systems in Java

    • Javase (J2SE) (JAVA2 Platform standard Edition,java platform version)
    • EE (Java 2 platform,enterprise Edition,java Platform Enterprise Edition)
    • Javame (J2ME) (Java 2 Platform Micro Edition,java Platform mini version).
2, simple, object-oriented, distributed, robust, secure, architecture neutrality, interpretation, high performance, dynamic, multi-threaded3.Each class has a constructor method. If you do not explicitly define a construction method for a class, the Java compiler will provide a default constructor for the class 4, one source file can have only one public class. The name of a source file may have multiple non-public class source files that should be consistent with the class name of the public class. For example: The class name of the public class in the source file is employee, then the source file should be named Employee.java. If a class is defined in a package, then the packages statement should be in the first row of the source file. If the source file contains an import statement, it should be placed between the package statement and the class definition. If there is no package statement, the import statement should be first in the source file. The import statement and the package statement are valid for all classes defined in the source file. In the same source file, you cannot give different package declarations to different classes. 5, constant refers to the amount can not be changed. In Java, the final flag is declared in a similar manner to a variable (similar to define), 6, this member variable is visible to the child class, the name is assigned a value of 7 in the constructor,
    • When a class variable (static variable) is declared as public static final type, the class variable name must use uppercase letters. If the static variable is not public and final, it is named in the same way as the instance variable and the local variable.
8. A method declared as public in a parent class must also be public in a subclass. A method declared as protected in a parent class is either declared as protected in the subclass or declared as public. cannot be declared as private. The method declared by the default modifier in the parent class, which can be declared as private in the subclass. The method declared as private in the parent class cannot be inherited. 9, in order to implement some other functions, Java also provides a number of non-access modifiers.

The static modifier, which is used to create class methods and class variables.

Final modifiers, which are used to modify classes, methods, and variables, the final decorated class cannot be inherited, the decorated method cannot be redefined by the inheriting class, the modified variable is constant, and is not modifiable.

An abstract modifier that is used to create abstract classes and abstract methods.

Synchronized and volatile modifiers, which are used primarily for threading programming.

10.

The instanceof operator is used to manipulate an object instance to check whether the object is a specific type (class type or interface type). 11, the SSH framework generally refers to struts, Spring, Hibernate, and later Struts2 instead of struts. In the last 5 years, STRUTS2 has been replaced by spring MVC, and hibernate is basically replaced by Ibatis/mybatis. 1 first to correct the landlord of a point of view: Do Java domain development SSH not as important as you think, from the current situation, most projects will use spring, as for struts (STRUTS2) and hibernate will usually have some other more suitable framework to replace 12, preceded by a backslash (\ Character represents the escape character, which has a special meaning to the compiler.

13, char[] helloarray = { ' h ', ' e ', ' l ', ' l ', ' o ', ' . ' }< /c4>

14, when the string is modified, you need to use the StringBuffer and StringBuilder classes. 15, you must first declare the array variable, in order to use the array in the program,dataType[] arrayrefvar;  //preferred method,dataType Arrayrefvar[]; //effect is the same, but not the preferred method 16, Foreach Loop, for (double element:mylist) {System.out.println (Element), 16, the Java.util.Arrays class can easily manipulate an array, and all of the methods it provides are static. Has the following functions: Assigning a value to an array: through the Fill method. Sort the array: By the Sort method, in ascending order. Compare arrays: Compares the values of elements in an array by the Equals method. Find array elements: The BinarySearch method can be used to perform binary lookups of sorted arrays. 17. You can allow the program to hibernate for a millisecond or any period of time to the life of your computer. For example, the following program sleeps 10 seconds: 18, Java Regular expression, Java.util.regex package mainly includes the following three classes, pattern class:, Matcher class:, Patternsyntaxexception:19, Patternsyntaxexception is a non-mandatory exception class that indicates a syntax error in a regular expression pattern.

The Patternsyntaxexception class provides the following methods to help us see what errors have occurred.

17. When a method returns a value, the method call is usually treated as a value. For example:

int= Max(+);      

If the method return value is void, the method invocation must be a statement. For example, method println returns void. The following call is a statement:

System.  Out.  println("Welcome to java!" );
18. When an object is created, the constructor method is used to initialize the object. The constructor method is the same as the name of the class it is in, but the constructor does not return a value.

The constructor method is typically used to assign an initial value to an instance variable of a class, or to perform other necessary steps to create a complete object.

Whether or not you customize the constructor method, all classes have a constructor method, because Java automatically provides a default constructor that initializes all members to 0.

Once you have defined your own construction method, the default constructor method is invalidated.

19.

The Finalize () method Java allows you to define a method that is called before the object is destroyed (reclaimed) by the garbage collector, which is called Finalize (), which is used to clear the recycled object. For example, you can use Finalize () to ensure that a file opened by an object is closed. In the Finalize () method, you must specify the operation to be performed when the object is destroyed. 20, Java console input is completed by sysem.in.

To get a character stream bound to the console, you can wrap the system.in in a BufferedReader object to create a character stream.

21. The stream is used to read data from a file, and its objects can be created with the keyword new. There are several construction methods that you can use to create objects. 22, Fileinputstream,fileoutputstream
OutputStream=newfileoutputstream("C:/java/hello")     
There is another method, defined first, in the File23, file class, there are two methods that can be used to create a folder:
    • The mkdir () method creates a folder, returns True if successful, and returns False if it fails. Failure indicates that the path specified by the file object already exists, or that the folder cannot be created because the entire path does not yet exist.
    • The mkdirs () method creates a folder and all its parent folders.
24. To understand how Java exception handling works, you need to master the following three types of exceptions:
    • Check Exception: the most representative of the inspection exception is the user error or the exception caused by the problem, which is not foreseen by the programmer. For example, to open a nonexistent file, an exception occurs, and these exceptions cannot be simply ignored at compile time.
    • Run-time Exceptions: runtime Exceptions are exceptions that can be avoided by programmers. Contrary to the inspection exception, run-time exceptions can be ignored at compile time.
    • Error: The error is not an exception, but a problem that is out of the programmer's control. Errors are usually ignored in the code. For example, when a stack overflows, an error occurs, and they are not checked for compilation.
  25.If a method does not capture an inspection exception, the method must be declared using the throws keyword. The throws keyword is placed at the tail end of the method signature.

You can also throw an exception with the Throw keyword, whether it's newly instantiated or just captured.

26.

finally keyword

The finally keyword is used to create a block of code that executes after a try code block.

The code in the finally code block is always executed, regardless of whether an exception occurs.

In the finally code block, you can run an end-of-nature statement such as cleanup type.

The finally code block appears at the end of the catch code block, with the following syntax:

 try{//program code }Catch(Exception type 1 Exception variable name 1) {//program code }catch (Exception type 2 exception variable name 2) {//program code }finally{//program code }   

27. In Java, you can customize the exception. Here are some things to keep in mind when writing your own exception classes.
    • All exceptions must be subclasses of Throwable.
    • If you want to write an inspection exception class, you need to inherit the exception class.
    • If you want to write a run-time exception class, you need to inherit the RuntimeException class.
28, instanceof judge whether one is not another subclass, return True,false29.  Use the Super keyword when you need to call the overridden method of a parent class in a subclass. 30. Declaring an abstract method will result in the following two results:
    • If a class contains an abstract method, the class must be an abstract class.
    • Any subclass must override the abstract method of the parent class, or declare itself an abstract class.
31.A class that implements an interface must implement all the methods described in the interface, otherwise it must be declared as an abstract class
    • All methods in an interface must be abstract methods.
    • Interfaces are not inherited by classes, but are implemented by classes.
    • Interface has no constructor method.
    • Interfaces are implicitly abstract, and it is not necessary to use the abstract keyword when declaring an interface.
    • Each method in the interface is implicitly abstract, and the declaration does not require an abstract key.
    • The methods in the interface are public.
All is nonsense, the interface is an abstract method, but the default needless to say, but also to implement all of the abstract methods32.Java uses the package as a mechanism to prevent naming conflicts, access control, to provide search and locate classes (class), interfaces, enumerations (enumerations), and annotations (annotation), and so on. 33, in order to be able to use the members of a package, we need to explicitly import the package in a Java program. Use the "Import" statement to complete this function. 34. Usually, a company uses its Internet domain name in reverse form as its package name. For example: Internet domain name is apple.com, all package names start with Com.apple. Each part of the package name corresponds to a subdirectory. 35. The compiled. class file should be the same as the. Java source files, and the directories they place should correspond to the names of the parking. However, the path to the. class file is not required to be the same as the corresponding. Java path. You can arrange the directory of source code and class. (compiled file) 36,$javac -d . Dell. Java

This will put the compiled file as follows:

. \com\apple\computers\dell.  Class.  \com\apple\computers\ups.  Class      

Noob (Java Tutorial)

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.