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");
}
}}

Thursday, September 17, 2009

ubuntu installation process

When it comes to installing Ubuntu, there are so many useful snippets of information on blogs and guides all over the internet. If you Google “How to install Ubuntu”, you’ll see what I mean.

For an Ubuntu beginner or curious Windows intermediate user however, there’s no single, simple source of information when it comes to trying out your first Ubuntu installation. One thing I have noticed is that there’s a lot of technical jargon and sometimes unnecessary terminal commands in lengthy forum posts, but no simple “how to” guides, which I think might put some people off! A shame, when you think about how easy Ubuntu is to install, use and tweak to look really cool!

This post will talk you through your first Ubuntu installation, hopefully teaching you everything you need to know to give Ubuntu a try without breaking or removing your existing Windows installation. The end result will be a “vanilla” Ubuntu Installation running simultaneously with your Windows installation using either the GRUB bootloader, or WUBI, depending on how far you’d like to go on your first Ubuntu experience.

Ubuntu desktop - running Compiz

I hope my guide makes installing Ubuntu an enjoyable, simple experience. By the end of the guide you should have a dual boot Windows / Ubuntu machine that happily plays music, video, and acts as a perfectly usable home office computer with Openoffice 3.0. For the really adventurous you could even run Windows XP inside Virtualbox, which is linked to later on in the guide. The Ubuntu OS is unique and seriously cool, so, enjoy the trip.

The all new Ubuntu login screen

If you’re planning on installing the latest version of Ubuntu (Jaunty Jackalope 9.04) you can install Ubuntu straight from the CD inside Windows or from a USB stick and the install process can takes care of formatting your hard drive partition for you. You might not yet have a spare partition to do this, so I’ve covered shrinking your existing Windows partition to make space for Ubuntu here.

How to install Ubuntu from a CD

1) Download the Ubuntu ISO from http://www.ubuntu.com/getubuntu/download and save to your desktop

2) Burn the ISO image to a blank CD using Roxio CD creator or similar:

burn a disc image with roxio

3) Run the CD from “My Computer” – the CD should ask permission to run at which point you’ll see this option screen:

4) If you’d like to install Ubuntu using Wubi, select “install inside Windows” and follow the instructions. Installing with WUBI is ideal for a first taste of Ubuntu as you can remove from add/remove programs in Windows later on. This install process is really easy but you don’t get the same performance as if Ubuntu had a separate partition running on its EXT3 file system. The following screens are all based on the Wubi installer process, so you can follow the rest of the instructions below.

If you’d like to install Ubuntu separately to Windows, then skip to point 7) below.

Here’s what you see next:

Wubi installer

If you’ve got the space on your hard drive, go for 30gb or more for the installation size.

5) Now configure your installation using the simple settings options. You can specify the location of the Ubuntu installation on your Windows partition, the size of the Ubuntu installation, the Ubuntu flavour (Ubuntu, Kubuntu, Xubuntu, etc), your preferred language, and a username and password for the Ubuntu system.

When you click install, you’ll see this screen:

As soon as the files have finished downloading, you’ll see this:

Time to reboot Wubi installer

6) That’s it! Click reboot now, and select “Ubuntu” on the startup screen. You now have a fully functional dual boot Windows / Ubuntu machine.

If you’d like to install Ubuntu separately to Windows, then follow these instructions:

7) Click “Demo and full installation” and your computer will restart and boot into Ubuntu.

It’s worth saying at this point that you’re about to install Ubuntu on an entirely separate drive partition. That means, you need to make sure you have enough space on your computers hard drive to accomodate the new setup. Keir Thomas found that a partition less than 4gb would lead Ubuntu to crash during install in his first look at Ubuntu 9.04 over at Lifehacker.

Here’s a guide on how to resize or shrink your Windows Vista partition. Follow those instructions before you reboot into the live version of Ubuntu and you’ll have a really easy time during the following steps. Maybe you’d like to install from a USB? Let’s have a quick look at the process of installing from a USB before we continue:

Here’s how to install Ubuntu on a USB drive from Windows Vista:

8) Format your USB stick with a FAT32 partition from Windows. You can get to the format dialogue by opening My Computer and right mouse clicking the removable drive icon. Click “Format” and follow the settings in the image below. You need a minimum 2gb USB stick.

format your USB drive in Windows Vista

9) Download UnetBootin. UNetbootin allows for the installation of various Linux/Ubuntu distributions to a partition or USB drive, so it’s no different from a standard install, only it doesn’t need a CD. The coolest thing about the application is that it’s a “portable” app. You don’t need to install it into Windows meaning UNetbootin will run on your Windows PC without “admin” privileges.

using unetbootin to install the new ubuntu jaunty jackalope

The new version of Ubuntu isn’t in the Distribution list supplied with UNetbootin yet, so use the downloaded Ubuntu ISO from earlier on. Add the ISO using the “Diskimage”, make sure your USB drive is selected below and click OK.

The ISO transfers to the USB pretty quickly, so soon after you click OK you’ll see this screen:

unetbootin complete

10) That’s it – when the installation process is complete, restart your computer and make sure it’s set up to boot from USB. On my HP Laptop, pressing F9 on the boot screen shows a boot order menu. Selecting “USB Hard Drive” follows a black screen, an Ubuntu logo, and finally, your new Ubuntu desktop appears.

Completing your Ubuntu installation, step by step

Installing Ubuntu is so easy that it requires very little effort past this point. If you’ve managed to repartition your hard drive and restart your computer you’ll sail through the next few steps:

11) Click “install” on the live desktop (top left)

vanilla Ubuntu desktop

12) Choose your language in the welcome screen

welcome1

13) Choose your location

Choose location

14) Choose your keyboard layout

welcome31

15) Set up your disk partition. This is probably the most “technical” part of the installation. When I shrunk my Windows Vista drive volume, I never formatted the new partition, which means the “use the largest continuous free space” option works nicely:

Set up a disk partition for Ubuntu

16) Choose your username and password:

Choose your Ubuntu Password

17) Migrate your Windows documents and settings

Migrate your Windows settings

18) You’re now ready to install your new Ubuntu installation

Ready to install

kubuntu installation process


Kubuntu is a user friendly operating system based on KDE, the K Desktop Environment. With a predictable 6 month release cycle and part of the Ubuntu project, Kubuntu is the GNU/Linux distribution for everyone.

Kubuntu is an entirely open source operating system built around the Linux kernel. The Kubuntu community is built around the ideals enshrined in the Ubuntu Philosophy: that software should be available free of charge, that software tools should be usable by people in their local language and despite any disabilities, and that people should have the freedom to customize and alter their software in whatever way they see fit.

If you want to download Kubuntu click here . Afte downloading .iso image from the download link you need to burn a CD after that you need to boot from your kubuntu cd you should see the following screen in this screen select “start or install kubuntu” and press enter.

Now you can see on next screen kubuntu cd is loading

Now your next screen is kubuntu initializing

After loading complete desktop you can see the screen including the two icons like below.Now if you want to install kubuntu just click on install icon on your desktop.

Now you need to select you installation language in this i have selected english and press continue

Next step is you need to select your country and time zone in this i have selected uk as country and london time zone and press continue

Now you need to select your keyboard language here i have selected United Kingdom and press continue

Now you need to create user and assign the hostname for your computer and press continue

Here you can see Hard Disks initializing

Now you need to select how you want to partition your hard disk.In this example i am selecting “manually edit partition table” and click on forward

Now you can See the following screen with the disks available in your machine here you need to create partitions for this you need to select the available freespace and in this example you can see the 8GB of space for this installation here i am going create a partitions you need to right click and select create partition table.

Now you can see the following screen asking for your confirmation to create partition table click yes

Now you should see the following screen with the available space now you need to create a partitions by cliking on create button at the top of the menu

Now you can see the following screen here you can select new size,partition type and click on add.In this example i am entering size as 100 mb and partition type as ext3 and click on ok

Now you need to create another partition using the available space and click ok

Here you can see the two created partitions and click on forward

Confirm the commit changes to your hard disk by clicking on yes

Now you can see the completed changes successfully and click on ok

Here you need to create a mount points by selecting mount point and partition and click on continue

Collecting all the required information for installation in progress

Here is the all the list of information for available for installation here you need to click on install to start the installation.

Creating filesystem in progress

Installation in progress and it shows the copying files percentage.

Installation Completed Succesfully and you need to restart the system by clicking “Restart Now”

Network Configuration in Kubuntu

Most ethernet configuration is centralized in a single file, /etc/network/interfaces. If you have no ethernet devices, only the loopback interface will appear in this file, and it will look something like this:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback
address 127.0.0.1
netmask 255.0.0.0

If you have only one ethernet device, eth0, and it gets its configuration from a DHCP server, and it should come up automatically at boot, only two additional lines are required:

auto eth0
iface eth0 inet dhcp

The first line specifies that the eth0 device should come up automatically when you boot. The second line means that interface (“iface”) eth0 should have an IPv4 address space (replace “inet” with “inet6” for an IPv6 device) and that it should get its configuration automatically from DHCP. Assuming your network and DHCP server are properly configured, this machine’s network should need no further configuration to operate properly. The DHCP server will provide the default gateway (implemented via the route command), the device’s IP address (implemented via the ifconfig command), and and DNS servers used on the network (implemented in the /etc/resolv.conf file.)

To configure your ethernet device with a static IP address and custom configuration, some more information will be required. Suppose you want to assign the IP address 192.168.0.2 to the device eth1, with the typical netmask of 255.255.255.0. Your default gateway’s IP address is 192.168.0.1. You would enter something like this into /etc/network/interfaces:

iface eth1 inet static
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1

In this case, you will need to specify your DNS servers manually in /etc/resolv.conf, which should look something like this:

search mydomain.com
nameserver 192.168.0.1
nameserver 4.2.2.2

The search directive will append mydomain.com to hostname queries in an attempt to resolve names to your network. For example, if your network’s domain is mydomain.com and you try to ping the host “mybox”, the DNS query will be modified to “mybox.mydomain.com” for resolution. The nameserver directives specifiy DNS servers to be used to resolve hostnames to IP addresses. If you use your own nameserver, enter it here. Otherwise, ask your Internet Service Provider for the primary and secondary DNS servers to use, and enter them into /etc/resolv.conf as shown above.