Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Generations of the Computer First Generation: 1940-1956: Vacuum Tubes First generation computers used vacuum tubes for circuitry & magnetic drum for memory. First generation computers relied on machine language, it is low level programming language understood by computers, to perform operations. Major component of this generation was vacuum tubes. Second Generation : 1956-1963: Transistors Transistors replaced vacuum tubes in second generation. Transistor was far superior than vacuum tubes. Major component of this generation was transistors. AWB 1 • Third Generation: 1964-1971: Integrated Circuits Development of Integrated circuits was hallmark of third generation. Transistors were miniaturized & placed on silicon chips called semiconductor which drastically increased speed & efficiency of computers. SSI(Small Scale Integration): IC chips contained only ten to twenty components. MSI(Medium Scale Integration): Hundred components integrated on single chip. Chips are much smaller, less expensive, reliable, fast in operation, dissipated less heat & consumed less power. AWB 2 Fourth Generation: 1971-Present: Microprocessors Thousands of integrated circuits were built onto a single silicon chip to create microprocessor. •LSI(Large Scale Integration): In this 30,000 components were integrated. •VLSI(Very Large Scale Integration): In this it is possible to integrate about one million electronic components on a single chip. It started a new revolution of computer known as Personal Computer(PC). Major component of this generation was microprocessor. Fifth Generation: Present – Future: Artificial Intelligence •ULSI(Ultra Large Scale Integration) is used to produce processor chips, having ten million electronic components. Size of main memory is larger than 1 GB. •Focuses on two concepts namely artificial intelligence & expert systems. AWB 3 • Machine Language • Machine language or machine code is the native language directly understood by the computer’s central processing unit or CPU. This type of computer language is not easy to understand, as it only uses a binary system, an element of notations containing only a series of numbers consisting of one and zero, to produce commands. • Assembly Level Language • Assembly Level Language is a set of codes that can run directly on the computer’s processor. This type of language is most appropriate in writing operating systems and maintaining desktop applications. With the assembly level language, it is easier for a programmer to define commands. It is easier to understand and use as compared to machine language. • High Level Language • High Level Languages are user-friendly languages which are similar to English with vocabulary of words and symbols. These are easier to learn and require less time to write. • They are problem oriented rather than ‘machine’ based. • Program written in a high-level language can be translated into many machine language and therefore can run on any computer for which there exists an appropriate translator. AWB 4 • Compilation • A compiler is a special program that processes statements written in a particular programming language called as source code and converts them into machine language or “machine code” that a computer’s processor uses. • Compiler translates high level language programs directly into machine language program. This process is called compilation. • Interpretation • An interpreter translates high-level instructions into an intermediate form, which it then executes. Compiled programs generally run faster than interpreted programs. The advantage of an interpreter, however, is that it does not need to go through the compilation stage during which machine instructions are generated. This process can be time-consuming if the program is long. AWB 5 Abstract Class • Abstract class is a class which contains atleast one abstract method. • Abstract method is a method that is declared, but have no implementation i.e body. • Abstract classes cannot be instantiated. • They require subclasses to provide implementation for their abstract methods by overriding them. AWB 6 Features of abstract class • • • • They cannot be instantiated. A class can inherit only one abstract class. Multiple inheritance is not allowed. Abstract class can have constructor & variables like normal classes. • It is mandatory for a subclass to override abstract methods of abstract class. AWB 7 Interface • Interface can be defined as a class which contains all the method as abstract method. • Interfaces are basically collection of methods which are public & abstract by default. • A class can inherit any number of interfaces, thus allowing multiple inheritance. • Interfaces are declared with keyword “Interface”. AWB 8 Key Features of Interface • It contains all the methods as abstract. • Classes while inheriting use keyword “extends” while interface use “Implements”. • Variables in interface are by default public, static & final. • While overriding the method from interface it needs to be declared as “public”. • It helps to implement Multiple Inheritance. AWB 9 multithreading • Multithreading enables programs to have more than one execution paths(separate) which execute concurrently. • Each such path of execution in thread. • Through multithreading , efficient utilization of system resources can be achieved. Such as maximum utilization of CPU cycles & minimizing idle time of CPU. AWB 10 Multithreading in java • Java is a multi-threaded programming language which means we can develop multi-threaded program using Java. • Every program we write has at least one thread, i.e ‘main’ thread. Whenever a program starts executing, JVM is responsible for creating the main thread & call main() method from within that thread. • A thread can either die naturally or forced to die. • A thread dies naturally when it exits the run() method normally. • A thread can always be killed or interrupted by calling interrupt() method. AWB 11 Methods to manage threads • • • • • • • getName(): Used for obtaining the threads name getPriority(): Used to obtain threads priority. isAlive(): Determine if a thread is still running. join(): Wait for a thread to terminate. run(): Entry point for a thread. sleep():Suspend a thread for a period of time. start(): start a thread by calling its run() method. AWB 12 AWB 13 • Applet may override some of the basic methods of Applet class. These methods are responsible for life cycle of an Applet. These methods are: • init() • start() • stop() • destroy() • Born State: Applet enters in this phase as soon as it is first loaded by java. This is possible by calling init() method. init() method is called only once during lifetime of an applet. In order to initialize applet we must override init() method. AWB 14 • Running state: Applet moves to running state by calling start() method of applet class. An applet moves to this phase automatically after initialization. But if applet is stopped or it goes to idle state, start() method must be called in order to force the applet again to running state. • Idle State: An Applet goes to idle state, once it is stopped from running. If we leave web page containing applet, it goes to idle state.It can be forced to stop or go to idle state by calling stop() method. • Dead State: Terminating or stopping an applet is different from destroying an applet. It goes to dead state when it is destroyed by invoking destroy() method. AWB 15 Commnon methods for displaying output 1.drawString():- This method is a member of Graphics class, used to output a string to an applet. It is typically called from paint() method. Syn: void drawString(“msg”, int x, int y); Here, “msg” is a String to be displayed. x & y are co-ordinates where output has to be displayed. 2. setBackground():- This method is used to set background color of the applet window. It belongs to the component class. Syn: void setBackground(Color anycolor); AWB 16 • 3. setForeground():- This method is similar to setBackground method, except that it is used to set color of text to be displayed on the foreground of applet window. Syn: void setForeground (Color anycolor); • 4. showStatus();- This method is used to display any string in the status window of browser or appletviewer. It belongs to Applet class. • Syn: void showStatus (“String text”); AWB 17 Graphics class • You can write java applets that can draw lines, figures of different shapes, images, text in different fonts, styles & colors. Every applet has its own area on screen known as canvas which is actually the display area. It works on coordinate system, it has the origin(0,0) in the upper left corner. Graphics class belongs to the java.awt package. AWB 18 Color class • Color class is a class which is inherited from object class. We have RGB colors as default color for monitors & TV screens. Apart from specifying a particular color, you can also create your own color in java. Color class has various constants specifying a number of common colors. • Ex. Color.Red, Color.Yellow, Color.Green AWB 19 Constructors of color class • Color(float r, float g, float b) • Creates a mix color of red(r), green(g), blue(b) and the values are in the range (0.0-1.0) • Color(int rgbValue) • Creates a mix color of red, green & blue. Bits for red component is 16-23, bits for green component is 8-15 & for blue is 0-7. • Color(int r, int g, int b) • Specify a color of mix red, green & blue values in range of (0-255). AWB 20 Font class • Font class extends Object class. Various fonts are represented by Font class to write text. • Three important attributes of Font are: • Family name: It is name of font such as “Times new roman”. • Logical Font Name: It specifies font category, such as monospaced. • Face name: It specifies specific font such as “courier italic”. AWB 21 Constructor of font class • Font( Font font): This constructor is used to create a new font from specified font. • Font (String name, int style, int size) • Three arguments to this constructor are: • Name: It specifies name of desired font. • Style: It specifies style as like Font.BOLD, Font.PLAIN etc. • Size: It specifies size of font in points • Once the font is created , setFont() method of component class is used to set it. AWB 22 Event delegation model • In event delegation model, a source generates events which are sent to one or more listeners. • Listeners are responsible for receiving the event & processing it in way required. • This model has three dimensions events, event sources, event listeners. • Events: An event is an object that describes the state change in a source. • Events are generated due to interacting with elements in GUI. ex. Pressing button, clicking mouse. AWB 23 • Event sources • A source is an object on which event occurs. Source may generate more than one type of event. • A source must register listener in order to receive notifications about specific event. • General form of registration is: public void addTypeListeners(TypeListener ref) • In above statement ‘Type’ is type of the event & ‘ref’ is reference to the event listeners for that particular event. AWB 24 • Event Listeners • A listener is an object that is notified when an event occurs. • It must register with source & it must implement methods to receive & process notifications. Methods are defined in various interfaces of java.awt.event package. • When an event occurs, source invokes appropriate method defined by listener & provides an event object as its argument. AWB 25 Listeners • ActionListener: This interface defines actionPerformed() method that is invoked when action event occurs. • Syn: void actionPerformed(ActionEvent e); • WindowListener: This interface has seven methods defined in it with following signatures. • Void windowActivated(WindowEvent e) • void windowClosed(WindowEvent e) • void windowClosing(WindowEvent e) • void windowOpened(WindowEvent e) • void windowDeactivated(WindowEvent e) • void windowIconified(WindowEvent e) AWB 26 • MouseMotionListener: This interface defines two methods. • void mouseDragged(MouseEvent e) • void mouseMoved(MouseEvent e) • MouseListener: This interface defines five methods. If the mouse is pressed & released at same time mouseClicked() is invoked. • void mouseClicked(MouseEvent e) • void mouseEntered(MouseEvent e) • void mouseExited(MouseEvent e) • void mousePressed(MouseEvent e) • void mouseReleased(MouseEvent e) AWB 27 Adapter class • Adapter class provides empty definition for all the methods of their corresponding listener interface. • Interface contains all abstract methods & it is compulsory to implement all those methods in derived class. • Above statement is true for listener also, if you are implementing a particular listener, you have to implement all the methods. AWB 28 • Following table shows different adapter classes in java.awt.event Sr. no. Adapter class Listener Interface 1 MouseAdapter MouseListener 2 MouseMotionAdapter MouseMotionListener 3 WindowAdapter WindowListener 4 KeyAdapter KeyListener 5 ComponentAdapter ComponentListener 6 ContainerAdapter ContainerListener 7 FocusAdapter FocusListener AWB 29 Awt in java • Java AWT (Abstract Windowing Toolkit) is an API to develop GUI or window-based application in java.AWT is a well-designed object oriented interface between your application & low-level resources. • The package java.awt contains all classes used for creating graphical user interfaces, painting graphics, images, colors & fonts. • A user interface element such as a button or a textbox is called a ‘component’. AWB 30 Java awt hierarchy AWB 31 • Component: It is a super class of all AWT components. These components fire events when user interacts with these components.eg. When a user clicks on a button. • Container: A Container is one which contains other awt components . A Container has a layout manager that determines the visual placement of components in the container. • Window: The Window class creates a top-level window without border & menu bar. • Panel: The Panel class is subclass of Container.It creates a window that does not have title bar & menu bar. It can have other components like button, textfield etc. • Frame: The Frame is subclass of Window & has a title bar, menu bar, border & resizing corner. It can have other components like button, textfield etc. AWB 32 Button class • It is used to create buttons. It is present in a package java.awt. Buttons are used to trigger an event in a GUI. • Constructors: 1. Button(): It is empty constructor which creates a button with no label. 2.Button(String str): This constructor creates a button with given string as label. Creation: Button b=new Button(String str); Where, ‘b’ is button object, str is string. Once it is created, it is added on applet by using method add(Button_object); AWB 33 Label class • This is simplest component in awt. The label contains string which is displayed as a text only & never perform any action. • Constructors: 1.Label(): Creates empty label. • 2.Label(String str): creates a new label with specified string of text. • Label(String str, int alignment): Creates a label with specified string & specified alignment. AWB 34 checkbox • Checkbox is a control that is used to turn an option ON or OFF. It consist of small box that can contain either check mark or not. Label is associated with checkbox. We can change the state of checkbox by clicking on it. • Constructors: 1.Checkbox() 2.Checkbox(String str) 3.Checkbox(String str, boolean true/false) 4.Checkbox(String str, boolean true/false,CheckboxGroup cbg) AWB 35 Checkbox names=new Checkbox(“ABC”,null,false); Above line will create a checkbox with ABC as labe, ‘null’ as a placeholder for a group argument & ‘false’ to indicate that it is not selected. AWB 36 Radio buttons • Radio buttons are also called as checkbox groups, are special kind of checkboxes, where within a particular group, only one box can be selected at a time. • CheckboxGroup fruits=new CheckboxGroup(); Above line creates a checkbox group, named fruits. Once you create checkbox group, add individual checkboxes to that group. add(new Checkbox(“mango”,fruits,false)); add(new Checkbox(“orange”,fruits,false)); AWB 37 List boxes • List class provides a multiple choice, scrolling list of values that may be selected alone or together. A list can be created to show any number of choices in visible window. • Constructors: 1. List(): Only one item can be selected at a time. 2.List(int no_of_rows): In this you can specify number of rows in the list that you want to be visible. 3.List(int no_of_rows, boolean multi_select): If boolean value is set to true, it means user can select more than one item, if false only one item can be selected. AWB 38 Choice boxes • Choice class is like lists, but it allows you to conserve space since it provides a pop-up menu of text string choices. The current choice is displayed on top. • Creation: Choice c=new Chioce(); • After creation you can add entries. c.add(“red”); Currently selected item can be changed by using select() method. c.select(“red”); or c.select(0); AWB 39 Textfield & textarea • These two are different java classes for entering text data. TextField class handles single line of text. TextArea is used for handeling multiple lines of text. • Constructors: 1.TextField():constructs a new testfield. 2.TextField(int columns): constructs empty textfield with no. of columns. 3. TextField(String text): construct new textfield with specified string. 4. TextField(String text, int columns): create new textfield with specified string & no. of columns. AWB 40 • TextArea constructors 1. TextArea(): constructs a empty textarea. 2. TextArea(int column, int rows): construct textarea with specified number of rows & column. 3. TextArea(String text): constructs a textarea with string. 4. TextArea(String text, int rows, int column, int scrollbar) : constructs textarea with string,rows,column,scrollbar. AWB 41 frame • If you are not creating an applet, then most likely creating a Frame. • Constructors: 1. Frame() 2.Frame(String title) First constructor creates frame without any title while second one creates a frame with specified title. Methods: 1. void setSize(int width,int height) 2. void setVisible(boolean flag) AWB 42 Exception handeling • Exceptions in real life are rare & usually used to denote something unusual. • Exceptions can arise due to number of situations. • There are predefined classes for all exception types. • Whenever exception occurs in a method, runtime environment identifies type of exception & throws object of it. AWB 43 Exception types • Exceptions are broadly classified into two categories: checked & unchecked. • Checked exceptions are those for which compiler checks to see whether they have been handled. • Unchecked or runtime exceptions are not checked by compiler. Checked Exceptions Unchecked Exceptions ClassNotFound Exception ArithmeticException NoSuchFieldException ArrayIndexOutOfBoundsExceptions NoSuchMethodException NullPointerException InterruptedException ClassCastException IOException BufferOverflowException IllegalAccessException AWBBufferUnderflowException 44 Exception handeling techniques • Java provides five keywords for exception handeling: try, catch,throw,throws & finally. • try…catch: It can be placed within any method that can throw exception. • All the statements to be tried for exceptions are put in a try block & immediately following ‘try’ is ‘catch’ block. • If exception occurs in any statement of ‘try’ block control immediately passes to corresponding ‘catch’ block. AWB 45 throw • ‘throw’ keyword is used to explicitly throw an exception. • Whether implicit or explicit objects of exceptions need to be created before they are thrown. • Execution of the program is suspended & runtime environment looks for the appropriate catch to handle exception. • ‘throw’ is more useful when we want to throw a user-defined exception. • Syntax: throw new NullPointerException(); AWB 46 throws • throws is added to the method signature to let the caller know about what exceptions the called method can throw. • It is the responsibility of the caller to handle the exception or it can also pass the exception. • A method can throw more than one exception, the exception list is separated by commas. • Syntax: public void divide(int a, int b) throws ArithmeticException,IOException. AWB 47 finally • Finally block is always executed in try-catch-finally statements irrespective of whether an exception is thrown from within the try/catch block or not. • Statements following the exception in a try block are not executed. • Some statements are mandatory to execute like the statements related to the release of resources. • All these statements can be put in a finally block. AWB 48