Sunday 12 August 2012

STATEMENT LITERALS ACCESS CONTROL AND LOOP

Hi Friends !! Today I am going to tell about import statements,Java literals,access control and inheritance,Loop control in Java...
Import statements !!

In java if a fully qualified name, which includes the package and the class name, is given then the compiler can easily locate the source code or classes. Import statement is a way of giving the proper location for the compiler to find that particular class.

For example following line would ask compiler to load all the classes available in directory java_installation/java/io :

import java.io.*;
Variables are nothing but reserved memory locations to store values. This means that when you create a variable you reserve some space in memory.
Java Literals:
Java language supports few special escape sequences for String and char literals as well. They are:
Notation
Character represented
\n
Newline (0x0a)
\r
Carriage return (0x0d)
\f
Formfeed (0x0c)
\b
Backspace (0x08)
\s
Space (0x20)
\t
Tab
\"
Double quote
\'
Single quote
\\
Backslash
\ddd
Octal character (ddd)
\uxxxx
Hexadecimal UNICODE character (xxxx)

Access Control and Inheritance:

The following rules for inherited methods are enforced:
·         Methods declared public in a superclass also must be public in all subclasses.
·         Methods declared protected in a superclass must either be protected or public in subclasses; they cannot be private.
·         Methods declared without access control (no modifier was used) can be declared more private in subclasses.
·         Methods declared private are not inherited at all, so there is no rule for them.
Loop Control:
 To execute a block of code several number of times, and is often referred to as a loop.
Java has very flexible three looping mechanisms. You can use one of the following three loops:
·         while Loop
·         do...while Loop
·         for Loop
As of java 5 the enhanced for loop was introduced. This is mainly used for Arrays.

The while Loop: A while loop is a control structure that allows you to repeat a task a certain number of times.

Syntax:

while(Boolean_expression)
{
   //Statements
}

The do...while Loop: A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time.

Syntax:

do
{
   //Statements
}while(Boolean_expression);

The for Loop:

A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
A for loop is useful when you know how many times a task is to be repeated.

Syntax:

for(initialization; Boolean_expression; update)
{
   //Statements
}

Enhanced for loop :  As of Java 5 the enhanced for loop was introduced. This is mainly used for Arrays.

Syntax:

for(declaration : expression)
{
   //Statements
}
·         Declaration. The newly declared block variable, which is of a type compatible with the elements of the array you are accessing. The variable will be available within the for block and its value would be the same as the current array element.
·         Expression. This evaluate to the array you need to loop through. The expression can be an array variable or method call that returns an array.

The break Keyword:   The break keyword is used to stop the entire loop. The break keyword must be used inside any loop or a switch statement.The break keyword will stop the execution of the innermost loop and start executing the next line of code after the block.

Syntax:

break;

The Continue Keyword:

The continue keyword can be used in any of the loop control structures. It causes the loop to immediately jump to the next iteration of the loop.
·         In a for loop, the continue keyword causes flow of control to immediately jump to the update statement.
·         In a while loop or do/while loop, flow of control immediately jumps to the Boolean expression.

Syntax:

continue;

Now !! You can download the copy of this article by just click on below download link...
I hope this post will help you !!
Thanx !!
If still you have some query regarding to this article then please post your comment after that 1 will 100 % reply back you...




0 comments:

Post a Comment

Hey thanax alot to comment i will revert you back soon...

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites