Programming Methodology-Open Course Study Notes (5)

Source: Internet
Author: User

Lesson 13th: handling strings2011.7.25

Next, we will introduce String in the previous lesson, which distinguishes char from String.

This article introduces the usage of StringTohenizer. In the past, I used the String [] str. split method. From C, I prefer the [] array method. It is also applicable to simple segmentation and can be used for parsing text and messages. The default value is "". If you need to use another one or add some, you can specify it in the constructor, such as new StringTohenizer (str ,",");, here, space and comma are used for separation. You can use hasMoreTokens () Check and nextToken () to obtain the token.

Then there is a strange trick. The shift of letters can move backwards or forward. If you want to migrate the data before, you can change it to 26-(-key % 26), where key is the shift, forward shift 3, key =-3. On the other hand, we need to note that the key can be positive or negative, not only in the range of plus and minus 26, but also in addition, the key can be any integer, instead of taking some values for granted manually, this may cause the program to run correctly.


Lesson 14th: Memory2011.7.26, 27

Introduction to memory is definitely a bitter memory of C programmers. Especially when developing services, do not cause memory leakage or forget to release the content. In the past, books once said that java has no pointer. In fact, every object is a pointer, but programmers do not need to care about memory collection and avoid many exceptions.

In java, char occupies 2 bytes.

There are static variables in the data storage, which are allocated when the program is called. Dynamic variable data is stored in HEAP mode. For example, if a variable is stored in Address 2000, The next variable is stored in 2004, and address allocation continues to increase. Local variable data is stored as a stack. For example, if a variable is stored in the address FFFF and the next variable is stored in the address FFFC, the address is continuously reduced.

The Heap address is increasing, and the stack address is decreasing. If their addresses overlap, the stack will crash. However, most programs do not need to consider this issue because the memory is sufficient. However, if the server is not easy to allow, it is necessary to track this situation. If the memory keeps increasing and cannot be converged, it will be very troublesome.

Whether heap or stack is assigned a 4 bytes overhead. For example, if a method has two local variables, an overhead is set to indicate the method, then allocate the memory of two variables. If one of the variables creates an object through new, this is a dynamic variable during runtime and running to new, allocate an overhead from heap. The overhead address is the address of this object, and allocate memory for this object in heap. Object
O = new object (......); with this "=", enter the address of the object, that is, the value of the pointer, in the memory of the 4 bytes allocated for this variable in the stack.

Because C needs to be learned, I still have a good understanding of Java memory allocation, but I don't know whether there are two storage methods: heap and stack.

Lesson 15th: Review of Pointer Points and documents2011.7.27

The pointer is further described in the previous lesson. For primitive, which includes int, double, Boolean, and char, it is not an object, so the current value is maintained in the memory. If it is used as the parameter in the method, a copy is provided. This is significantly different from the object passing pointer. Copy a pointer and actually point to the same object.

Next we will introduce the file, read the text through the bufferreader class, and write the text through the printwriter class. Remember to close () after the file is processed ().

This section describes how to capture and process Java exceptions. Try {...} catch (ioexception E1) {} catch (exception E2) {}, which is a more suitable method for server development than in C/C ++, you can easily handle exceptions you don't think. Yeah, this is indeed a value. The number of try statements is small, so dangerous operations can be caught. Try not to throw a large amount of processing into them. However, if you feel unreliable, you can always throw them in. Catch is often used for debugging, for example, locating the cause of program failure. Throw an exception to the caller.


Related Links: My articles related to programming ideas

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.