block : Java Glossary


In Pascal blocks are subpieces of a method that have local variables. Java for loops are considered new scope blocks where you can initialise one local variable in the for loop. You can also define a block in Java just by enclosing the code in{}. Local variables defined inside{} are not known outside the block, though they are allocated when the method starts, not when the block is entered. In other words there is no speed penalty for declaring a local variable inside a loop. A new stack frame is not started for each block. Smalltalk programmers us the term block to mean a little fragment of code that you can store in a variable or pass as a parameter. Even if statements can use blocks for the ifTrue and ifFalse actions. Blocks also provide a slick way of invoking an enumeration of a collection, running some code on each element of a set. In contrast to Smalltalk, Java has a rather verbose way for requesting a piece of code be executed on each element of a collection using the Enumeration class.

The term has quite a different used in datacommunications: Modern file transfer protocols send data in blocks, or packets, rather than just a byte at a time. Usually, the larger the block size the more efficient the file transfer. This is because most file transfer protocols wait for an acknowledgement from the other end after each block is sent, so larger blocks mean fewer stops for handshaking. However having blocks too big slows things down. This is because a single error means the whole block must be re-transmitted. Not only do the blocks take longer to retransmit, there is an increased change for error in each block.

This page is posted
on the web at:

Optional Replicator mirror
on local hard disk J:

Please the feedback from other visitors, or your own feedback about the site.
Contact Roedy. Please feel free to link to this page without explicit permission.

Your face IP:[]
You are visitor number