Java Basics (Miscellaneous)

Source: Internet
Author: User

Java Foundation Compaction (Miscellaneous):
1: The creation of an instance object can be initialized by using the parameterless constructor and then calling the member variable to initialize the property, or you can define the constructor method to initialize the property directly, and when the property is private we can access it indirectly through the Getset method:
2: Methods and properties that are defined as static in a class are part of the class itself, can be invoked without instantiation, or that all instantiated objects collectively own it
3: Static members in the same class can be called directly, but non-static members cannot be called directly. If you want to call a non-static variable in a static method,
You can access non-static variables by creating the object of the class and then through the object. In the normal member method, you can directly access the same non-static variables and static variables
Non-static methods cannot be called directly in a static method, and non-static methods need to be accessed through objects, but static methods can be called directly. In the normal member method, you can
Call the normal member method directly and

 Public classHelloWorld {//defining static Variables Score1    Static intScore1 = the; //defining static variables Score2          Static    intScore2 = the; //Common Variables        intscore3=1; //defines the static method sum, calculates the score score, and returns the total score     Public Static   intsum () {intTotoal =score1+score2+ (NewHelloWorld ()). Score3; returnTotoal; }    //call the static method directly in the normal method,     Public intsum1 () {inttotoal1=sum (); returnTotoal1; }    //calling a normal method in a static method method must instantiate the object     Public Static voidMain (string[] args) {//call the static method sum and receive the return value        intAllscore = (NewHelloWorld ()). SUM1 (); System. out. println ("Total Score:"+Allscore); }}

4:equals is a value comparison, = = is compared with memory for example: if (str = = NULL | | "". Equals (null)) and if (str = = NULL | |  Str.equals ("")) the former two meaning, all is the comparison is empty, does not occupy memory the latter is not called Str is empty and is empty string (not only empty and not memory) 5: Exactly when to manually throw an exception first: Suppose Voteid you pass a value accidentally a string type, such as a value of a, so that he does not belong to the int range, at this time, will throw an exception.  Should be a type conversion exception.  The second one. In addition, exceptions are not required, just in some cases (such as when a type is converted, or when connecting to a database, stream input or output, or whatever), such as your two methods.

6: The data obtained from the stream must first be converted into a byte type in the convertible character

Java Basics (Miscellaneous)

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.