Archive for February, 2010
OOPS/JAVA : Control Structures
by hkesavaraju on Feb.27, 2010, under Java
Control Structures: These are used to control flow of program execution.
Selection Statements: These are used to execute only one path among alternative execution paths at a time based on outcome of an expression or state of a variable.
Java supports two selection statements such as if and switch.
(i) if: It is called java’s conditional branch statement. It route program execution through two different paths. The general form of if is:
if(condition) statement1;
else
statement2;
In this, each statement may be a single or compound statement enclosed in curly braces. The condition is any expression that returns true. else clause is optional.
It works as: if the condition is true, then statement1 is executed. otherwise, statement2 is executed. In no case is true, both statements will be executed.
Example is:
int a,b;
//;;;;;;;;;;;;;
if(a<b) a=0;
else b=0;
In this, if a<0, a is set to 0.otherwise b=0. In no case, both a & b set to 0.
There are some types of if’s like nested if and if else if ladder.
a) Nested if: A nested if is an if statement that is target of another target if or else. One main thing to remember in this is an else statement always refers to the nearest if statement within the same block.
An example is:
if(i==10)
{
if(j<20) a=b;
if(k>100) c=d;
else a=c;
}
else a=d;
The outer else is not in the same block so it is matched with if(i==10). The inner else is the same block of if(i==10), so it is matched to closet if the same block such as if(k>100).
b) if else if ladder: It is based upon a sequence of nested if’s .It’s general form is
if(condition) statement;
else if(condition) statement;
else if(condition) statement;
..
.
.
else
statement;
The if statements are executed from top to down. In this, if any one of if condition is true, then the statement associated with that true if condition is executed, and rest are bypassed. The final else is default condition. If all other conditions fail, the the last else statement is executed. if there is no final else and all other conditions fail, no action take place.
An example program is:
class ifladderdemo
{
public static void main(String args[])
{
int m=4;
String s;
if(m==12||m==1||m==2)
s=”winter”;
else if(m==3||m==4||m==5)
s=”spring”;
else if(m==6||m==7||m==8)
s=”summer”;
else
s=”autumn”;
System.out.println(“april is in”+s);
}
}
Output: april is in spring.
(ii) switch: It is a java’s multiway branch statement. It provides better alternative than larger if else if ladder. The general form of switch is:
switch(expression)
{
case value1: // statement sequence
break;
case value2: //statement sequence
break;
.
.
.
case valueN: //statement sequence
break;
default: //default statement sequence
}
The expression must be of type byte, short, int or char. Each of the values of case must be type compatible with type of expression. Duplicate case values are not allowed.
Switch works as: The value of the expression is compared to all case values in the switch body. If any one is matched to expression value, the statement sequence associated with that case is executed. If none of case values matched with value of expression, then default statement sequence is executed. If none of case values matches and no default is present, no further action take place.
Every case statement sequence ends with break which transfers control to the first statement that follows the switch.
An example is:
class switchdemo
{
public static void main(String args[])
{
for(int i=0;i<6;i++)
{
switch(i)
{
case 0: System.out.println(i is zero”);
break;
case 1: System.out.println(i is one”);
break;
case 2: System.out.println(i is two”);
break;
case 3: System.out.println(i is three”);
break;
default: System.out.println(i is greater than 3”);
}
}
}
}
Output:
i is zero
i is one
i is two
i is three
i is greater than 3
i is greater than 3
In this, for each loop execution, the statements associated with case values matches with i are executed. All others are bypassed. After i became greater than 3, default is executed because no case values match with i.
Note: If break is omitted in any case, execution continues into next case.
The improved version of If else if ladder is shown for switch is as follows:
class switchdemo
{
public static void main(String args[])
{
int m=4;
String s;
switch(m)
{
case 12:
case 1:
case 2: s=”winter”;
break;
case 3:
case 4:
case 5: s=”spring”;
break;
case 6:
case 7:
case 8: s=”summer”;
break;
case 9:
case 10:
case 11: s=”autumn”;
break;
default: s=”bogus month”;
}
System.out.println(“april is in”+s);
}
}
Output:
april is in spring
Nested switch: It contains another switch in it.
The important difference between if’s and switch are:
(i) The switch differs from if in that switch can only test for equality where as if can evaluate any type of boolean expression.
(ii) No two case values in the same switch can have identical values.
(iii) A switch is more efficient than a set of nested ifs.
Iterative Statements: These are used to execute certain collection of statements repeatedly.
Java provides three types of iteration statements such as while, do while and for.
(a) while: It is java’s most fundamental looping statement. It executes its block of statements as long as condition is true. It’s general form is
while(condition)
{
// body
}
The condition may be any boolean expression. The curly braces are unnecessary if only a single statement is being executed. It is also called entry controlled loop because first condition is evaluated, if condition is true, its loop is executed until condition made false.
The while loop body cal also be empty.
An example is
i=100,j=200;
while(++i<=–j);
System.out.println(mid pointis”+i);
Output produced is 150.
(b) do while: There are some times to execute the loop at least once and also to check conditional expression at termination of the loop. Java provides do while which satisfies both of these.
The general form of do-while is
do
{
// body of the loop
} while(condition);
Working of this loop is it first executes loop body and then evaluates condition. If the condition is true, loop will repeat. Otherwise, loop terminates. The condition must of Boolean type.
It is also called exit controlled loop.
An example is:
int n=5;
do
{
System.out.println”tick”+n);
}while(–n>0);
Output is:
tick: 5
tick: 4
tick: 3
tick: 2
tick: 1
tick: 0
The loop terminates when n becomes 0.
for loop: It is most powerful and versatile construct and it’s general from is
for( initialization; condition; iteration) where this loop sets initial value to loop control variable through initialization which also acts as counter for controlling the loop. This initialization is executed only one. If condition is evaluates to true, the loop body is executed, then next incrimination is used. This process is repeated until condition fails.
The following code illustrates sum of first 10 numbers:
int i,sum=0,n=10;
for(i=1;i<=n;i++)
sum+=i;
System.out.println(“sum of first”+n+”numbers is”+sum);
Output:
sum of first 10 numbers is: 55
Note:
-
comma is used when more than one statement needs to be included in initialization or iteration parts of for loop.
-
Loops can be nested means a loop contain another loop.
Jump Statements:
These are used to transfer control from one part of the program to another part of the same program. There are three jump statements frequently used in java.
a) break: There are three uses of break. (i) it is used to exit from a statement sequence of switch construct (ii) it is used to come out of loop.
(iii) it can be used as civilized form of goto.
break is needed when to immediate terminate of loop is needed and also to bypass conditional expression and remaining code of the loop.
An example code is:
for(int i=1;i<1=100;i++)
{
if(i==5) break;
System.out.println(“ i is”+i);
}
System.out.println(“loop completed”);
Output: i is: 1
i is:2
i is:3
i is:4
loop completed.
Note: break can also be in form break label: where label specifies name of the label that identifies block of code. When this form executes, control transferred out of named block of code.
Example code is:
boolean t=true;
first: {
second: {
third: {
System.out.println(“before break”);
if(t) break second;
System.out.println(“this won’t execute”);
}
System.out.println(“this won’t execute”);
}
System.out.println(“this is after second block”);
}
Output: before break
this is after second block
b ) continue: It is used to stop remaining of the loop code (current iteration) and give control to next immediate iteration.
An example is:
for(int i=0;i<10;i++)
{
System.out.print(i+” “);
if(i%2==0) continue;
System.out.println();
}
Output is:
0 1
2 3
4 5
6 7
8 9
Note: Like break, continue also has a label which indicates which enclosing loop to execute.
c ) return: It is used to explicitly return something from a method. It causes transfers control back to caller of the method.
boolean t=true;
System.out.println(“before return”);
if(t) return;
System.out.println(“this won’t execute”);
Output: before return . In this, when return is executed , control transferred to caller of the method.
Note: At time, when return is executed in a method returns control back to caller of the method.
OOPS/JAVA:Operators
by hkesavaraju on Feb.27, 2010, under Java
Operators: An operator is a symbol that instructs the computer to perform certain mathematical and logical operations. Operators are needed to manipulate the data.
Arithmetic operators: Java provides all basic arithmetic operators. These operate on any numeric data types but these are not applicable to non numeric data. The arithmetic operators are listed below in a table.
-
operator
meaning
+
addition
-
subtraction
*
multiplication
/
division
%
modulo
Integer arithmetic: It means the operation involved in evaluating an integer arithmetic expression. An integer arithmetic expression contains only arithmetic operators and integer operands.
The examples are:
The following results use integer operands a & b with values 14 & 4.
a-b=10 a+b=18 a*b=56 a/b=3 a%b=2
where % results remainder after integer division.
Real Arithmetic: In this, the operands can be either scientific or exponential floating point type. The expression that contains only floating point types in an arithmetic expression is called real expression and the operation involved in this process is called real arithmetic.
Modulus(% ) operator can also applied to floating point values in which % returns floating point equivalent of integer division.
Ex: float a=20.5,b=6.4 then a%b results 1.3
2.7.1.3 Mixed mode arithmetic: In this, some operands are integers and others are reals. Such an expression is known as real arithmetic expression and the operation involved is called real arithmetic. This mixed mode expression can be converted to real expression by translating all integer operands to real operands.
2.7.2 Relational operators: These type of operators are needed when two quantities need to be compared. The relational expression contains any of relational operators. The output of any relational expression is Boolean type. The following table shows the relational operators:
|
operator |
meaning |
|
< |
less than |
|
<= |
less than or equal to |
|
> |
greater than |
|
>= |
greater than or equal to |
|
== |
equal to |
|
!= |
not equal to |
A simple realtional expression can contain only one relational operator and is as follows:
ae-1 relational operator ae-2 where ae-1 and ae-2are arithmetic expressions which may be constants, variables or combination of them.
When arithmetic expressions are used on either side of a relational operator, then aithmetic expressions are evaluated first and then results are compared.
The relational expressions are used in decision statements such as if, while to decide the course of action of a running program.
2.7.3 Logical operators: These are listed in a table.
|
operator |
meaning |
|
&& |
Logical AND |
|
|| |
Logical OR |
|
! |
Logical NOT |
The && and || are used to form compound conditions by combining two or more relations.
An example is: a>b && x==10
A logical expression contains two or more relational expressions and is also called compound relational expresion.
|
Op-1 |
Op-2 |
Op-1 && op-2 |
Op-1 || op-2 |
|
1 |
1 |
1 |
1 |
|
1 |
0 |
0 |
1 |
|
0 |
1 |
0 |
1 |
|
0 |
0 |
0 |
0 |
Note:
-
op-1 && op-1 is true if both op-1 andop-2 are true.false otherwise.
-
Op-1||op-2 is false if both are false.otherwise returns true.
2.7.4 Assignment operators: These are used to assign the value of the expression to a variable. Java has a set of short hand assignment operators and it’s general syntax is
v op=exp; where v is a variable, exp is an expression and op is a binary operator. It is also equivalent to v=v op exp;
An example is (i) compute x+=y+1 when y is 2 and old value of x is 5, then x=x+y+1=5+2+1=8 is resulted.
The advantages of assignment operators are:
-
This form is easy to write because what appears on left hand side need not be repeated.
-
The statement is more concise and easier to read.
-
Using of this operator results in a more efficient code.
2.7.5 Increment and decrement operators: Java has two useful operators which are not found in other languages. They are increment & decrement operators.
(i) ++: It adds 1 to the operand. There are two types of ++ operators. They are
a) pre ++: It increments the operand by 1 and assigns to target variable.
b) post ++: It assigns the operand to target variable and later it is incremented.
An example is :
m=5;
y=++m means value of y & also m is 6.
where as for the same statements such as m=5;
y=m++; where y is 5 and m is 6.
(ii) –: It substracts 1 from the operand. It also has two types. They are
-
pre –: It decrements the operand by 1 and assigns to target variable.
-
post –: It assigns the operand to target variable and later it is decremented.
These ++ or – can also be used in subscripted variables.
2.7.6 Conditional operator: The ?: is also called ternary operator and is used to construct conditional expressions of the form as
exp1? exp2: exp3
It’s operation is: In this ,exp1 is evaluated. If exp1 is true or non zero, exp2 is evaluated and becomes the value of the conditional expression. otherwise, exp3 is evaluated and that value becomes value of conditional expression.
a=10;
b=15;
x=(a>b)?a:b;
In this, exp1 is a>b is false, exp3 is evaluated means b that can be assigned to x. So, x is 15.
This can also be written using if else as follows:
if(a>b)
x=a;
else
y=b;
2.7.7 Bitwise operators: These are used to manipulate the values at bit level. These are used in testing the bits or shifting them to right or left. Bitwise operators may not be applied to float or double. The following table lists bit wise operators:
|
operator |
meaning |
|
|
& |
bitwise AND |
op1 & op2 returns 1 if either of the bits read is 1.otherwise 0 |
|
| |
bitwise OR |
op1 & op2 returns 0 if both bits are 0. otherwise 1 |
|
ˆ |
bitwise exclusive OR |
it returns 1 if both bits are opposite. otherwise 0 |
|
~ |
One’s complement |
it returns 0 if the bit value is 1. otherwise, 1 |
|
<< |
Shift left |
An example : int a=8; x=a<<2; it returns 32 because a is shifted two times left. |
|
>> |
Shift right |
An example : int a=8; x=a>>2; it returns 2 because a is shifted two times right. |
|
>>> |
Shift right with zero fill |
int a=-1; take two complement when >>> is called on it. x=a>>>24; 2’s complement for -1: 11111111 11111111 11111111 11111111 results 00000000 00000000 00000000 11111111. The unsigned shift >>> fills 0 at top order bit after each right shift. |
2.7.8 Special operators: There are two special operators used such as instanceOf and dot(.) operator.
(i) instanceOf(): It is an object reference operator that returns true if object on left hand side is an instance of the class given on right hand side. This operator allows to determine whether the object belongs to a particular class or not.
An example is : person instanceOf student returns true if person belongs to student. otherwise false.
(ii) dot operator: It is used to access the instance variables or methods of class objects.
An example is: ob is an object for box class which contain double variables w,h,d and area() method. the dot operator is used to access them using its object ob.
ob.w
ob,h
ob.d
ob.area();
This operator is also used to access the class from a package and also sub package from it.
JNTU RO7 ECE PULSE AND DIGIATAL CIRCUITS SYLLABUS
by shaik.umar ali on Feb.27, 2010, under Syllabus Books
PULSE AND DIGITAL CIRCUITS
UNIT I
LINEAR WAVESHAPING :
High pass, low pass RC circuits, their response for sinusoidal, step, pulse, square and ramp inputs. RC network as differentiator and integrator, attenuators, its applications in CRO probe, RL and RLC circuits and their response for step input, Ringing circuit.
UNIT II
NON-LINEAR WAVE SHAPING :
Diode clippers, Transistor clippers, clipping at two independent levels, Transfer characteristics of clippers, Emitter coupled clipper, Comparators, applications of voltage comparators, clamping operation, clamping circuits using diode with different inputs, Clamping circuit theorem, practical clamping circuits, effect of diode characteristics on clamping voltage, Transfer characteristics of clampers.
UNIT III
SWITCHING CHARACTERISTICS OF DEVICES :
Diode as a switch, piecewise linear diode characteristics, Transistor as a switch, Break down voltage consideration of transistor, saturation parameters of Transistor and their variation with temperature, Design of transistor switch, transistor-switching times.
UNIT IV
MULTIVIBRATORS :
Analysis and Design of Bistable, Monostable, Astable Multivibrators and Schmitt trigger using transistors.
UNIT V
TIME BASE GENERATORS :
General features of a time base signal, methods of generating time base waveform, Miller and Bootstrap time base generators – basic principles, Transistor miller time base generator, Transistor Bootstrap time base generator, Current time base generators.
UNIT VI
SYNCHRONIZATION AND FREQUENCY DIVISION :
Principles of Synchronization, Frequency division in sweep circuit, Astable relaxation circuits, Monostable relaxation circuits, Synchronization of a sweep circuit with symmetrical signals, Sine wave frequency division with a sweep circuit.
UNIT VII
SAMPLING GATES :
Basic operating principles of sampling gates, Unidirectional and Bi-directional sampling gates, Reduction of pedestal in gate circuits, Applications of sampling gates.
UNIT VIII
REALIZATION OF LOGIC GATES USING DIODES & TRANSISTORS :
AND, OR gates using Diodes, Resistor, Transistor Logic, Diode Transistor Logic.