Java basics and java Basics

Source: Internet
Author: User

Java basics and java Basics

In object-oriented programming languages, classes are first-class citizens, and the entire system is composed of classes. Methods in Java cannot exist independently. All methods must be defined in the class. classes or objects must be used as callers for executing methods.

The Java language is a static language. After a class is defined, as long as the class file is not re-compiled, the methods of the Class and Class Object are fixed and will never change.

Method parameter transfer method: Pass the value to pass a copy of the actual parameter value into the method, and the parameter itself will not be affected. When a parameter is of the reference type, a copy of the actual object address is passed. Only two references point to the same object.

Variable-length parameters:

You can add "..." between the "type" and "parameter name" of a parameter to match an uncertain real parameter. Varargs can only be placed at the end of the parameter list, and can have at most one. When calling a method, you can also input an array in the Varargs section.

Public class Main {static int sumvarargs (int... intArrays) {int sum, I; sum = 0; for (I = 0; I <intArrays. length; I ++) {sum + = intArrays [I];} return (sum );}}

The System. out. println () method can only output strings on the console. when outputting an object, the actual output is the return value of the toString () method of the object.

ToString () method: to output the object's self-description information. The toString method implemented by the Object class is to return the class name + @ + hashCode value of the implementation class, so developers need to override this method in the subclass of the Object.

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.