You are on page 1of 1

Advantages of this combined approach are: We can have compile time type checking to avoid such issues coming

up during run time. We can have code optimizations during the compile time and run the optimized coe during run time. There needs to be only one version of the code (or executable) for every platfor m and hence is platform independent. Disadvantages are: The code will run slower compared to a language which is precompiled to machine language as java bytecode is converted to machine language while executing. Blocks, Methods and Constructors in Java A block is a group of zero or more statements between balanced braces {} and can be used anywhere a single statement is allowed like a method body, outside a me thod but inside the class atc. A method in Java can be considered as a block wit h a name. Variables declared inside a block has a scope or lifetime limited to t hat block. For example, if you declare a variable myVar inside a method, it won' t be recognized outside. However, a variable declared in one block will be avail able to its inner blocks. These variables are called local variables as they are local to a block. Local variables are always thread safe as a different copy of local variable will be created per thread. A local variable must be initialize d before you try to use it, else compiler will complain.

You might also like