Saturday, 4 January 2014

Iteration statements:for loop in java

The most common iteration Statements in Java

Iteration Statement: for loop


The 'for' LOOP:


The for statement provides a compact way to iterate over a range of values. Programmers often refer to it as the "for loop" because of the way in which it repeatedly loops until a particular condition is satisfied. If only one statement being repeated, there is no need for the curly braces. When using this version of the for statement, keep in mind that,The initialization expression initializes the loop; it's executed once, as the loop begins.

Switch Statement in Java

How to use Java Switch: Case: Default: 

Using switch statement

Swich:

The switch statement is Java’s multiway branch statement.It provides an easy way to dispatch execution to different parts of your code based on the value of an expression.It is an alternatives of else-if ladder. Switch allows you to choose a block of statements to run from a selection of code, based on the return value of an expression. The expression used in the switch statement must return an int, a String, or an enumerated value.

Friday, 3 January 2014

Nested if Statement in Java

The most common Control Statements in Java

Control Statement Nested if


The nested if Statement:

Nested if are very common in programming. Nesting an if  Statement just means putting one if Statement inside of another. when you nest ifs, the main thing to remember is that an else statement always refers to the nearest if statement that is with  in the same block as the else and that is not already associated with an else.

Saturday, 2 February 2013

if and if-else control statements in java

The most common Control Statements in Java

Control Statement if and if.. else

The if Statement:


In Java if statement is most widely used. The if statement is control statement which helps programmers in decision making. The if statement uses boolean expression in making decision whether a particular statement would execute or not. This is a control statement to execute a single statement or a block of code, when the given condition is true and if it is false then it skips if block and rest code of program is executed. 

Introduction to Control Statements in Java


Control statements decide flow of a program

JAVA CONTROL STATEMENTS

if, if-else, switch, nested if, switch, for, while, do-while, break, continue and return control statements


Control statements are used in programming languages to cause the flow of control to advance and branch based on changes to the state of a program. The statements inside your source files are generally executed from top to bottom, in the order that they appear. Control flow statements, however, break up the flow of execution by employing decision making, looping, and branching, enabling your program to conditionally execute particular blocks of code.
In Java, control statements can be divided under the following three categories:

Thursday, 24 January 2013

Java Program to convert Lower Case Letter in to Uppper Case

Conversion of Lower Case letter to UpperCase in JAVA

toUpperCase(char ch) and toLowerCase(char ch) functions in Java


Syntax: public static char toUpperCase(char ch)


Converts the character argument to uppercase using case mapping information from the UnicodeData file. Note that Character.isUpperCase (Character.toUpperCase(ch)) does not always return true for some ranges of characters, particularly those that are symbols or

Monday, 21 January 2013

Code Comments in Java Program

Commenting Methods used in Java Program

Code comments in JAVA Source Code

Code comments are placed in source files to describe what is happening in the code to someone who might be reading the file, to comment-out lines of code to isolate the source of a problem for debugging purposes, or to generate API documentation. To these ends, the Java language supports three kinds of comments: double slashes, C-style, and doc comments.

Double Slashes

Double slashes (//) are used in the C++ programming language, and tell the compiler to treat everything from the slashes to the end of the line as text.

//A Very Simple Example

class ExampleProgram {
          public static void main(String[] args){
          System.out.println("I'm a Simple Program");
          }
}

C-Style Comments

Instead of double slashes, you can use C-style comments (/* */) to enclose one or more lines of code to be treated as text.

/* These are C-style comments */
class ExampleProgram {
         public static void main(String[] args){
         System.out.println("I'm a Simple Program");
         }
}

Doc Comments

To generate documentation for your program, use the doc comments (/** */) to enclose lines of text for the javadoc tool to find. The javadoc tool locates the doc comments embedded in source files and uses those comments to generate API documentation.

/** This class displays a text string at 
* the console.
*/
class ExampleProgram {
          public static void main(String[] args){
          System.out.println("I'm a Simple Program");
          }
}