Friday, May 14, 2010

exception

ArithmeticException ---- Arithmetic error, such as divide-by-zero.

ArrayIndexOutOfBoundsException -- Array index is out-of-bounds.

ArrayStoreException -- Assignment to an array element of an incompatible type.

ClassCastException --- Invalid cast.

IllegalArgumentException ---- Illegal argument used to invoke a method.

IllegalMonitorStateException --- Illegal monitor operation, such as waiting on an unlocked thread.

IllegalStateException ----- Environment or application is in incorrect state.

IllegalThreadStateException ---- Requested operation not compatible with current thread state.

IndexOutOfBoundsException ------- Some type of index is out-of-bounds.

NegativeArraySizeException -------- Array created with a negative size.

NullPointerException ------- Invalid use of a null reference.

NumberFormatException ------ Invalid conversion of a string to anumeric format.

StringIndexOutOfBounds ---- Attempt to index outside the bounds of a string.

Thursday, April 22, 2010

inheritance, polymorphism,interface

Inheritance
●Benefits of Inheritance in OOP : Reusability–Once a behavior (method) is defined in a superclass, that behavior is automatically inherited by all subclasses. –Thus, you can encode a method only once and they can be used by all subclasses. –A subclass only needs to implement the differences between itself and the parent.

●In Java, all classes, including the classes that make up the Java API, are subclassed from the Object superclass.
●Superclass–Any class above a specific class in the class hierarchy.
●Subclass–Any class below a specific class in the class hierarchy.
●Superclass–Any class above a specific class in the class hierarchy.
●Subclass–Any class below a specific class in the class hierarchy.

Polymorphism
●Polymorphism–The ability of a reference variable to change behavior according to what object it is holding.–This allows multiple objects of different subclasses to be treated as objects of a single superclass, while automatically selecting the proper methods to apply to a particular object based on the subclass it belongs to.

Abstract Classes
●Abstract class –a class that cannot be instantiated. –often appears at the top of an object-oriented programming class hierarchy, defining the broad types of actions possible with objects of all subclasses of the class

An interface –is a special kind of block containing method signatures (and possibly constants) only. –defines the signatures of a set of methods, without the body. –defines a standard and public way of specifying the behavior of classes. –allows classes, regardless of their locations in the class hierarchy, to implement common behaviors. –NOTE: interfaces exhibit polymorphism as well, since program may call an interface method, and the proper version of that method will be executed depending on the type of object passed to the interface method call.

Wednesday, April 14, 2010

1. topics discussed in java 1. provide brief description per topic

Arrays
An array is a container object that holds a fixed number of values of a single type. The length of an array is established when the array is created. After creation, its length is fixed. You've seen an example of arrays already, in the main method of the "Hello World!" application. This section discusses arrays in greater detail.

Looping in Java

Loops are another essential part of modern programming languages, with no exception in Java. Their premise is simple: the computer executes some operation or group of operations until told to do otherwise or stop.

The loop comes in several variations, each with their own slight variance in structure and purpose: for loops, while loops, do-while loops, and and the brand new for-each loop. While each has differences, all consist of loosely the same structure:

  • A loop entry, or the point where the loop begins execution
  • A loop test, where the computer tests to see if the loop should begin, repeat, or skip to the next command in the program
  • Iteration, or a single cycle through the loop's group of operations
  • A termination condition, or the specified situation or event that a loop reaches when it's time to stop looping

Java Control Structures

switch (the Java case statement)

//note: shown using char.   //Primitive types char, byte, short, or int  //  can be used in the switch.

switch (charToCheck) { case 'A' : System.out.print('A'); break; //Print 'A' if charToCheck = 'A' case 'B' : System.out.print('B'); break; //Print 'B' if charToCheck = 'B' default : System.out.print('D'); //Print 'D' if charToCheck does // not equal 'A' or 'B' }

//note: if neither break were there, // and if charToCheck = 'A', // the code would print ABD

if else

if (x > 5) {     System.out.println("x is greater than 5"); } else {     System.out.println("x is not greater than 5"); }
Strings
Strings, which are widely used in Java programming, are a sequence of characters. In the Java programming language, strings are objects.

The Java platform provides the String class to create and manipulate strings.

METHODS
1.concat()
2.length()
3.IndexOf()
4.LastIndexOf()
5.CharAt()
6.equals()
7.equalsIgnoreCase()
8.StartsWith()
9.endswith()
10.toUpperCase()
11.toLowerCase()
12.replace()
13.Substring()
Using JOptionPane

import javax.swing.JOptionPane;
indicates that we want to import the class JOptionPane from the javax.swing package.
We can also write this as,
import javax.swing.*;
The statement,
name = JOptionPane.showInputDialog("Please enter your name");
creates a JOptionPane input dialog, which will display a dialog with a message, a
textfield and an OK button as shown in the figure. This returns a String which we will
save in the name variable.
2.Introduction to java programming
● Java
– was created in 1991
– by James Gosling et al. of Sun Microsystems.
– Initially called Oak, in honor of the tree outside Gosling's window, its name
was changed to Java because there was already a language called Oak.
– The original motivation for Java
● The need for platform independent language that could be embedded in various
consumer electronic products like toasters and refrigerators.
– One of the first projects developed using Java
● a personal hand-held remote control named Star 7.
– At about the same time, the World Wide Web and the Internet were gaining
popularity. Gosling et. al. realized that Java could be used for Internet
programming.
● The Java technology is:
– A programming language
– A development environment
– An application environment
– A deployment environment
● Java Virtual Machine (JVM)
– an imaginary machine that is implemented by emulating software on a real
machine
– provides the hardware platform specifications to which you compile all Java
technology code
● Bytecode
– a special machine language that can be understood by the Java Virtual
Machine (JVM)
– independent of any particular computer hardware, so any computer with a
Java interpreter can execute the compiled Java program, no matter what
type of computer the program was compiled on
● Garbage collection thread
– responsible for freeing any memory that can be freed. This happens
automatically during the lifetime of the Java program.
– programmer is freed from the burden of having to deallocate that
memory themselves

Thursday, March 18, 2010

networking

Explain the kind of networking device required to create such an environment and why it’s the only choice for this particular kind of networking implementation.
The device required for the creation of this environment is switch (fast Ethernet), cable (fast Ethernet) and the end devices such as server and workstations.
This devices is are crucial for supporting high speed performance, an example of this is the switches compared to hubs, switch has the upper hand in performance because data request does not broadcast request to find out if this workstation needs it or not because switch distinguish the workstation that need the data and workstation that don’t need them.
In the picture you can see that I have 5 switches 2 sever and 40 imaginary workstations. The 40 workstation is divided by 4 switches consisting 10 workstation/switch and the 5th switch is connected to the 2 severs and the 4 switches is connected to the 5th switch. This setup is expensive because you have a separate switch for the 2 server but this setup will shorten the delay of data. Because the entire 4 switch is connected to the 5th switch which is for the servers so this means the approach is not linear or switch connect to another switch and so on until it will reach the server.

Tuesday, January 5, 2010

java

import java.io.*;
import java.text.*;
import java.lang.*;
class Input
{
public static void main (String [ ] args)
{
int a;
for(a=0;a<=20;a++)
System.out.print(a+"\t"+Math.sqrt(a)+"\n");
}}

import java.io.*;
import java.text.*;
import java.lang.*;
class Input
{
public static void main (String [ ] args)
{
int a,b,c;
for(a=0;a<=20;a++){
c=0;
for(b=1;b<=a;b++){
if((a%b)==0)
c++
}
if(c==1||c==2)
System.out.print(a+"\t Prime \n");
else
System.out.print(a+"\tNOT Prime \n");
}}}

import java.io.*;
import java.text.*;
import java.lang.*;
class Input
{
public static void main (String [ ] args) throws IOException
{
BufferedReader stdIn = new BufferedReader(new InputStreamReader (System.in));
int a,b,c;
System.out.println("enter number(1-20): ");
a = Int.parseInt(stdIn.readLine());
c=0;
for(b=1;b<=a;b++){
if((a%b)==0)
c++
}
if(c==1||c==2)
System.out.print(a+"\t Prime \n");
else
System.out.print(a+"\tNOT Prime \n");
}
}}