An array of Java

Source: Internet
Author: User

Tag: RGS template does not validate Col friend in while RET

Arrays are supported in almost all programming languages. It is very dangerous to use arrays in C and C + +, because those arrays are just blocks of memory. If a program accesses an array other than its own block of memory, or uses memory (which is a general programming error) before initialization, it can have unpredictable consequences (note ②).

②: in C + +, you should try not to use arrays, in exchange for a more secure container in standard template libraries (templatelibrary).

One of the main design goals of Java is security. So many of the problems that plague programmers in C and C + + are not duplicated in Java. A Java can be guaranteed to be initialized and not accessible outside of its scope. Because the system automatically checks the scope, there is a certain price to pay: a small amount of memory overhead is incurred for each array and for checking the indexes during run time. But the result is a higher level of security and higher productivity. It is worthwhile to pay a little price for it. When an array of objects is created, an array of handles is actually created. And each handle is automatically initialized to a special value with its own keyword: null (NULL). Once Java sees NULL, it knows that the handle does not point to an object. Before you can use it formally, you must assign an object to each handle. If you try to use a handle that is still null, the problem is reported at run time. As a result, typical array errors are avoided in Java. You can also create an array of primary types. Similarly, the compiler can vouch for its initialization because it divides the memory of that array into 0. The array problem will be discussed in detail in a later section.

1  Packagecom.tomtest;2 3 4 ImportJava.util.*;5  Public classtomtest_49 {6    Public Static voidMain (String args[]) {7String s= "I am Geng.x.y,she is my girlfriend";8StringTokenizer fenxi=NewStringTokenizer (S, ","); 9       intNumber=Fenxi.counttokens ();Ten        while(Fenxi.hasmoretokens ()) { OneString str=Fenxi.nexttoken (); A System.out.println (str); -System.out.println ("Still Left" +fenxi.counttokens () + "words"); -        } theSystem.out.println ("s total word:" +number+ "); -    }  -}

An array of Java

Related Article

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.