Thursday, 10 May 2012

Whether given no. is Armstrong or not



/*Write a program to find whether given no. is Armstrong or not. 

 Example :           Input - 153       

 Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */

class Armstrong{
      public static void main(String args[]){
      int num = Integer.parseInt(args[0]);
      int n = num; //use to check at last time

Tuesday, 8 May 2012

Convert given no. of days into months and days



/* Write a program to convert given no. of days into months and days.

  (Assume that each month is of 30 days)

  Example :         

  Input - 69  

 Output - 69 days = 2 Month and 9 days */

Program to generate a Triangle



/*Write a program to generate a Triangle.

 eg:

  1
  2 2
  3 3 3
  4 4 4 4

 and so on as per user given number */

class Triangle{
      public static void main(String args[]){

Program to Swap the values



/* Write a program to Swap the values */

class Swap{
      public static void main(String args[]){
      int num1 = Integer.parseInt(args[0]);
      int num2 = Integer.parseInt(args[1]);
      System.out.println("\n***Before Swapping***");
      System.out.println("Number 1 : "+num1);
      System.out.println("Number 2 : "+num2);

Program to Display Multiplication Table



/* Program to Display Multiplication Table */

class MultiplicationTable{
      public static void main(String args[]){
      int num = Integer.parseInt(args[0]);
      System.out.println("*****MULTIPLICATION TABLE*****");

Concatenate string using for Loop



/* Write a program to Concatenate  string using for Loop   Example:          Input - 5          Output - 1 2 3 4 5 */


class Join{
      public static void main(String args[]){
      int num = Integer.parseInt(args[0]);

Sunday, 6 May 2012

JavaServer Pages

  Java Server Pages (JSP) 

It is a Java technology that allows software developers to dynamically generate HTML, XML or other types of documents in response to a Web client request. The technology allows Java code and certain pre-defined actions to be embedded into static content.

The JSP syntax adds additional XML-like tags, called JSP actions, to be used to invoke built-in functionality. Additionally, the technology allows for the creation of JSP tag libraries that act as extensions to the standard HTML or XML tags. Tag libraries provide a platform independent way of extending the capabilities of a Web server. JSPs are compiled into Java Servlets by a JSP compiler. A JSP compiler may generate a servlet in Java code that is then compiled by the Java compiler, or it may generate byte code for the servlet directly.
"JavaServer Pages" is a technology released by Sun.

Java Servlet

Java Servlet

The Servlet API, contained in the Java package hierarchy javax.servlet, defines the expected interactions of a web container and a servlet. A web container is essentially the component of a web server that interacts with the servlets. The web container is responsible for managing the lifecycle of servlets, mapping a URL to a particular servlet and ensuring that the URL requester has the correct access rights.

A Servlet is an object that receives requests (ServletRequest) and generates a response (ServletResponse) based on the request. The API package javax.servlet.http defines HTTP subclasses of the generic servlet (HttpServlet) request (HttpServletRequest) and response (HttpServletResponse) as well as an (HttpSession) that tracks multiple requests and responses between the web server and a client. Servlets may be packaged in a WAR file as a Web application.

Moreover, servlets can be generated automatically by JavaServer Pages (JSP), or alternately by template engines such as WebMacro. Often servlets are used in conjunction with JSPs in a pattern called "Model 2", which is a flavor of the model-view-controller pattern.

History
The original servlet specification was created by Sun Microsystems (version 1.0 was finalized in June 1997). Starting with version 2.3, the servlet specification was developed under the Java Community Process. JSR 53 defined both the Servlet 2.3 and JavaServer Page 1.2 specifications. JSR 154 specifies the Servlet 2.4 and 2.5 specifications. As of May 10, 2006, the current version of the servlet specification is 2.5.

In his blog on java.net, Sun veteran and GlassFish lead Jim Driscoll details the history of servlet technology. James Gosling first thought of servlets in the early days of Java, but the concept did not become a product until Sun shipped the Java Web Server product. This was before what is now the Java Platform, Enterprise Edition was made into a specification.

Web containers
A Web container is a computer program that runs Web applications. Web containers are also sometimes called Web engines. Like the other Java APIs, different vendors provide their own implementation. Below is a list of some of the free web containers. (Note that 'free' means that commercial use is free. Some of the commercial containers, e.g. Resin and Orion, make ideal development containers and are also free to use in a server environment for non-profit organizations).

Non-commercial web containers



* Java System Application Server is developed by Sun.
* Apache Tomcat (formerly Jakarta Tomcat) is an open source web container available free of charge under the Apache Software License. It is used in the official reference implementation and has a reputation for being stable.
* Jetty
* Jaminid contains a higher abstraction than servlets.
* Enhydra
* jo!
* Winstone supports specification v2.4, has a focus on minimal configuration and the ability to strip the container down to only what you need.
* tjws spec 2.4, small footprint, modular design

Thursday, 3 May 2012

Flow control and Exception in java


 Flow Control and Exceptions

   Unreachable statements produce a compile-time error.
while (false) { x = 3; } // won't compile
for (;false;) { x =3; } // won't compile
if (false) {x = 3; } // will compile, to provide the ability to conditionally compile the code.
·         Local variables already declared in an enclosing block, therefore visible in a nested block cannot be re-declared inside the nested block.
·         A local variable in a block may be re-declared in another local block, if the blocks are disjoint.
·         Method parameters cannot be re-declared.

1.        Loop constructs

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