Java Control Statements

Posted: June 10, 2012 by bhumika289 in JAVA

Selection Statements

1. if

2.switch

Allow you to control the flow of your program’s execution based upon conditions during run time.

1. if :

  • It is a conditional branch statement.
  • Can be used to route program execution through two different paths.

Syntax :

if (condition)

{

statements;

}

  • When the condition is true the Statement within the if is executed and execution continues with the next statement after the if statement.
  • If the condition is false then the statement within the if is not executed and the execution continues with the statement after the if statement.
  • If the number of statement in if block is only one then parentheses are optional but if its more than one than parentheses are compulsory.

if else :

Syntax :

if (condition)

{

statement1;

}

else

{

statement2;

}

  • If the condition is true, then statement1 is executed.
  • Otherwise, statement2 is executed.

if-else-if Ladder :

Syntax :

if(condition)

statements;

else if(condition)

statements;

else if(condition)

statements;

else

statements;

  • As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder statements are bypassed.
  • If none of the conditions is true, then the final else statement will be executed.

Nested if :

A nested if is an if statement that is the target of another if or else.

Syntax :

if(condition)

{

if(condition)

statements….

else

statements….

}

else

{

if(condition)

statements….

else

statements….

}

2. switch :

  • Multiway branch statement.
  • Provides an easy way to dispatch execution to different parts of your code based on the value of an expression.

Syntax :

switch (expression)

{

case value1 :

statement1 ;

break;

case value2 :

statement2 ;

break;

case valuen :

statementn ;

break;

default :

statements ;

break;

}

  • The expression must be of type byte, short, int, or char and each of the values specified in the case statements must be of a type compatible with the expression.
  • Each case value must be a unique literal.
  • The value of the expression is compared with each ‘case’ values. If a match is found, the corresponding statement or statements are executed.
  • If no match is found, statement or statements in the default case are executed. Default statement is optional.
  • If default statement is absent, then if no matches are found, then the switch statement completes without doing anything.
  • The break statement is used inside the switch to terminate a statement sequence.

Looping Statements

1. for

2. while

3. do while

A loop repeatedly executes the same set of instructions until a termination condition is met.

1. for :

  • Repeats a set of statements a certain number of times until a condition is matched.
  • Entry controlled loop, as condition is checked while entering the loop.

Syntax :

for (initialization; condition; expression)

{

Set of statements;

}

  • In the first part a variable is initialized to a value.
  • The second part consists of a test condition that returns only a Boolean value.
  • The last part is an expression, evaluated every time the loop is executed.

2. while :

  • Executes a set of code repeatedly until the condition returns false.
  • Entry-controlled loop.

Syntax :

while (condition)

{

body(statements) of the loop

}

  • <condition> is the condition to be tested.
  • If the condition returns true then the statements inside the <body of the loop> are executed.
  • Else, the loop is not executed.

3. do while :

  • Similar to the while loop except that the condition to be evaluated is given at the end.
  • Hence the loop is executed at least once even when the condition is false.
  • Exit-controlled loop.

Syntax :

do

{

body of the loop

} while (condition);

In do while loop semicolon(;) is compulsory after while.

Jump Statements

1. break

2. continue

3. return

These statements transfer control to another part of your program.

1. break:

  • This statement is used to jump out of a loop.
  • On encountering a break statement within a loop, the execution continues with the  next statement outside the loop and the remaining statements which are after the break and within the loop are skipped.
  • Break statement can also be used with the label of a statement.
  • A statement can be labeled as follows.

statementName : SomeJavaStatement

  • When we use break statement along with label the execution continues with the statement having the label.

break statementName;

2. Continue:

  • Used only within looping statements.
  • When the continue statement is encountered, the next iteration starts.
  •  The remaining statements in the loop are skipped. The execution starts from the top of loop again.

3. return:

  • Used to explicitly return from a method.
  • Causes program control to transfer back to the caller of the method.
  • Immediately terminates the method in which it is executed.

PaintStar

Posted: June 10, 2012 by athulpavithran in Uncategorized

PaintStar is a versatile digital image processing software suitable for such tasks as retouching of photographs, composing and authoring images, image morphing, screen capture, and displaying image thumbnail in Windows Explorer context menu. It supports alpha, layer, path ,and the most common editing techniques. PaintStar has many of the tools and filters you would expect to find in commercial offerings, and some interesting extras as well.

Minimum System Requirements

  • Microsoft Windows 95, 98, Me, NT 4.0, 2000, or XP.
  • Memory: 32MB of RAM.
  • 4 MB hard disk space.
  • Video display of at least 256 colours.
  • Mouse or other pointing device

PaintStar

Xara Xtreme

Posted: June 10, 2012 by athulpavithran in Downloads

Xara X for Linux

Linux needs a top-tier commercial-standard graphics program. The Linux desktop has come on leaps and bounds in the last year or so but it still lacks a vector or general purpose graphics program  that truly competes with the best programs for the Mac or Windows . We intend to change that. Xara X has been a commercial shipping Windows product for 10 years (and non-Windows versions go back before that). It’s a modern, object orientated design that’s highly stable, and has gained hundreds of thousands of users. Our users and customers have produced artwork that is as impressive, if not more impressive, than that produced from any other vector graphics program

Xara X forMac

Ironically, given the dominance of the Mac in graphic design circles, there is no mass-market, high performance, easy-to-use graphic-design tools available for the Mac. For more than 10 years, we’ve had a continuous stream of Mac users asking, begging, that we port Xara X to their platform. By Open Sourcing the product we believe this is now a practical, realistic prospect.

With the likely elimination of Macromedia Freehand by the Adobe acquisition, Expression being acquired by Microsoft (who are unlikely to create any new Mac versions), this leaves the Mac platform with just a single serious player in this space – Adobe Illustrator. This near monopoly is not good for the Mac platform. We hope that Xara Xtreme on the Mac will change the graphics landscape for Mac users.

Xara Xtreme on Linux

GIMP 2.8

Posted: June 10, 2012 by athulpavithran in Downloads

GIMP is an acronym for GNU Image Manipulation Program. It is a freely distributed program for such tasks as photo retouching, image composition and image authoring.

It has many capabilities. It can be used as a simple paint program, an expert quality photo retouching program, an online batch processing system, a mass production image renderer, an image format converter, etc.

GIMP is expandable and extensible. It is designed to be augmented with plug-ins and extensions to do just about anything. The advanced scripting interface allows everything from the simplest task to the most complex image manipulation procedures to be easily scripted.

GIMP is written and developed  on UNIX platforms. But basically the same code also runs on MS Windows andMac OS X.

GNU/Linux Screenshots

Fundamentals of Java

Posted: June 9, 2012 by bhumika289 in JAVA

Identifiers

Identifiers are names used for classes, variables and methods. Points to remember:

  • All identifiers should begin with a letter (A to or a to z ), currency character ($) or an underscore (-).  eg. $name, _name, __1_name ,name
  • After the first character identifiers can have any combination of characters.
  • A keyword cannot be used as an identifier.
  • Identifiers are case-sensitive.

Keywords

The following list shows the reserved/keywords in Java.

abstract assert boolean break
byte case catch char
class const continue default
do double else enum
extends final finally float
for goto if implements
import instanceof int interface
long native new package
private protected public return
short static strictfp super
switch synchronized this throw
throws transient try void
volatile while

Variables

  • Basic unit of storage in a java program.
  • Every variable has scope and life time throughout the program.
  • A block is begins with an opening curly brace and ends with a closing curly brace.A block defines a scope.
  • Most other computer languages define two categories of scopes: global and local.

Declaring variables:
syntax:       type identifier1=val , identifier2; where,

  • type: datatype or classname.
  • identifier: variable name.
  • optional initializer to directly initialize the variable with a value.
example:
    int a = 29, b;

 Dynamic Initialization:Variables can be initialized dynamically as shown below:

    int a = 29, b;
b= a*a;

Symbolic Constants

  • Value is fixed within the scope.
  • Declared using the ‘final’ keyword.

example:

    final double PI = 3.414;

Java Literals

  • Representation of a fixed value.
  • Can be assigned to any primitive type variable.

example:

    int a = 29;
String s = “Welcome to Engineering Adda”;

Escape sequences for String and char literals:

Notation

Character represented

\n Newline
\r Carriage return
\f Formfeed
\b Backspace
\s Space
\t Tab
\” Double quote
\’ Single quote
\\ backslash
\ddd Octal character
\uxxxx Hexadecimal UNICODE character

Data Types in Java

There are two data types available in Java:

  1. Primitive Data Types
  2. User-defined Data Types

1. Primitive Data Types:

Primitive Data Types

2. User-defined Data Types:

  • Reference variables are created using defined constructors of the classes.
  • They are used to access objects.
  • These variables are declared to be of a specific type that cannot be changed.
  • Class objects, and various type of array variables come under reference data type.
  • Default value of any reference variable is null.
  • A reference variable can be used to refer to any object of the declared type or any compatible type.

example:

     Fruit fruit = new Fruit(“apple”);

Operators

Symbol that tells the computer to perform mathematical and logical calculation.   Arithmetic Operators:

Operator Description Example
+ Addition – Adds values on either side of the operator A=10, B=12, A + B=22
Subtraction – Subtracts right hand operand from left hand operand A=10, B=12, A – B=-2
* Multiplication – Multiplies values on either side of the operator A=10, B=12, A * B=120
/ Division – Divides left hand operand by right hand operand A=10, B=10, B / A will give 1
% Modulus – Divides left hand operand by right hand operand and returns remainder A=10, B=9, B % A will give 1
++ Increment – Increase the value of operand by 1 B=20, B++ gives 21
Decrement – Decrease the value of operand by 1 B=20, B– gives 19

Relational Operators:

Operator Description Example
== Checks if the value of two operands are equal or not, if yes then condition becomes true. A=19, B=20, (A == B)=false.
!= Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. A=19, B=20, (A != B)=true.
> Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. A=19, B=20, (A > B)=false.
< Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. A=19, B=20, (A < B)=true.
>= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. A=19, B=20, (A >= B)=false.
<= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true. A=19, B=20, (A <= B)=true.

Bitwise Operators:

Operator Description Example
& Binary AND Operator copies a bit to the result if it exists in both operands. A=0011, B=1110, (A & B)=0010i.e. A=3, B=15, (A & B)=2
| Binary OR Operator copies a bit if it exists in eather operand. A=0011, B=0110, (A | B)=0111i.e. A=3, B=6, (A | B)=7
^ Binary XOR Operator copies the bit if it is set in one operand but not both. A=1010, B=0011, (A ^ B)=1001i.e. A=10, B=3, (A ^ B)=9
~ Binary Ones Complement Operator is unary and has the efect of ‘flipping’ bits. A=0011, (~A)=1100i.e. A=3, (~A)=12
<< Binary Left Shift Operator. The left operands value is moved left by the number of bits specified by the right operand. A=0001, A << 2 =0100i.e. A=1, A << 2 =4
>> Binary Right Shift Operator. The left operands value is moved right by the number of bits specified by the right operand. A=0100, A >> 2 =0001i.e. A=4, A >> 2 =1
>>> Shift right zero fill operator. The left operands value is moved right by the number of bits specified by the right operand and shifted values are filled up with zeros. A=1101, A >>>2 =0010i.e. A=13, A >>>2 =2

Logical Operators:

Operator Description Example
&& Called Logical AND operator. If both the operands are non zero then then condition becomes true. A=11, B=01, (A && B) is false.
|| Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. A=11, B=01, (A || B) is true.
! Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false. A=11, B=01, !(A && B) is true.

Assignment Operators:

Operator Description Example
= Simple assignment operator, Assigns values from right side operands to left side operand C = A + B assign value of A + B into C
+= Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand C += A equivalent to C = C + A
-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand C -= A equivalent to C = C – A
*= Multiply AND assignment operator, It multiplies right operand with the left operand and assign the result to left operand C *= A equivalent to C = C * A
/= Divide AND assignment operator, It divides left operand with the right operand and assign the result to left operand C /= A equivalent to C = C / A
%= Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand C %= A equivalent to C = C % A
<<= Left shift AND assignment operator C <<= 2 same as C = C << 2
>>= Right shift AND assignment operator C >>= 2 same as C = C >> 2
&= Bitwise AND assignment operator C &= 2 same as C = C & 2
^= bitwise exclusive OR and assignment operator C ^= 2 same as C = C ^ 2
|= bitwise inclusive OR and assignment operator C |= 2 same as C = C | 2

Conditional Operator ( ? : ):

  • Also known as the ternary operator.
  • Consists of three operands.
  • Used to evaluate boolean expressions.
  • The goal of the operator is to decide which value should be assigned to the variable.

syntax:     variable x = (expression) ? value if true : value if false   instanceOf Operator:

  • Used only for object reference variables.
  • Checks whether the object is of a particular type(class type or interface type).

syntax:   ( Object reference variable ) instanceOf  (class/interface type)
Precedence of Java Operators:

Category  Operator  Associativity 
Postfix () [] . (dot operator) Left to right
Unary ++ – – ! ~ Right to left
Multiplicative * / % Left to right
Additive + – Left to right
Shift >> >>> << Left to right
Relational > >= < <= Left to right
Equality == != Left to right
Bitwise AND & Left to right
Bitwise XOR ^ Left to right
Bitwise OR | Left to right
Logical AND && Left to right
Logical OR || Left to right
Conditional ?: Right to left
Assignment = += -= *= /= %= >>= <<= &= ^= |= Right to left
Comma , Left to right

Allegation or Mixture

Posted: June 9, 2012 by makaranddalal in Uncategorized

Allegation or Mixture Formula’s

1. Allegation

It is the rule that enables us to find the ratio in which two or more ingredients at the given price must be mixed to produce a mixture of a desired price

2. Mean Price

The cost price of a unit quantity of the mixture is called the mean price.

3. Example

Suppose a container contains x of liquid from which y units are taken out and replaced by water .After n operations, the quantity of pure liquid = [x(1-y/x)n] units.

4. Rule of Allegation

If two ingredients are mixed, then

Layout in html

Posted: June 8, 2012 by makaranddalal in HTML

Layout in html is very important to attract users


<!DOCTYPE html>
<html>
<body>

<table width=”500″ border=”0″>
<tr>
<td colspan=”2″ style=”background-color:#BCBCBC;”>
<h1>Engineering Adda</h1>
</td>
</tr>

<tr valign=”top”>
<td style=”background-color:#F3460C;width:100px;text-align:top;”>
<b>Menu</b><br />
HTML<br />
Engineering<br />
Java
</td>
<td style=”background-color:#FFFF2F;height:200px;width:400px;text-align:top;”>
An website for Engineers.
You can add more content</td>
</tr>

<tr>
<td colspan=”2″ style=”background-color:#FFA500;text-align:center;”>
Copyright © Engadda.com</td>
</tr>
</table>

</body>
</html>


Output:

HTML Layout

iframe code in html

Posted: June 8, 2012 by makaranddalal in HTML

A webpage can be displayed within a webpage using HTML iframe


<!DOCTYPE html>
<html>
<body>

<iframe src=”https://engadda.wordpress.com/&#8221; width=”500″ height=”500″>

</body>
</html>


Iframe tag is hidden in wordpress blogs

So if you are unable to see it in above code the actual code is as shown in below image:

HTML iframe code

Few older browsers are unable to support iframes.

For such browsers iframe will not be visible.

Use of legend and fieldset tag in html

Posted: June 8, 2012 by makaranddalal in HTML

Code with legend and fieldset tag


<!DOCTYPE html>
<html>
<body>

<form action=””>
<fieldset>
<legend>About Me:</legend>
Name: <input type=”text” size=”50″ /><br />
E-mail: <input type=”text” size=”50″ /><br />
Date of birth: <input type=”text” size=”15″ />
</fieldset>
</form>

</body>
</html>


Html Form to send an email

Posted: June 8, 2012 by makaranddalal in HTML

Send email via form code:


<!DOCTYPE html>
<html>
<body>

<h3>Sending email to some one</h3>

<form action=”MAILTO:Engadda@gmail.com” method=”post” enctype=”text/plain”>
My Name:<br />
<input type=”text” name=”My Name” value=”your name” /><br />
E-mail id:<br />
<input type=”text” name=”Email id” value=”your email” /><br />
Comment:<br />
<input type=”text” name=”Comment” value=”your comment” size=”160″ />
<br /><br />
<input type=”submit” value=”Send”>
<input type=”reset” value=”Reset”>

</form>
</body>
</html>