Posts

Showing posts from 2011

Exception Handling

Exception,  that means exceptional errors. Actually  exceptions  are used for handling errors in programs that occurs during the program execution. During the program execution if any error occurs and you want to print your own message or the system message about the error then you write the part of the program which generate the error in the  try{}  block and catch the errors using  catch()  block. Exception turns the direction of normal flow of the program control and send to the related  catch()  block. Error that occurs during the program execution generate a specific object which has the information about the errors occurred in the program. import  java.io.*; public class  exceptionHandle{    public static  void  main(String[] args)   throws  Exception{      try {         int  a,b;        Scanne...

Loops

Looping constructs are used when we need to repeat a task a number of times or till some condition is me t. A looping construct should have - an initial condition – which starts the loop - an increment – which advances the loop - a termination condition – which helps come out of the loop The loops used in JAVA language are : 1. do - while 2. while             3. for  

Conditional Statements

There are statements which check for a condition and accordingly the execution flow can be changed. The most common conditional construct is of the format IF (condition)   THEN ----------------------   ELSE -------------------- Here, if the condition* evaluates to be “true”, THEN part is executed (& ELSE part is skipped) & if it evaluates to “false”, ELSE part is executed ( & IF part is skipped). * NOTE - the condition should be a valid expression that can be evaluated to either true or false.

Disadvantages of OOP

OOP is a high level concepts so takes more time to execute as many routines run behind at the  time of execution. Offers less number of functions as compared to low level programming which interacts directly with  hardware. Increased burden on part of OOP developer.  

ADVANTAGES OF OOP

Reduced Maintenance Real-World Modeling Improved Reliability and Flexibility High Code Reusability

OOP Concept

ABSTRACTION:- Abstraction refers to the act of representing essential features without including the background details. • Data abstraction is used as a tool to increase the modularity of a program • It is used to build walls between a program and its data structures DYNAMIC BINDING:- Dynamic Binding means that the code associated with the given function call is not know  until the time of call at runtime. Binding refers to the act of associating an object or a class  with its member .

Switch Statement

Switch Statement JAVA has a built-in multiple-branch selection statement called switch, which successively tests the value of an expression against a list of integer or character constants. When a match is found, the statements associated with that constant are executed.  The general form of the switch statement is: switch (expression) { case constant1 :statement sequence break; case constant2 :statement sequence break; case constant3 :statement sequence break; . . . default statement sequence } SAMPLE PROGRAM:- public class  SwitchExample {    public static  void  main ( String []  args )  throws  Exception {      int  x, y; x = 2 ; y = 4 ;       System.out.println ( "1. Add" ) ;        System.out.println ( "2. Subtract" ) ;        System.out.println ( "3....

ARRAY

ARRAY:- There is one variable capability wherein we can use one variable to store a list of data and manipulate them more efficiently. This type of variable is called an array. OR An array stores multiple data items of the same data type, in a contiguous block of memory, divided in to a number of slots. To declare an array in JAVA int[] ages; int ages[]; ages = new int[100]; OR int ages[] = new int[100]; SAMPLE PROGRAM:- public class Test { public static void main(String[] arg) { String day[] = new String[7]; day[0] = "Mon"; day[1] = "Tue"; day[2] = "Wed"; day[3] = "Thu"; day[4] = "Fri"; day[5] = "Sat"; day[6] = "Sun"; for (int i=0 ; i<7 ; i++) System.out.println(day[i]); } }

JAVA OOPs Concepts

Polymorphism:- Polymorphism allows one interface to be used for set of actions i.e one name may refer to different functionality Polymorphism allows a object to accept different requests of a client Types of Polymorphism 1. compile-time polymorphism 2. runtime polymorphism In compile-time polymorphism, method to be invoked is determined at the compile-time. Compile time polymorphism is supported through the method overloading. Method overloading means having multiple method with the same name but with different signature(number, type, and order of parameters). EXAMPLE OF COMPILE-TIME POLYMORPHISM:- class A { public void fun1(int x) { system.out.println("int"); } public void fun1(int x, int y) { system.out.println("int and int"); } } public class B { public static void main(String[] arg) { A obj = new A(); obj.fun1(2); obj.fun1(2,3); } } In runtime polymorphism, the method to be invoked is determined at runtime. The example of runtime...

JAVA OOPs Concepts

OOP:- Object Oriented Programming is the technique to create programs based on real world Class:- A class defines the Properties and behavior ( Variables and methods) that is shared by all its objects. It is a blue print for the creation of objects Object:- Object is the basic entity of object oriented programming language. Object is a n instance of class. It takes the properties(Variables) and uses the  behavior  (Methods) defined in the class. Encapsulation, Inheritance and Polymorphism are main pillars of OOPs. Encapsulation:- Encapsulation is the process of binding together the methods and data variables as a single entity. This keeps both the data and functionality code safe from outside world. It hides the data within the class as makes it available only through the methods. Java provides different accessibility scopes (Public, Protected, Private, default) to hide the data from outside. EXAMPLE:- class check { private int amo...

GUI Introduction

Image
11.1 Introduction A graphical user interface (GUI) presents a user-friendly mechanism for interacting with an application. A GUI (pronounced “GOO-ee”) gives an application a distinctive “look” and “feel.” Providing different applications with consistent, intuitive user interface components allows users to be somewhat familiar with an application, so that they can learn it more quickly and use it more productively. As an example of a GUI, Fig. 11.1 contains an Internet Explorer web-browser window with some of its GUI components labeled. At the top is a title bar that contains the window’s title. Below that is a menu bar containing menus (File, Edit, View, etc.). Below the menu bar is a set of buttons that the user can click to perform tasks in Internet Explorer. Below the buttons is a combo box; the user can type into it the name of a website to visit or can click the down arrow at the right side of the box to select from a list of sites previously visited. The menus, ...

Example of Breadth Search

Image
Here is a tree the root is 1. and the goals are 9,10,11,12 Queue = Q ----------------------------------------------------------------------- 1 2 ----------------------------------------------------------------------- At the first movement State = 1 ( is state is our goal  :::::::: Not ) Sucessor of state is added in Queue form Back   ( Q = 2 3 4 ) then state = queue[0] = 2 remove first item form queue. ( Q = 3 4 ) State = 2 ( is state is our goal  :::::::: Not ) Sucessor of state is added in Queue form    ( Q = 3 4 5 6 ) then state = queue[0] = 3 remove first item form queue. ( Q = 4 5 6 ) State = 3 ( is state is our goal  :::::::: Not ) Sucessor of state is added in Queue form Front   ( Q = 4 5 6 ) then state = queue[0] = 4 remove first item form queue. ( Q = 5 6 ) State = 4 ( is state is our goal  :::::::: Not ) Sucessor of state is added in Queue form Front   ( Q = 5 6 7 8 ) then state = queue[0] = 5 remove first item form ...

Java Localization

Intelligent Programmer------> To translate a text in to a particular language is know as  Localization.  It is a process by which we can change a text to a different language and also we can add some   locale-specific components. Swing  supports localization in the way that when we localize an application to a particular language and run it in that specific locale then Swing pulls up the localized strings from the  resource bundle.  After this,  the  component  gets resized  by the  layout manager.  The previous example demonstrates how to localize an application. Undo Framework API To perform  undo  and  redo,  the developers can use   Swing's undo framework.  There are number of actions related to undo and redo which are supported by Swing. Moreover, it can easily be used with any other application such as if you want to undo the  add and remove elements from a table,  you can easil...

Java Internationalization

Intelligent Programmer-----> Swing in Java also supports the feature of  Internationalization.  The developers can build applications by which the users can interact worldwide in  different languages. They can also create applications that can accept input in languages having different characters such as  French, Spanish, Japanese,  etc.   An  automatic support  is provided by the Swing's layout managers  required by the UI.  That is Swing's layout manager let the UI to appear from  right to left in a locale.  Hence to let the UI work for left to right and right to left and also to take care of the size of components that change on localization, you need to code the UI only once. Lets see how to  internationalize  the program given below. import java.util.*; public class InternationalizationDemo {     public static void main(String[] args) {         ...

Java Data Transfer

Image
Intelligent Programmer-----> Swing supports data transfer through  drag and drop, copy-paste, cut-paste  etc.  Data transfer  works between  Swing components within an application and between Java and native applications. The ability of data transfer is beneficial to programs  between Java applications, between components etc. There are two ways to transfer data. These are: 1.  The diagram below displays the  Drag and drop (DnD)  functionality of Swing.  2.   The diagram below displays the  cut/copy and paste  functionality of Swing.  That is the clipboard transfer  via cut/copy and paste. The path of the data is shown by the arrows. To be more precise, first of all the  bundling of data  takes place into a  package  known as Transferable  to begin  Data Transfer.  Then the data gets extracted by an object i.e. TransferHandler   from the Transferable  which i...

Java 2D API

Image
Intelligent Programmer-----> Programming has become more interactive with  Java 2D API.  You can add  images, figures, animation  to your  GUI  and even pass visual information with the help of Java 2D API. You can easily use 2D within Swing components such as  drop shadows  since Swing is built on 2D package. Pluggable Look and Feel  The Java Swing supports the  plugging between the look and feel  features. The look and feel that means the dramatically changing in the component like  JFrame, JWindow, JDialog  etc. for viewing it into the several types of window. You can create your own look and feel using  Synth package.  There are many of existing look and feels which are available to Swing programs provided by  GTK+ look and feel.  Moreover, the look and feel of the platform  can be specified by the program while running and also to use Java look and feel can be specified by it. The  ...

Java Swing Components

Intelligent Programmer--->Lets now see what's Swing? Well, Swing is important to develop Java programs with a  graphical user interface (GUI).  There are many components which are used for the building of GUI in Swing. The  Swing Toolkit consists of many components for the building of GUI. These components are also helpful in providing  interactivity to Java applications.  Following are components which are included in Swing toolkit: list controls buttons labels tree controls table controls All  AWT  flexible components can be handled by the  Java Swing.  Swing toolkit contains far more components than the simple component toolkit. It is unique to any other toolkit in the way that it supports   integrated internationalization,   a highly customizable text package, rich undo support  etc. Not only this you can also  create your own look and feel using Swing  other than the ones that are supported by it. The cu...

UNINFORMED SEARCH

UNINFORMED SEARCH: There are two uniformed search:- 1. Breath First Search 2. Depth First Search SEARCH TREE:- - Root Node - Leaf Node - Ancestor / Descendant - Branching factor - Complete Path / Partial Path. EVALUATING SEARCH STRATEGIES:- 1. Completeness:  is the strategy guaranteed to find a solution if one exists. 2. Optimality:  if the solution is found, is the solution guaranteed to have the minimum cost. 3. Time Complexity:  Time taken (number of node expanded worst or average case) to find a solution. 4. Space Complexity:  Space used by the algorithm measured in term of the maximum size of list. BREADTH SEARCH:- Function breadth(){ queue = []; state = root - node; while(true) { if is_goal(state)            then return success else add_to_back_of_queue(Sucessor(state)); if queue = []            then repeat failure; state = queue[0] remove_first_...