Dark Horse Programmer--java Basic Learning Note 4

Source: Internet
Author: User

Dark Horse Programmer--java Basic Learning Note 4   I. Summary of the contents of the notes:functions-Definitions, functions-formats, functions-Details-void, functions-Details-error formats, functions-details-Define thought errors, functions-two explicit, functions-memory loading procedures, functions-overloads, arrays-Overview, arrays-definitions, arrays-memory space Partitioning, array-stack memory-heap memory, data Problems. second, the introduction of common content:1. When writing the function body, two explicit:A. What is the result of this feature? (In fact, it is in the explicit function of the return value type). B. Does the implementation of this feature require unknown content to participate in the operation? (In fact, it is in the explicit parameter list). C. The function return value type has no relation to the parameter type in the parameter list. (see below)Public static double add (int a,int b)where the definition of double is not directly related to the definition of the parameter list int. 2. Overloading of functions:definition: In the same class, more than one function with the same name is allowed .as long as they have a different number of arguments or parameter types. Benefits: Easy to read and optimized for programming. the principle of implementation: functions of the same function, only the unknown content of the parameter operation is not at the same time,you can define multiple functions, but use the uniform function name so that it is easy to read. when called, the virtual machine distinguishes a function with the same name by different argument lists. Details:overloading is independent of the return value type, only the parameter list. 3. Stack memory and heap memoryA. Stack memory: For storing local variables, the occupied space is automatically freed when the scope of the variable belongs to the end. B. Heap Memory:arrays and objects are stored in heap memory by the instances created by the new method. Each entity has a memory address value. The variables in the entity have default initialization values,different depending on the type. The integer type is 0, the decimal type is 0.0 or 0.0fA Boolean value of type False,char is ' \u0000 'If you set the reference entity of an array to null, that is, the entity is no longer being used, theis reclaimed by the garbage collector within the determined time. Iii. Classic Examples and explanations:1. Understand the characteristics of nested for loops:
Package com.date4;/** * Print Effect: * * * * * * * * * * * * * * * * * * * * * * * * * * * public      CLA SS Demo1 {public static void main (string[] args) {/** * requirements: divided into two parts for printing, first printing spaces, printing *  *///1. Control the number of outer loops for (int i=0;i<5;i++ {for (int j=0;j<i;j++) {System.out.print ("");} for (int z=0;z<5-i;z++) {System.out.print ("*" + "");} System.out.println ();}}}
2. Understanding the use of break and continue
The package com.date4;/** *break and Continue use  *1.break abort the loop, the loop that is closest to it, the external loop does not affect *  continue, is to skip this cycle and continue to the next loop. When these two statements exist individually, there can be no statements below because they cannot be executed. * */public class Demo2 {public static void main (string[] args) {method2 ();} private static void Method1 () {for (int. x=0;x<3;x++) {for (int j=0;j<4;j++) {System.out.println ("x=" +x); private static void Method2 () {for (int x=0;x<3;x++) {if (x==1) continue; System.out.println ("x=" +x);}}



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Dark Horse Programmer--java Basic Learning Note 4

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.