Getting Started with Java-object-oriented basics

Source: Internet
Author: User

Getting Started with Java-object-oriented
  • The difference between the public class and class declaration classes:
    1. public class Life: The file name must be the same as the class name
    2. The file name and class name can be inconsistent when the class declaration
    3. A file can have multiple class-defined classes, but only a class that is defined by a public class
  • Recommendations for writing identifiers
    1. Do not use too many symbols, preferably starting with letters
    2. can have uppercase and lowercase letters, underscores, numbers, $
    3. Cannot start with a number
  • Data types are classified as "base data type", "Reference data Type"
      1. Basic
        Integer type Byte Short int long
        Floating-point types Float Double
        Character type Char
        Boolean type Boolean
      2. Reference
        Class Class
        Interface Interface
        Array
  • Overflow of data
     Public classDateDemo02 {/**     * @paramargs*/     Public Static voidMain (string[] args) {//TODO auto-generated Method Stub        intmax=Integer.max_value; System.out.println (The maximum value for int is: "+max); System.out.println ("The maximum value of int +1 is:" + (max+1)); System.out.println ("The maximum value of int +2 is:" + (max+2)); System.out.println ("The maximum value of int +3 is:" + (max+3)); }}

    The results of the operation are as follows:

    The maximum value of int is: The maximum value of 2147483647int +1 is:The maximum value of -2147483648int +2 is: -2147483647int the maximum value of +3 is:- 2147483646

    Will cause data errors, but the program will not error.

You can use forced type conversions to prevent data overflow:

 Public classDateDemo02 {/**     * @paramargs*/     Public Static voidMain (string[] args) {//TODO auto-generated Method Stub        intmax=Integer.max_value; System.out.println (The maximum value for int is: "+max); System.out.println ("The maximum value of int +1 is:" + (max+1l)); System.out.println ("The maximum value of int +2 is:" + ((Long) max+2)); }}

The results are as follows:

The maximum value of int is: The maximum value of 2147483647int +1 is:The maximum value of 2147483648 int +2 is: 2147483649

Getting Started with Java-object-oriented basics

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.