How do you use classes in reference data types in Java?

Source: Internet
Author: User

---------------------------------------

Classification of data types in Java:

Basic Data type: 4 Class 8 kinds. BYTE, short, int (integer default), long, float, double (decimal default), Char, Boolean

Reference data types: classes, interfaces, arrays, strings, lambda, and so on.

Note: The two reference data types, string, lambda, are learned later.

---------------------------------------

How do you use classes in reference data types in Java?


In Java 9 or earlier, in addition to 8 basic data types, other data types belong to the reference data type.

If you want to use "classes" in reference types, the general steps for typical usage are:


For example, use a scanner class Scanner that is already written by the JDK in Java.


Step 1: Guide the package.

Specify where you want the target to be used. Write the code on a line before the public class:

Import xxx.yyy.zzz. class name;

For example:

Import Java.util.Scanner; //This method imports the level that is imported to the class.

Step 2: Create the object.

Want to use the function inside this class, need to create object Ah!

Reference data types generally require creation of objects to be used in the following format:

Data type variable name = new data type ();

For example:

Scanner sc = new Scanner (system.in);

Step 3: Call.

What features you need to use, just one feature name (method name), in the format:

The name of the variable. Method name ();

For example:

A: Gets the int number of the keyboard input

int num = Sc.nextint ();

B: Get the keyboard input string

String str = Sc.next ();

---------------------------------------


How do you use classes in reference data types in Java?

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.