JDBC, Java Programming, and Web Development Concepts
JDBC
3 Drivers
Handlers, also called drivers, are a set of classes that implement classes and interfaces required for JDBC API that a Java application can connect with a BD. When developers want a BD that it can be accessible through JDBC they must implement a handler for that base of data, the mission manager will translate JDBC API standard commands to native protocol of the database.
4 A Basic JDBC Application
Every application that accesses a database using the JDBC API must a series of steps:
- Establish a connection to the database.
- Run one or more SQL statements
- If intrusions return data (SELECT) must process them.
- Releasing the resources of the connection.
is good practice manual release, for this release to occur as no longer useful. The resources we are releasing the ResultSet, the Statment and the connection itself. To release we invoke close () method will correspond to their objects. Invoke the method close () automatically releases Statment its resources ResultSet.
Compilers
Therefore, the compiler takes care of converting the source program into a program object.
Cast
The shell is a program that translates high-level code into binary code, but unlike the compiler, the runtime ago. That is, there is an initial process of translation of the entire source program into binary, but is translated and executed instruction by instruction.
In general, the main disadvantage of interpreters is that when a program is interpreted, typically runs slower than if the same program was compiled. This is because the interpreter must analyze each statement in the program at each execution (real-time analysis).
Applets
The Applet class provides everything needed to create applets. It is contained in the java.applet package, therefore, if we want to develop an applet import this package, as well as the package java.awt, javax.swing and java.awt that contain all the necessary tools to develop graphical interfaces.
The applet has the advantage of running in Internet browser on the client computer, but the designers of Java were placed some restrictions to prevent such damage or virus inserted in the machines where they run, these include:
- They can not read or write to the file system from a browser
- only have access to ERVER defined in the applet in a program that uses sockets
- unable to run programs on the client
- unable to load programs including native DLL.
If we want this applet to manage events, we import the java.awt .* package and use the ActionListener interface to implement the action that responds to the event in the method actionPerformed ()
Life Cycle of an Applet
- init (): the first method to load the applet is running and runs only once. It should be used to initialize the variables.
- start () is executed after the init (). Enables restart an applet after it has stopped. The start () method is executed every time the screen shows the HTML document containing the applet.
- paint () is executed every time you must repaint the output of an applet.
- stop () is executed when the browser leaves the page containing the applet HTML. Used to stop the applet; to restart it is called the start () method.
- destroy () is executed when the environment determines that the applet must be completely erased from memory. The stop () method always executes before the destroy.
What is a Thread
The Java Virtual Machine (JVM) is a multi-thread. That is, is capable of running multiple execution sequences (programs) simultaneously. The JVM handles all the details, assigning execution times, priorities, etc., similar to an Operating System and manages multiple processes
The basic difference between an operating system process and Thread Java Threads is that run inside the JVM, which is a process of the OS and therefore share all resources, including memory and the variables and objects defined therein. In this type of process where shared resources are sometimes called “lightweight processes” (lightweight process).
threads are useful because they allow the flow of the program is divided into two or more parts, each dealing with a task. For example, a Thread can handle the communication with the user, while others work in the background, making the transmission of a file, accessing system resources
Thread Class
The most direct way to make a multi-threaded program is to extend the Thread class and override the run () method. This method is invoked when you start the thread (by calling the start () method of the Thread class). The thread starts with the run method call and ends when it ends.
- The Thread class is in java.lang package. It is therefore not necessary to import.
- The constructor public Thread (String str) received a parameter that is the identification of Thread.
- The run method contains the block execution Thread. Within it, the method getName () returns the name of the Thread (which passed as argument to the constructor).
- The main method creates two objects of class ThreadEjemplo and begins with the call to start () method. (which starts the new thread and calls the run () method).
- Typical output in the first message, end the main thread. Implementation of threads is asynchronous. Make the call to start () method, it returns and continues to control its execution, independent of the other threads.
What is a Servlet?
Servlets are Java classes that extend the functionality of a Web server by generating dynamic Web pages. A runtime environment called servlet engine manages the loading and unloading the servlet, and works with the HTTP Web server to direct requests from remote users (clients) to the servlet and send the response to customers.
Servlets are born to meet the limitations of applets, namely:
- Limiting access another server that is not the same that is hosting the applet.
- Limitation on access to server services
- Security limitations. (reverse engineering to tweak the applet, for accessing the business logic of the system in question)
Features of Servlets
The features that make it very convenient servlets are:
- They are 100% pure Java, making them platform
- It is an object-oriented language and therefore possess all the characteristics that follow from this.
- You can use all the Java technologies: storage classes, threads, or threads, access to databases, Stream I / S, RMI, network access, etc..
- They are safe as they apply the Java Security Manager
- Communicating with others is simple servlets
- By handling exceptions can be handled simply errors during execution of the servlet.
Structured Programming
Programming is a theory that is to build facilcomprension programs.
is especially useful when you need realizarcorrecciones or changes after having completed a program or application
Web Applications
a web application is a collection of servlets, JSPs, Java classes, description files the application, static documentsHTML, XHTML, images, etc.. and other resources that can be packaged and executed on different servers from different vendors. That is, a web application could be defined coma the web tier of any application.
