Sunday, November 29, 2009

Has Anyone Had Hair Transplant In Delhi,

try-catch block

block try-catch is a Java control structure that allows us to handle errors that may be generated by the execution of a block of code, which guarantees that our program does not become unstable and that can end unexpectedly. For the errors that are generated at run time in our program are called exceptions.

The try-catch block is as follows:


Within the block try {... } Attempting to perform a series of actions, while in catch ( exc) {... } are caught any errors that may be generated to execute the series of actions. However, you can add to the try-catch block another code segment:









If segment try {...} no errors occur then the complete execution of this segment is passed to the segment finally {...}, otherwise the segment will run catch {...} block followed finally {...}.

class Throwable ( java.lang package ) is the superclass for all errors and exceptions in Java. Only objects that are instances of this class (or one of its subclasses) are thrown by the Java virtual machine. Exception class (also java.lang package ) and its subclasses are a form of class Throwable , this class shows how applications are responsible for handling errors.

Exception class has the following constructors:

Exception ()
Constructs a new exception with a null message.
Exception (String message)
Constructs a new exception with the specified message to display.
Exception (Throwable cause)
Constructs a new exception with a specific cause. Generally class Throwable contains the message of the cause of the error.
Exception (String message, Throwable cause)
Constructs a new exception with detail message specified and the cause.

are many errors that can be generated by running our applications, either by programming errors or by user data entry inersperadas, eg division by zero a number or address to convert a letter into a number. Some, among many other exceptions that are generated are:

ArithmeticException
Occurs when an exceptional arithmetic condition has occurred. Por ejemplo, cuando se trata de dividir un número por cero se lanza una instancia de esta clase.
ClassNotFoundException
Es producida cuando una aplicación trata de hacer referencia a una clase por su nombre y dicha clase no existe.
DataFormatException
Indica que se ha producido un error en el formato de los datos.
InterruptedException
This exception may be generated when a thread is sleeping, waiting or stopped unexpectedly and tries to stop another thread.
IOException
can generate an error in data input or output, for example, file operations and data flows.
NumberFormatException
Launched to indicate that the application attempted to convert a string to a numeric types, but the chain does not have the proper format.
ParseException
Indicates that an error has been reached unexpectedly while trying raalizar an analysis to a sequence of tokens.
PrinterException
Used to indicate that it has generated an error in the printing system.

In Java there are two useful keywords related error handling:

throw
Launches new exception.
throws
Indicates that a method can throw an exception.

Example: A program that performs the division of two numbers.



Example: A program that determines whether a number is integer or double.

Today

Saturday, November 28, 2009

Pichees Of Scooter Wiells



high-volume applications information and also need to give these data persistence. To achieve this, many systems applications interact with database managers to accommodate far-reaching information and data. In this post I will discuss how we can make a Java application to connect to a database created in MySQL.

To achieve this we need to have installed the MySQL driver (which can be obtained for free from their official website ) and driver that allows us to make such connection (classes that manipulate database records data).

Once downloaded
have to install the database manager. Inside the zip file of MySQL driver will have to find the jar file to place within our portfolio of Java classes ( .../java/jdk1.6.0_xx/jre/lib/ext ). In my case the downloaded file is mysql-connector-java-5.1.10.zip and contains a jar file called mysql-connector-java-5.1.10.bin.jar

With
manager installed and the MySQL driver in place we can create a test database and add some records. The following example is the structure of a database to store contacts in a book:



However, in order to manipulate those records have to make use of the classes in package java.sql . Some of the classes within this package are:


Connection A connection with a particular database.

DatabaseMetaData contains information about the database. DriverManager

Basic services for the management of a set of JDBC drivers .
ResultSet

Table of data representing a result set of databases, which is usually generated by executing a statement that queries the database.
ResultSetMetaData
object that can be used to obtain information on the types and properties of the columns in a ResultSet object. Statement

object used for executing a SQL statement.


The following code shows the records from the contacts in our database Agenda:


Lines 9 and 10 contain the instruction code for connection to the database through the getConnection (). This method has the following forms:

static Connection getConnection (String url)
try to connect to the database of the given url. Static
Connection getConnection (String url, Properties info)
Try to connect to the database espeficicando the url given a set of properties.
static Connection getConnection (String url, String user, String pass)
try to connect to the database of the given url, using a username and password.

Note that line 10 is marked with blue. Be careful to replace the values \u200b\u200b "user" and "password" for the appropriate user data that can access the database in the handler.

Thursday, November 26, 2009

Anthropologie Clothing

MySQL Java Connection Reading data from the keyboard with Java (fourth form)

Along with the version of Java 5 came a new set of classes, including one that allows us to read data from the keyboard even easier than previously seen classes.

Scanner class of java.util package which gives us the ability to process data entered from the keyboard under primitive type they belong to these entries. This is achieved by treating the input data as tokens of an expression separated by a boundary that we have specified.

Let's see an example of the above ...

turns out that we need to write a Java program that allows capturing personal data of a company's payroll. We read data such as name, address, age and salary of an employee. We know the names that will introduce the program String class, like directions. While the employee's age must be an integer value and the wage is given in numbers with decimals. In short:

String name = "";
String address = "";
int age = 0;
double salary = 0.0;

Earlier we saw that the class BufferedReader capture data allowed keyboard through method readLine () , which returns a value type we String would subsequently be converted to numeric processing. However, the class Scanner contains specific methods for reading data much faster and safer, but above all, without the need for conversions ourselves. Following is a summary of these methods:

constructor Summary:

Scanner (File file)
Creates a new Scanner that produces values \u200b\u200bfrom a specified file.
Scanner (InputStream inputStream)
Creates a new Scanner that produces values \u200b\u200bfrom an input stream of data.
Scanner (String source)
Creates a new scanner from a particular string.

Summary of methods:

void close () Closes

Pattern Scanner delimiter () Returns
Scanner delimiter pattern
findInLine String (Pattern pattern)
Try searching a string in the scanner to ignore the patterns
boolean hasNext ()
Returns true if the value contains more tokens Scanner
boolean hasNext (String pattern )
Returns a true value if the Scanner contains the specified pattern
nextBoolean boolean ()
Scans the next token of the input to a Boolean value and returns that value.
nextByte byte ()
Scans the next token of the input as a byte.
double nextDouble ()
Scans the next token of the input as a double. Float
nextFloat ()
Scans the next token of the input as a float.
int nextInt ()
Scans the next token of the input as an int. String
nextLine () Returns
entire current line.
long nextLong ()
Scans the next token of the input as a long.
short nextShort ()
Scans the next token of the input as a short.

Then, with the Scanner class can perform data reads to solve our example.



Wednesday, November 4, 2009

Crossover Emulator For Mac Trade Pokemon

Reading data from the keyboard in Java (Third form) responds to events

In the previous post on reading data from the second form use a method that returns the text we put into a command prompt / terminal until you press the enter key , or which is equal to that System.in receive '\\ n' (line using the backslash caractetes). The data that we receive the added to a string that is returned upon completion with the reading method. One way to perform the above process is helping us with a read buffer. Buffer to be defined as the space in the memory of our computer that we can store a certain amount of information temporarily or until they are processed.

class from java.io BufferedReader is a class that allows us to read data in sequence, which gives us greater reliability in the reading done. By default, the buffer created BufferedReader is large enough to cover virtually any need, and also gives us the possibility to obtain the text from a file or other information flow.

To read data from our console have to wrap within BufferedReader data flow manipulate them in our case we will use the keyboard to the class to wrap InputStreamReader also java.io package , a bridge between the standard input buffer and Java, as InputStreamReader is a decoder bytes causes us these bytes in the corresponding character. So it is strongly recommended to use the buffer for reading data. However, suffice to specify where to get the InputStreamReader to convert bytes to characters.

Some methods of the class BufferedReader are void

close () - Close reading of data flow Void

mark (int anchor) - Mark the position in the data stream int

read () - Read a single character String

readLine ( ) - Read a line of text

ready boolean () - Decide if the flow is ready to be read

void reset () - Restores flow to the brand
recent
Example:

{public class
Reading Public static void main (String args []) {
String name = "" , address = ", phone = " " ;
BufferedReader buffer = new BufferedReader ( new InputStreamReader (System.in));
System . out. Print ( Name: ")
name = buffer. readLine ();
System.out. print ( "Address:" )
address = buffer. readLine ();
System.out. print ( "Telefono: ")
phone = buffer. readLine ();
System.out. println ( "\\ nData enter: \\ n" + name + "\\ n" + address + "\\ n" + phone);
System. exit (0);

}}

Sunday, November 1, 2009

Sympathy About Cancer

JTextField Reading

At the request of my friend Pollitux talk about events that produce the keyboard on a JTextField to process data quickly on this component.
class JTextField javax.swing package is a class that helps us to create text boxes, graphical user interfaces, which can be adding in a form and ask the user for a value we need to processing such as name, age, address, email, etc. Like all elements have a lot of methods and I shall only discuss some methods relevant.
Builders:
JTextField () - Creates an empty text field.
JTextField (int columns) - Creates an empty text field with a specific number of columns.
JTextField (String text) - Create a text field with a message
JTextField (String text, int columns) - Create a text field with a message and a specific number of columns.
Methods:
Void
addActionListener (java.awt.event.ActionListener action)
Adds a listener component action events, there is generally when we enter into the text field.
void addKeyListener (java.awt.event.KeyListener eventoTeclado)
Adds a listener component events from the keyboard, including enter. Responds to events like pressing a key, and release a key when painting the character corresponding to the key in the text field.
void addMouseListener (java.awt.event.MouseListener eventoMouse)
A gregarious an event listener component generated by the mouse.
void setFont (java.awat.Font source) - I change the font for the text field.
Our focus is on the KeyListener interface. This class provides three methods that we implement and are responding to keyboard events mentioned above:
void keyPressed (KeyEvent evt) - This method is invoked when a key is pressed.
void keyReleased (KeyEvent evt) - This method is invoked when a key is released.
void keyTyped (KeyEvent evt) - This method is invoked when the character is printed for the key pressed on a text field.
NOTE: As KeyListener is an interface must implement all methods, however, if we do not need all the adapters to use the listening component. All interfaces of action have an adapter that helps us to implement only the methods we need, if we may use your class KeyListener adapted KeyAdapter call.

Here a small example of using the KeyListener interface:

java.awt.GridLayout import, import
java.awt.event.KeyListener;
import java.awt.event . KeyEvent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField ;

EventosTeclado public class extends JFrame implements KeyListener {

    public EventosTeclado () {
        super ( "La interface KeyListener" );
        setSize ( 400, 150 );
        setLocationRelativeTo ( null );
        setResizable ( false );
        setDefaultCloseOperation ( JFrame. EXIT_ON_CLOSE );
        iniciarGUI ();
    }

    private void iniciarGUI () {
        JPanel pnlCampos = new JPanel ( new GridLayout ( 3, 2, -100, 0 ) );
        pnlCampos. setBounds ( 10, 10, 380, 85 );
        cmpNumero1 = new JTextField ( "0" );
        cmpNumero1. addKeyListener ( this );
        cmpNumero2 = new JTextField ( "0" );
        cmpNumero2. addKeyListener ( this );
        cmpResultado = new JTextField ( "0" );
        pnlCampos. add (new JLabel ( "Number:" ));
pnlCampos. add (cmpNumero1);
pnlCampos. add (new JLabel ( "Number:" ));
pnlCampos. add (cmpNumero2);
pnlCampos. add ( new JLabel ( "Sum:" ));
pnlCampos. add (cmpResultado)
getContentPane (). setLayout (null )
getContentPane (). add (pnlCampos)
}

public void keyPressed (KeyEvent AD) {
Sumar ();
}

public void keyReleased (KeyEvent AD) {
Sumar ();}


public void keyTyped (KeyEvent evt) {
summer ();}



private void summer () {
double amount = 0;
try {
; = double the amount. parseDouble (cmpNumero1. gettext ()) + double. parseDouble (cmpNumero2. gettext ());}

catch (NumberFormatException exc) {
sum = 0;

} finally {
; cmpResultado. setText ( "" + suma );
        }
    }

    public static void main ( String args[] ) {
        new EventosTeclado (). setVisible ( true );
   
}

private JTextField cmpNumero1;
private JTextField cmpNumero2;
private JTextField cmpResultado;
}