Friday, 20 September 2013

Differences between SQL and MySQL

Differences between SQL and MySQL

SQL

MySQL

1.     Dual table required for calculation
Eg. Select 4+3 from Dual;

No dual table required for calculation
Select 4+3;
2.     Datatype is Varchar2

Dataype is Varchar for variable strings
3.     Number for real numbers
Number(s,p)

Decimal (s,p)
4.     Update is only simple without order by clause

Update has the order by clause
5.     For concatenation :
Select fname || lname from emp;

Only concat function,
No || or +
6.     Insert only for 1 row at a time
Insert multiple rows
Insert into emp values(1,’a’),(2,’b),(3,’c’);

7.     Date format is
dd-mm-yyyy

Date format is
Yyyy-mm-dd,  yy-mm-dd, yyyy/mm/dd, yyyymmdd


These are some code how we work with swing control without using any IDE i.e. using Notepad and fundamental of Programming.

                                  
                                                                   Swing

Swing:-
              Swing is a Java Foundation Classes [JFC] liberary and an extension of the Abstract Window Toolkit [AWT],new components, expanded components features, excellent event handling with drag and drop support.

Swing Components:-
                                  Swing is a package built on top of the AWT that provides a great number of pre built classes [over 250 classes and 40 UI components].

Swing Components
Features
JApplet
An extended version of java.applet.Applet that adds support for root panes and other panes
JButton
A command button
JCheckBox
A checkbox that can be user selected or deselected and displays its state visually on the GUI
JCheckMenuItem
A menu item that can be select or deselect and display its state visually on the  GUI
JComboBox
A combo box, which is a combination of a text field and drop down list of selectable items
JDialog
The base class for creating a dialog window
JFrame
An extended version of java.awt.Frame
That adds support for root panes and other panes
JLable
A display area that can hold a short text message, an image or both normally placed adjacent to a textbox as its prompt
JList
A component that allows the user to select one or more objects from a list
JMenu
A pop up menu containing JMenuItem that is displayed when the user selects it in the JMenuBar component
JMenuBar
An implementation of a menu bar
JMenuItem
An implementation of a menu item
JOptionPane
Make it easy to pop up a standard dialog box
JPanel
A generic Lightweight container
JPasswordFeild
Allow editing of a single line of text where the view does not show the original characters
JPopupMenu
A pop up menu
JPopupMenuSeparator
A pop-up menu-specific separator
JProgressBar
A component that displays an integer value within an interval
JRadioButton
A radio button that can be selected or deselected, displaying its state visually
JRadioButtonMenuItem
A radio button menu item
JRootPane
The fundamental component in the container hierarchy
JScrollBar
An implementation of a scrollbar
JScrollPane
A container that manages a viewport, optional vertical and horizontal scrollbars and optional row and column heading viewports
JSlider
A component that lets the user select a value by sliding a knob within an interval
JTabbedPane
Lets the user switch between a group of components by clicking tabs
JTable
Presents data in a two-dimensional table format
JTextArea
A multi line area that accepts and displays user input as plain text
JTextFeild
A single line area that accepts and displays user input as plain text
JtextPane
A text component that can be marked up with attributes that are representes graphically
JToolBar
A toolbar, used for displaying commonly used controls as icon in a the GUI of a commercial application
JTree
Display a set of hierarchical data as an tree outline


Comparison between swing and AWT:-
                                                                     The biggest difference between the AWT and swing components is that swing components are implemented totally in java. Swing components have more functionality than AWT components.



Working with swings

JFrame:
              A swing frame is a container that functions as the main window for applications that use swing components. A swing frame has a title, a border and buttons for iconofying, maximizing and closing frame.
                                 The JFrame class is subdivided into several different panes. The main pane is the content pane which represents the full area of a frame into which components can be added.

Methods of JFrame:
Methods
Description
Void setContentPane(Container)
Container getContentPane()
Set or get the frame’s content pane. The content pane contains the frame’s visible GUI components. The content pane is opaque.
JRootPane creatRootPane()
Void setRootPane(JRootPane)
JRootPane getRootPane()
Create, set or get the frame’s root pane. The root panel manages the interior of the frame including the content pane, the glass pane and so on.
Void setGlassPane(Component)
Component getGlassPane()
Set or get the frame’s glass pane.Use the frame’s layered pane to put components on top or behind other components
Void setLayeredPane(JLayeredPane)
JLayeredPane getLayeredpane()
Set or get the frame’s layered pane. Use the frame’s layered pane to put components on top of or behind other components.

Example1:
Import javax.swing.*;
Import java.awt.event.*;
Import java.awt.*;

Public class HelloworldFrame extends JFrame
{
Public static void main(String[]args)
{
JFrame frm =new JFrame(“welcome”);
Container container =frm.getContentPane();
Container.add(new JLable(“Hello World”, JLable.CENTER));
Frm.setSize(200,200);
Frm.setVisible(true);

WindowListener listener = new WindowAdaper()
{
             Public void windowClosing(WindowEvent winEvt)
{                  
                        System.exit(0);
         }
};
Frm.addWindowListener(listener);
         }
}

JPanel:-
               A JPanel is a Swing container [a component extension of JComponent] that is used for grouping components within one area of an applet or a frame. A panel can also be used to group other panels.

Example2:

Import javax.swing.*;
Import java.awt.event.*;
Import java.awt.*;

Public class MasterForm extends JFrame
{
Public MasterForm()
{
super(“Address Book”);

JButton btnAdd =new JButton(“Add”);
JButton btnEdit =new JButton(“Edit”);
JButton btnDelete =new JButton(“Delete”);
JButton btnView=new JButton(“View”);
JPanel pnlMenu =new JPanel();

pnlMenu.add(btnAdd);
pnlMenu.add(btnEdit);
pnlMenu.add(btnDelete);
pnlMenu.add(btnView);

btnAdd.setMnemonic(‘a’);
btnEdit.setMnemonic(‘e’);
btnDelete.setMnemonic(‘d’);
btnView.setMnemonic(‘v’);

btnAdd.setToolTipText(“To add new contents”);
btnEdit.setToolTipText(“To edit existing contents”);
btnDelete.setToolTipText(“To delete existing contents”);
btnView.setToolTipText(“To view existing contents”);

setContentPane(pnlMenu);
}
public static void main(String[]args)
{
MasterForm frmMaster =new MasterForm();

frmMaster.setSize(300,200);
frmMaster.setVisible(true);

WindowListener listener = new WindowAdaper()
{
             Public void windowClosing(WindowEvent winEvt)
{                  
                        System.exit(0);
         }
};
Frm.addWindowListener(listener);
         }
}

Swings Basic Containers:
                                           These components are the content pane, layered pane, glass pane and an optional menu bar.
In addition to this, the root pane is a virtual container that contains all four of them.

Root Pane:
                   Swing containers such as JApplet, JFrame, jWindow delegates their duties to the root pane represented by the class JRootPane. Root pane cannot have any children class. Thus, GUI Components cannot add directly.

JButton Method:
Methods
Description
Boolean isDefaultButton()
Sets the button as the default button in the GUI.
void updateUI()
Used to update the look and feel of the application’s GUI
                        
JLabel Methods:
Methods
Description
void setHorizontalAlignment(int)
void setVerticalAlignment(int)
int getHorizontalAlignmen()
int getVerticalAlignmen()


The set or get specifies where in the lable its contents should be placed. The SwingContantsinterface define five possible values for horizontal alignment: LEFT[default for text only labels], CENTER[default for image only labels],
RIGHT, LEADING and TRAILING.For
Vertical alignment: TOP, CENTER[default], BOTTOM

Void setIconTextGap(int)
Int getIconTextGap()
Sets or gets the number of pixels between the labels text and its images
Icon getIcon()
Returns an icon associated with the image
Void setIcon(Icon)
Sets an icon to an lable
String getText()
Return the text string that the lable display
Void setText(String)
Defines a single line of text the lable will display
Void setDisplayedKeyAcceletor(char)
Specifies a character that indicates the shortcut key
Char getDisplayedKeyAccelerator()
Returns the char that indicates the shortcut key

Example3:

Import javax.swing.*;
Import java.awt.event.*;
Import java.awt.*;

Public class Login extends JPanel
{
Public Login()
{
Icon imgIcon =new ImageIcon(“Images/security.jpg”);
JLabel lbllnValid =new JLable(“The Login Username or password is not valid.”,SwingConstant.RIGHT);

add(lblReEnter);
}
Public static void main(String args[])
{
JFrame frm =new JFrame(“Invalid Login”);
Login lblLogin =new Login();
Frm.getContentPane().add(“Center”,lblLogin);
Frm.setSize(400,200);
Frm.setVisible(true);


WindowListener listener = new WindowAdaper()
{
             Public void windowClosing(WindowEvent winEvt)
{                  
                        System.exit(0);
   }};
               }
}


Text Field:
                   A text field is a component that lets a user enter a small amount of text, normally used with GUI based data entry screen in commercial application or Applets.

JTextField Method:
Methods
Description
Void setEditable(Boolean)
Boolean getEditable()
Sets or gets whether the user can edit the text in the text field
Void setColumns(int)
Int getColumns()
Sets or gets the number of columns displayed by the text field
Int getColumnWidth()
Get the width of the text field’s columns
Void setHorizontalAlignment(int)
Int getHorizontalAlignment()
Set or get how the text is aligned horizontally within its area. One can use JTextField.LEFT, JTextField.CENTER and JTextFeild. RIGHT for aligning text in the text field.
Void setEchoChar(char)
Char getEchoChar ()
(in JPasswordField)
Set or get the echo character – the character displayed instead of the actual characters typed by the user

Example4:

Import javax.swing.*;
Import java.awt.event.*;

Public class Login extends JPanel
{
JLable lblUserName;
JLable lblUserPassword;
JTextField txtUserName;
JpasswordField txtPassword;

Public Login()
{
lblUserName =new JLable(“Username:”);
txtUserName =new JTextField(10);
lblUserPassword =new JLable(“UserPassword:”);
txtUserPassword =new JPasswordField(10);
txtPassword.setEchoChar(‘*’);

txtUserName.setToolTipText(“Enter Username”);
txtPassword.setToolTipText(“Enter Password”);

add(lblUserName);
add(txtUserName);
add(lblUserPassword);
add(txtlUserPassword);
}
Public static void main(String[]args)
{
Login frmLogin =new Login();
JFrame frm =new JFrame(“Login Form”);
Frm.setContentPane(frmLogin);
Frm.setSize(200,150);
Frm.setVisible(true);
WindowListener listener = new WindowAdaper()
{
             Public void windowClosing(WindowEvent winEvt)
{                  
                        System.exit(0);
         }
};
Frm.addWindowListener(listener);
         }
}

Text Areas:
                     A text area is a text control used in a GUI that lets a user enter multiple lines of text.

JTextArea Methods:

Methods
Description
Append(String)
Appends the given string to the end of the document
Void getColumns(int)
Int getRows(int)
Returns the number of columns and rows in the text area.
Insert(String,int)
Inserts a specified text at the specified position in the text area
Void setRows(int)
Sets the number of rows for the text area
Void setFont(Font)
Sets a specific font for the text


Example5:

Import javax.swing.*;
Import java.awt.event.*;

Public class AddressDetails extends JPanel
{
JLable lblFirstName, lblLastName, lblAddress;
JTextFeild txtFirestName, txtLastName;
JTextArea txtareaAddress;

Public AddressDetails()
{
setLayout(null);

lblFirstName =new JLable(“First Name:”);
lblLastName =new JLable(“Last Name:”);
lblAddress =new JLable(“Address:”);
txtFirstName =new JTextFeild(15);
txtLastName =new JTextFeild(15);
txtareaAddress =new JTextArea(10,10);

lblFirstName.setBounds(10,20,120,25);
txtFirstName.setBounds(150,20,210,25);
lblLastName.setBounds(10,60,180,25);
txtLastName.setBounds(150,60,210,25);
lblAddress.setBounds(10,100,250,25);
txtareaAddress.setBounds(150,100,280,100);

add(lblFirstName);
add(txtFirstName);
add(lblLastName);
add(txtLastName);
add(lblAddress);
add(txtareaAddress);
}
Public static void main(String[]args)
{
AddressDetails frmAddress =new AddressDetails();
JFrame frm =new JFrame(“Address Details”);
frm.setContentPane(frmAddress);
frm.setSize(500,300);
frm.setVisible(true);

WindowListener listener = new WindowAdaper()
{
             Public void windowClosing(WindowEvent winEvt)
{                  
                        System.exit(0);
         }
};
Frm.addWindowListener(listener);
         }
}

JCheckBox Methods:

Methods
Description
String getLabel()
Void setLabel(String)
Sets or gets a label for a check box
Boolean getState()
Void setState(Boolean)
Sets or gets the status of the check box

Example6:

Import javax.swing.*;
Import java.awt.event.*;

Public class Hobbies extends JPanel
{
JCheckBox chkMusic, chkDancing, chkReading, chkStamp, chkCoins, chkDriving;

Public Hobbies()
{
        chkMusic =new JCheckBox(“Music”,true);
        chkDancing =new JCheckBox(“Dancing”,false);
        chkReading =new JCheckBox(“Reading”,false);
        chkDriving =new JCheckBox(“Driving”, false);
        chkStamp =new JCheckBox(“Collecting Stamp”, false);
        chkCoins =new JCheckBox(“Collecting Old Coins”, false);

add(chkMusic);
add(chkDancing);
add(chkReading);
add(chkDriving);
add(chkStamp);
add(chkCoins);
}
Public static void main(String[] args)
{
Hobbies frmHobbies =new Hobbies();
JFrame frm =new JFrame(“Hobbies”);
Frm.setContentPane(frmHobbies);

frm.setSize(300,150);
frm.setVisible(true);

WindowListener listener = new WindowAdaper()
{
             Public void windowClosing(WindowEvent winEvt)
{                  
                        System.exit(0);
         }
};
Frm.addWindowListener(listener);
         }
}


I hope after reading this article now you pupil understood how Net Beans IDE or Eclipse IDE made our programming life simple.

So enjoy GUI programming with NET BEANS IDE.

Java Swings - Some Important Typical Questions based on Java Swing controls.

1. What is JFC? 
             JFC stands for Java Foundation Classes. The Java Foundation Classes (JFC) are a set of Java class libraries provided as part of Java 2 Platform, Standard Edition (J2SE) to support building graphics user interface (GUI) and graphics functionality for client applications that will run on popular platforms such as Microsoft Windows, Linux, and Mac OSX. 
      
2 .What is AWT? 
            AWT stands for Abstract Window Toolkit. AWT enables programmers to develop Java applications with GUI components, such as windows, and buttons. The Java Virtual Machine (JVM) is responsible for translating the AWT calls into the appropriate calls to the host operating system. 
      
3 .What are the differences between Swing and AWT? 
           AWT is heavy-weight components, but Swing is light-weight components. AWT is OS dependent because it uses native components, But Swing components are OS independent. We can change the look and feel in Swing which is not possible in AWT. Swing takes less memory compared to AWT. For drawing AWT uses screen rendering where Swing uses double buffering. 
      
4. What are heavyweight components ? 
          A heavyweight component is one that is associated with its own native screen resource (commonly known as a peer). 
      
5 .What is lightweight component? 
               A lightweight component is one that "borrows" the screen resource of an ancestor (which means it has no native resource of its own -- so it's "lighter"). 
      
6 .What is double buffering ? 
              Double buffering is the process of use of two buffers rather than one to temporarily hold data being moved to and from an I/O device. Double buffering increases data transfer speed because one buffer can be filled while the other is being emptied. 
      
7.What is an event? 
             Changing the state of an object is called an event. 
      
8.What is an event handler ? 
             An event handler is a part of a computer program created to tell the program how to act in response to a specific event. 
      
9.What is a layout manager? 
             A layout manager is an object that is used to organize components in a container.   
      
10.What is clipping? 
             Clipping is the process of confining paint operations to a limited area or shape.   
      
11.Which containers use a border Layout as their default layout? 
             The window, Frame and Dialog classes use a border layout as their default layout.   
      
12, What is the preferred size of a component? 
            The preferred size of a component is the minimum component size that will allow the component to display normally. 
      
13 .What method is used to specify a container's layout? 
            The setLayout() method is used to specify a container's layout.   
      
14.Which containers use a FlowLayout as their default layout? 
            The Panel and Applet classes use the FlowLayout as their default layout. 
      
15.Which method of the Component class is used to set the position and size of a component? 
           set Bounds 
16 What is the difference between invokeAndWait() and invokeLater()?   
  A invokeAndWait is synchronous. It blocks until Runnable task is complete. InvokeLater is asynchronous. It posts an action event to the event queue and returns immediately. It will not wait for the task to complete   
      
17  Why should any swing call back implementation execute quickly?   
  A Callbacks are invoked by the event dispatch thread. Event dispatch thread blocks processing of other events as long as call back method executes.   
      
18 What is an applet? 
  A Applet is a java program that runs inside a web browser. 
      
19 What is the difference between applications and applets? 
  A Application must be run explicitly within Java Virtual Machine whereas applet loads and runs itself automatically in a java-enabled browser. Application starts execution with its main method whereas applet starts execution with its init method. Application can run with or without graphical user interface whereas applet must run within a graphical user interface. In order to run an applet we need a java enabled web browser or an appletviewer. 
      
20 Which method is used by the applet to recognize the height and width? 
  A getParameters(). 
      
21 When we should go for codebase in applet? 
  A If the applet class is not in the same directory, codebase is used. 
      
22  What is the lifecycle of an applet? 
  A init( ) method - called when an applet is first loaded 
start( ) method - called each time an applet is started 
paint( ) method - called when the applet is minimized or maximized 
stop( ) method - called when the browser moves off the applet's page 
destroy( ) method - called when the browser is finished with the applet 
      
23 Which method is used for setting security in applets? 
  A setSecurityManager 
      
24  What is an event and what are the models available for event handling? 
  A Changing the state of an object is called an event. An event is an event object that describes a state of change. In other words, event occurs when an action is generated, like pressing a key on keyboard, clicking mouse, etc. There different types of models for handling events are event-inheritance model and event-delegation model 
      
25 What are the advantages of the event-delegation model over the event-inheritance model? 
  A Event-delegation model has two advantages over event-inheritance model. a)Event delegation model enables event handling by objects other than the ones that generate the events. This allows a clean separation between a component's design and its use. b)It performs much better in applications where many events are generated. This performance improvement is due to event-delegation model does not have to be repeatedly process unhandled events as is the case of the event-inheritance. 
      
26 What is source and listener ? 
  A A source is an object that generates an event. This occurs when the internal state of that object changes in some way. A listener is an object that is notified when an event occurs. It has two major requirements. First, it must have been registered with a source to receive notifications about specific event. Second, it must implement necessary methods to receive and process these notifications.   
      
27 What is controls and what are different types of controls in AWT? 
  A Controls are components that allow a user to interact with your application.   AWT supports the following types of controls: Labels, Push Buttons, Check Boxes, Choice Lists, Lists, Scrollbars, Text Components. These controls are subclasses of Component. 
      
28 What is the difference between choice and list? 
  A A Choice is displayed in a compact form that requires you to pull it down to see the list of available choices and only one item may be selected from a choice. A List may be displayed in such a way that several list items are visible and it supports the selection of one or more list items. 
      
29 What is the difference between scrollbar and scrollpane? 
  A A Scrollbar is a Component, but not a Container whereas Scrollpane is a Container and handles its own events and perform its own scrolling. 
      
30 What is a layout manager and what are different types of layout managers available? 
  A A layout manager is an object that is used to organize components in a container. The different layouts are available are FlowLayout, BorderLayout, CardLayout, GridLayout , GridBagLayout, Boxlayout and SpringLayout.