Posts

Showing posts from December, 2010

Introduction to Java For Loops

Purpose :
The for statement is similar to the while statement, but it is often easier to use if you are counting or indexing because it combines three elements of many loops:  initialization, testing, and Increment.

Initialization: It allows the variable to be initialize. Such as: int i = 0; int j = 2;  Termination (or condition): It allows to check the certain condition. If condition is true then all statements and processes written in the for block will be executed otherwise ignored. Condition such as: i <= 5; i <j;  Increment: It allows the how much increase the given variable. Such as: i++; j++;

While Statement Introduction in Java

The while statement is used to repeat a block of statements while some condition is true. The condition must become false somewhere in the loop, otherwise it will never terminate. 
Purpose : Purpose - to repeat statements The purpose of the while statement is to repeat a group of Java statements many times. It's written just like anif statement, except that it uses the while keyword. 

If Statement examples in Java

Example 1 :
If Student marks is grater than equal 60 print "passed" else "failed"

/** * To change this template, choose Tools | Templates * and open the template in the editor. */ package statement; import java.util.Scanner; /** * * @author ACHCHUTHAN */ public class Result {

If Statement Introduction in Java

Image
Purpose :
The purpose of the if statement is to make decisions, and execute different parts of your program depending on a boolean true/false value. About 99% of the flow decisions are made with if. [The other 1% of the decisions use the switch statement.]


 General Forms :
The if statement has this form, where condition is true or false. ... // Do these statements before. if (condition) { ... // Do this clause if the condition is true. } ... // Do these statements after.

Java Language Keywords

Keywords

Here is a list of keywords in the Java programming language. You cannot use any of the following as identifiers in your programs. The keywords const and goto are reserved, even though they are not currently used. true, false, and null might seem like keywords, but they are actually literals; you cannot use them as identifiers in your programs.





Primitive Data Types and Operations in Java

Primitive Data Types 
The primitive data types are predefined data types, which always hold the value of the same data type, and  the values of a primitive data type don't share the state with other primitive values. These data types are named by a reserved keyword in Java  programming language. 

Programming Style and Simple "Hello World"program in java

Image
Programming Style and Documentation
Appropriate CommentsNaming ConventionsProper Indentation and Spacing LinesBlock StylesAppropriate Comments , Naming Conventions  Choose meaning and descriptive names.  Variables and method names:Use lowercase. If the name consists of several                       words, concatenate all in one, use lowercase for the first  word, and capitalize the first letter of   each  subsequent word in the name.For example, the variables radius and area, and the method compute Area.Naming Conventions, cont.Class names:Capitalize the first letter of each word in the name. For example, the class name ComputeArea.Constants:Capitalize all letters in constants. For example, the constant PIProper Indentation and Spacing IndentationIndent two spaces. SpacingUse blank line to separate segments of the code.Programming ErrorsSyntax ErrorsDetected by the compilerRun time ErrorCauses the program to abortLogic ErrorsProduces incorrect resultCreating Your First ApplicationA sou…