Monday, 30 April 2012

Hardware Basics

1. Which of the following components found on a motherboard is the most visible?

A. Keyboard connector
B. BIOS chip
C. Expansion slots
D. Power connectors


2. Which of the following BEST describes the difference between the "baby" AT and ATX motherboards?

A. The "baby" AT motherboard allows for the installation of more than two full- length expansion cards whereas the ATX motherboard allows for only one or two.
B. The processor, memory, and expansion slots are all in line with each other on a "baby" AT motherboard, whereas the ATX motherboard has the processor and memory slots at right angles to the expansion cards.
C. The ATX motherboard allows for the installation of more than two full-lengthexpansion cards, whereas the "baby" AT allows for only one or two.
D. The "baby" AT motherboard has a 20-pin power connector while the ATX has a12-pin power connector.
(Select two options)


3. Which of the following memory module form factors are commonly used for laptops?

A. Dual Inline Memory Modules (DIMMs)
B. Small Outline DIMMs (SODIMMs)
C. Single Inline Memory Modules (SIMMs)
D. Rambus Inline Memory Modules (RIMMs)


4. Which of the following are SCSI types that allow for 16 devices, including theadapter, to be connected on a single shared cable?

A. Ultra Wide SCSI
B. Fast SCSI
C. Ultra SCSI
D. Fast Wide SCSI
E. Ultra 2 SCSI
(Select two options)

5. What do you call the part of a CD-ROM drive's head assembly that moves acrossthe disk to read it?

A. Read/Write Actuator.
B. The Mechanical Frame.
C. The Head Actuator.
D. The Disk Spindle

6. What is clock speed of the AGPx8 expansion slot?

A. 66 MHz
B. 133 MHz
C. 266 MHz
D. 533 MHz

7. Which of the following components on the motherboard usually house the IDEconnectors?

A. PCI bus
B. North Bridge.
C. ISA bus.
D. South Bridge.

8 When a technician upgrades firmware on a motherboard he has to ______.

A. flash the BIOS
B. replace the CMOS chip
C. replace the BIOS
D. reset the CMOS

9 In which of the following is the output from a power supply rated?

A. Voltage.
B. Watts.
C. Hertz.
D. Ohms

10. When connecting the power cable of an AT power supply to the mother board,which two wires on the power connectors (P8/P9) should be together?

A. The green wires.
B. The white wires.
C. The black wires.
D. The brown wires.

Friday, 27 April 2012

Modifiers in java

1.        Modifiers are Java keywords that provide information to compiler about the nature of the code, data and classes.

2.        Access modifiers - public, protected, private
·         Only applied to class level variables. Method variables are visible only inside the method.
·         Can be applied to class itself (only to inner classes declared at class level, no such thing as protected or private top level class)
·         Can be applied to methods and constructors.
·         If a class is accessible, it doesn't mean, the members are also accessible. Members' accessibility determines what is accessible and what is not. But if the class is not accessible, the members are not accessible, even though they are declared public.
·         If no access modifier is specified, then the accessibility is default package visibility. All classes in the same package can access the feature. It's called as friendly access. But friendly is not a Java keyword. Same directory is same package in Java's consideration.

·         'private' means only the class can access it, not even sub-classes.  So, it'll cause access denial to a sub-class's own variable/method.
·         These modifiers dictate, which classes can access the features. An instance of a class can access the private features of another instance of the same class.
·         'protected' means all classes in the same package (like default) and sub-classes in any package can access the features. But a subclass in another package can access the protected members in the super-class via only the references of subclass or its subclasses. A subclass in the same package doesn't have this restriction. This ensures that classes from other packages are accessing only the members that are part of their inheritance hierarchy.
·         Methods cannot be overridden to be more private. Only the direction shown in following figure is permitted from parent classes to sub-classes.
private à friendly (default) à protected à public
                Parent classes                                                                   Sub-classes

3.        final
·         final features cannot be changed.
·         The final modifier applies to classes, methods, and variables.
·         final classes cannot be sub-classed.
·         You can declare a variable in any scope to be final.
·         You may, if necessary, defer initialization of a final local variable. Simply declare the local variable and initialize it later (for final instance variables. You must initialize them at the time of declaration or in constructor).
·         final variables cannot be changed (result in a compile-time error if  you do so )
·         final methods cannot be overridden.
·         Method arguments marked final are read-only. Compiler error, if trying to assign values to final arguments inside the method.
·         Member variables marked final are not initialized by default. They have to be explicitly assigned a value at declaration or in an initializer block. Static finals must be assigned to a value in a static initializer block, instance finals must be assigned a value in an instance initializer or in every constructor. Otherwise the compiler will complain.

·         A blank final is a final variable whose declaration lacks an initializer.
·         Final variables that are not assigned a value at the declaration and method arguments that are marked final are called blank final variables. They can be assigned a value at most once.
·         Local variables can be declared final as well.
·         If a final variable holds a reference to an object, then the state of the object may be changed by operations on the object, but the variable will always refer to the same object.
·         This applies also to arrays, because arrays are objects; if a final variable holds a reference to an array, then the components of the array may be changed by operations on the array, but the variable will always refer to the same array
·          A blank final instance variable must be definitely assigned  at the end of every constructor of the class in which it is declared; otherwise a compile-time error occurs.
·         A class can be declared final if its definition is complete and no subclasses are desired or required.
·         A compile-time error occurs if the name of a final class appears in the extends clause of another class declaration; this implies that a final class cannot have any subclasses.
·         A compile-time error occurs if a class is declared both final and abstract, because the implementation of such a class could never be completed.
·         Because a final class never has any subclasses, the methods of a final class are never overridden   

4.        abstract
·         Can be applied to classes and methods.
·         For deferring implementation to sub-classes.
·         Opposite of final, final can't be sub-classed, abstract must be sub-classed.
·         A class should be declared abstract,
1.        if it has any abstract methods.
2.        if it doesn't provide implementation to any of the abstract methods it inherited
3.        if it doesn't provide implementation to any of the methods in an interface that it says implementing.
·         Just terminate the abstract method signature with a ';', curly braces will give a compiler error.
·         A class can be abstract even if it doesn't have any abstract methods.

5.        static
·         Can be applied to nested classes, methods, variables, free floating code-block (static initializer)
·         Static variables are initialized at class load time. A class has only one copy of these variables.
·         Static methods can access only static variables. (They have no this)
·         Access by class name is a recommended way to access static methods/variables.
·         Static initializer code is run at class load time.
·         Static methods may not be overridden to be non-static.
·         Non-static methods may not be overridden to be static.
·         Abstract methods may not be static.
·         Local variables cannot be declared as static.
·         Actually, static methods are not participating in the usual overriding mechanism of invoking the methods based on the class of the object at runtime. Static method binding is done at compile time, so the method to be invoked is determined by the type of reference variable rather than the actual type of the object it holds at runtime.
Let's say a sub-class has a static method which 'overrides' a static method in a parent class.  If you have a reference variable of parent class type and you assign a child class object to that variable and invoke the static method, the method invoked will be the parent class method, not the child class method.  The following code explains this.
public class StaticOverridingTest {
  public static void main(String s[]) {
                Child c = new Child();
                c.doStuff(); // This will invoke Child.doStuff()
 
                Parent p = new Parent();
                p.doStuff(); // This will invoke Parent.doStuff()
                p = c;
                p.doStuff(); // This will invoke Parent.doStuff(), rather than Child.doStuff()               
  }
}
class Parent {
  static int x = 100;
  public static void doStuff() {
                System.out.println("In Parent..doStuff");
                System.out.println(x);
  }
}
class Child extends Parent {
  static int x = 200;
  public static void doStuff() {
                System.out.println("In Child..doStuff");
                System.out.println(x);
  }
 }

6.        native
·         Can be applied to methods only. (static methods also)
·         Written in a non-Java language, compiled for a single machine target type.
·         Java classes use lot of native methods for performance and for accessing hardware Java is not aware of.
·         Native method signature should be terminated by a ';', curly braces will provide a compiler error.
·         native doesn't affect access qualifiers. Native methods can be private.
·         Can pass/return Java objects from native methods.
·         System.loadLibrary is used in static initializer code to load native libraries. If the library is not loaded when the static method is called, an UnsatisfiedLinkError is thrown.

7.        transient
·         Can be applied to class level variables only.(Local variables cannot be declared transient)
·         Transient variables may not be final or static.(But compiler allows the declaration, since it doesn't do any harm. Variables marked transient are never serialized. Static variables are not serialized anyway.)
·         Not stored as part of object's persistent state, i.e. not written out during serialization.
·         Can be used for security.

8.        synchronized
·         Can be applied to methods or parts of methods only.
·         Used to control access to critical code in multi-threaded programs.

9.        volatile
·         Can be applied to variables only.
·         Can be applied to static variables.
·         Cannot be applied to final variables.
·         Declaring a variable volatile indicates that it might be modified asynchronously, so that all threads will get the correct value of the variable.
·         Used in multi-processor environments.


Modifier
Class
Inner classes (Except local and anonymous classes)
Variable
Method
Constructor
Free floating Code block
public
Y
Y
Y
Y
Y
N
protected
N
Y
Y
Y
Y
N
(friendly)
No access modifier
Y
Y (OK for all)
Y
Y
Y
N
private
N
Y
Y
Y
Y
N
final
Y
Y (Except anonymous classes)
Y
Y
N
N
abstract
Y
Y (Except anonymous classes)
N
Y
N
N
static
N
Y
Y
Y
N
Y (static initializer)
native
N
N
N
Y
N
N
transient
N
N
Y
N
N
N
synchronized
N
N
N
Y
N
Y (part of method, also need to specify an object on which a lock should be obtained)
volatile
N
N
Y
N
N
N


Check the below links for
Operators and assignments in java
Some basic java programs:

Thursday, 26 April 2012

Reactions before the final engineering viva

Final day of Engineering VIVA

Sayali desai before her Final viva


Engrossed in studies

HCI--We hate this subject

















Operators and assignments in java


The Java programming language has included five simple arithmetic operators like + (addition), - (subtraction), * (multiplication), / (division)

1. Unary operators

1.1 Increment and Decrement operators ++ --
We have postfix and prefix notation. In post-fix notation value of the variable/expression is modified after the value is taken for the execution of statement. In prefix notation, value of the variable/expression is modified before the value is taken for the execution of statement.

x = 5; y = 0; y = x++; Result will be x = 6, y = 5

x = 5; y = 0; y = ++x; Result will be x = 6, y = 6

Implicit narrowing conversion is done, when applied to byte, short or char.
1.2 Unary minus and unary plus + -
+ has no effect than to stress positivity.

- negates an expression's value. (2's complement for integral expressions)
1.3 Negation !
Inverts the value of a boolean expression.
1.4 Complement ~
Inverts the bit pattern of an integral expression. (1's complement - 0s to 1s and 1s to 0s)

Cannot be applied to non-integral types.
1.5 Cast ()
Persuades compiler to allow certain assignments. Extensive checking is done at compile and runtime to ensure type-safety.

 2. Arithmetic operators - *, /, %, +, -
· Can be applied to all numeric types.

· Can be applied to only the numeric types, except '+' - it can be applied to Strings as well.

· All arithmetic operations are done at least with 'int'. (If types are smaller, promotion happens. Result will be of a type at least as wide as the wide type of operands)

· Accuracy is lost silently when arithmetic overflow/error occurs. Result is a nonsense value.

· Integer division by zero throws an exception.

· % - reduce the magnitude of LHS by the magnitude of RHS. (continuous subtraction)

· % - sign of the result entirely determined by sign of LHS

· 5 % 0 throws an ArithmeticException.

· Floating point calculations can produce NaN (square root of a negative no) or Infinity ( division by zero). Float and Double wrapper classes have named constants for NaN and infinities.

· NaN's are non-ordinal for comparisons. x == Float.NaN won't work. Use Float.IsNaN(x) But equals method on wrapper objects(Double or Float) with NaN values compares Nan's correctly.

· Infinities are ordinal. X == Double.POSITIVE_INFINITY will give expected result.

· + also performs String concatenation (when any operand in an expression is a String). The language itself overloads this operator. toString method of non-String object operands are called to perform concatenation. In case of primitives, a wrapper object is created with the primitive value and toString method of that object is called. ("Vel" + 3 will work.)

· Be aware of associativity when multiple operands are involved.

System.out.println( 1 + 2 + "3" ); // Prints 33

System.out.println( "1" + 2 + 3 ); // Prints 123

3. Shift operators - <<, >>, >>>

· << performs a signed left shift. 0 bits are brought in from the right. Sign bit (MSB) is preserved. Value becomes old value * 2 ^ x where x is no of bits shifted.

· >> performs a signed right shift. Sign bit is brought in from the left. (0 if positive, 1 if negative. Value becomes old value / 2 ^ x where x is no of bits shifted. Also called arithmetic right shift.

· >>> performs an unsigned logical right shift. 0 bits are brought in from the left. This operator exists since Java doesn't provide an unsigned data type (except char). >>> changes the sign of a negative number to be positive. So don't use it with negative numbers, if you want to preserve the sign. Also don't use it with types smaller than int. (Since types smaller than int are promoted to an int before any shift operation and the result is cast down again, so the end result is unpredictable.)

· Shift operators can be applied to only integral types.

· -1 >> 1 is -1, not 0. This differs from simple division by 2. We can think of it as shift operation rounding down.

· 1 << 31 will become the minimum value that an int can represent. (Value becomes negative, after this operation, if you do a signed right shift sign bit is brought in from the left and the value remains negative.)

· Negative numbers are represented in two's complement notation. (Take one's complement and add 1 to get two's complement)

· Shift operators never shift more than the number of bits the type of result can have. ( i.e. int 32, long 64) RHS operand is reduced to RHS % x where x is no of bits in type of result.

int x;

x = x >> 33; // Here actually what happens is x >> 1

4. Comparison operators - all return boolean type.

4.1 Ordinal comparisons - <, <=, > , >=
· Only operate on numeric types. Test the relative value of the numeric operands.

· Arithmetic promotions apply. char can be compared to float.
4.2 Object type comparison - instanceof
· Tests the class of an object at runtime. Checking is done at compile and runtime same as the cast operator.

· Returns true if the object denoted by LHS reference can be cast to RHS type.

· LHS should be an object reference expression, variable or an array reference.

· RHS should be a class (abstract classes are fine), an interface or an array type, castable to LHS object reference. Compiler error if LHS & RHS are unrelated.

· Can't use java.lang.Class or its String name as RHS.

· Returns true if LHS is a class or subclass of RHS class

· Returns true if LHS implements RHS interface.

· Returns true if LHS is an array reference and of type RHS.

· x instanceof Component[] - legal.

· x instanceof [] - illegal. Can't test for 'any array of any type'

· Returns false if LHS is null, no exceptions are thrown.

· If x instanceof Y is not allowed by compiler, then Y y = (Y) x is not a valid cast expression. If x instanceof Y is allowed and returns false, the above cast is valid but throws a ClassCastException at runtime. If x instanceof Y returns true, the above cast is valid and runs fine.
4.3 Equality comparisons - ==, !=
· For primitives it's a straightforward value comparison. (promotions apply)

· For object references, this doesn't make much sense. Use equals method for meaningful comparisons. (Make sure that the class implements equals in a meaningful way, like for X.equals(Y) to be true, Y instance of X must be true as well)

· For String literals, == will return true, this is because of compiler optimization.

5. Bit-wise operators - &, ^, |

· Operate on numeric and boolean operands.

· & - AND operator, both bits must be 1 to produce 1.

· | - OR operator, any one bit can be 1 to produce 1.

· ^ - XOR operator, any one bit can be 1, but not both, to produce 1.

· In case of booleans true is 1, false is 0.

· Can't cast any other type to boolean.

6. Short-circuit logical operators - &&, ||

· Operate only on boolean types.

· RHS might not be evaluated (hence the name short-circuit), if the result can be determined only by looking at LHS.

· false && X is always false.

· true || X is always true.

· RHS is evaluated only if the result is not certain from the LHS.

· That's why there's no logical XOR operator. Both bits need to be known to calculate the result.

· Short-circuiting doesn't change the result of the operation. But side effects might be changed. (i.e. some statements in RHS might not be executed, if short-circuit happens. Be careful)

7. Ternary operator

· Format a = x ? b : c ;

· x should be a boolean expression.

· Based on x, either b or c is evaluated. Both are never evaluated.

· b will be assigned to a if x is true, else c is assigned to a.

· b and c should be assignment compatible to a.

· b and c are made identical during the operation according to promotions.

8. Assignment operators.

· Simple assignment =.

· op= calculate and assign operators extended assignment operators.

· *=, /=, %=, +=, -=

· x += y means x = x + y. But x is evaluated only once. Be aware.

· Assignment of reference variables copies the reference value, not the object body.

· Assignment has value, value of LHS after assignment. So a = b = c = 0 is legal. c = 0 is executed first, and the value of the assignment (0) assigned to b, then the value of that assignment (again 0) is assigned to a.

· Extended assignment operators do an implicit cast. (Useful when applied to byte, short or char)

byte b = 10;

b = b + 10; // Won't compile, explicit cast required since the expression evaluates to an int

b += 10; // OK, += does an implicit cast from int to byte

9. General

· In Java, No overflow or underflow of integers happens. i.e. The values wrap around. Adding 1 to the maximum int value results in the minimum value.

· Always keep in mind that operands are evaluated from left to right, and the operations are executed in the order of precedence and associativity.

· Unary Postfix operators and all binary operators (except assignment operators) have left to right assoiciativity.

· All unary operators (except postfix operators), assignment operators, ternary operator, object creation and cast operators have right to left assoiciativity.

· Inspect the following code.

public class Precedence {

final public static void main(String args[]) {

int i = 0;

i = i++;

i = i++;

i = i++;

System.out.println(i); // prints 0, since = operator has the lowest precedence.

int array[] = new int[5];

int index = 0;

array[index] = index = 3; // 1st element gets assigned to 3, not the 4th element

for (int c = 0; c < array.length; c++)

System.out.println(array[c]);

System.out.println("index is " + index); // prints 3

}

}
 
Type of Operators
Operators
Associativity
Postfix operators
[] . (parameters) ++ --
Left to Right
Prefix Unary operators
++  -- + - ~ !
Right to Left
Object creation and cast
new (type)
Right to Left
Multiplication/Division/Modulus
* / %
Left to Right
Addition/Subtraction
+ -
Left to Right
Shift
>> >>> <<
Left to Right
Relational
< <= > >= instanceof
Left to Right
Equality
== !=
Left to Right
Bit-wise/Boolean AND
&
Left to Right
Bit-wise/Boolean XOR
^
Left to Right
Bit-wise/Boolean OR
|
Left to Right
Logical AND (Short-circuit or Conditional)
&&
Left to Right
Logical OR (Short-circuit or Conditional)
||
Left to Right
Ternary
? :
Right to Left
Assignment
= += -= *= /= %= <<= >>= >>>= &= ^= |=
Right to Left


Click below link for Related post:

JAVA Fundamentals 

Some basic java programs: