Advanced Java Programming

                          Advanced Java Programming


advanced java,
advanced java interview questions,
advanced java youtube,
advanced java in hindi,
advanced java online training,
what is advanced java topics,
advanced java interview questions for freshers,
advanced java programming syllabus,
advanced java j2ee interview questions,
introduction to advanced java,
introduction to advanced java programming,
advanced for java,
advanced java skills,
advanced java basic concepts,
is advanced java and j2ee same,
advanced java course online free,
advanced java web technologies,
advanced java development,
where to learn advanced java,
advanced java online training free,
advanced java introduction,
how to learn advanced java at home,
advanced java for beginners,
beginner to advanced java,
advanced java programming,
advanced java concepts youtube,
how much time it takes to learn advanced java,
what is core and advanced java,
advanced java 8 tutorial,
advanced java web development,
advanced java interview questions youtube,
how to run advanced java program in eclipse,
advanced java free course,
advanced java full tutorial,
advanced java and core java difference,
advanced java jsp tutorial,
advanced java web application,
java 7 advanced interview questions,
learn advanced java in 7 days,
software for advanced java,
advanced java definition,
advanced java and core,
what does advanced java consists of,
eclipse for advanced java,
java 6 advanced,
advanced java uses,
what does advanced java include,
advanced java vs core,
advanced java best tutorials,
advanced java programming handwritten notes,
advanced java jdbc program,
what are advanced java topics,
how to run advanced java program in netbeans,
java 9 advanced features,
advanced java coding,
java 8 advanced concepts,
advanced java mini projects,
advanced java language,
advanced java compiler,
why use advanced java,
advanced java and j2ee syllabus,
advanced java coding questions,
java 1.8 advanced interview questions,
what is jsp in advanced java,
java 8 advanced topics,
advanced java jdbc

Advanced Java Programming :- 

Introduction to advance java 

As most of us already know that if we want to make normal applications it  can be easily built using core Java concepts. But, when it we need to develop web applications, advanced Java fundamentals, like JSP, Servlets, JDBC etc. needed, so to add capabilities and features of the application advance java is essential for developers. Through the motive of this blog is to explain about Advanced Java, I will be giving you a complete insight into the fundamental concepts of Advance Java.
Figure - 1.2


If you want to see complete video on this please  have a look the video below.


                           Learn with Reshu



concepts of Advance Java.


Figure - 1.3

I hope you understood by the slide why Advanced Java is essential. For your better understanding, I have divided this article into two sections. Each of these section deals with one of the most important concepts of advanced Java:
  1.                    JDBC  (Java DataBase Connectivity
  2.           Java Servlets

So, now let’s begin our discussion and understand the concept of Java Database Connectivity, a helpful tool to interact with the database.


Figure - 1.4

Common JDBC Components

The JDBC API provides the following interfaces and classes −
  • DriverManager is used to manage a list of database drivers. The first driver that recognizes a certain subprotocol under JDBC will be used to establish a database Connection.
  • Driver is an interface that handles the communications with the database server. It also abstracts the details associated with working with Driver objects.
  • Connection is an interface that consists all the methods required to connect to a database. The connection object represents communication context, i.e., all communication with the database is through connection object only.

   JDBC Driver Types



Figure - 1.5


Figure - 1.6



Figure - 1.7


Figure - 1.8


Figure - 1.9


Figure - 2.0


Figure - 2.1


Now let’s move on to the next topic and look at the steps required to create a JDBC Application.







Figure - 2.2

Figure - 2.3


Figure - 2.4


Figure - 2.5


Figure - 2.6


Figure - 2.7

Figure - 2.8


Figure - 2.9

Code Example is given below



package com.jdbc.eamples;
import java.sql.*;
public class MyDatabase {
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/databasename";
static final String USER = "your root username";
static final String PASS = "your root password";
public static void main(String[] args) {
Connection conn = null;
Statement stmt = null;
try {
Class.forName("com.mysql.cj.jdbc.Driver");
System.out.println("Connecting to database...");
conn = DriverManager.getConnection(DB_URL,"USER",PASS);
System.out.println("Creating statement...");
stmt = conn.createStatement();
//first inserting data in table
String sql= "INSERT INTO emp VALUES (101, 'Taylor', 'Swift', 30)";
stmt.executeUpdate(sql);
sql= "INSERT INTO  emp VALUES(102, 'Linkin', 'Park', 28)";
stmt.executeUpdate(sql);
System.out.println("Inserted records into the table...");
System.out.println("Creating statement...");
System.out.println("database connected");

//then fetching data from table

sql = "SELECT idemp, first, last, age FROM emp";
ResultSet rs = stmt.executeQuery(sql);
//STEP 5: Extract data from result set
while(rs.next()){
//Retrieve by column name
int id  = rs.getInt("idemp");
int age = rs.getInt("age");
String first = rs.getString("first");
String last = rs.getString("last");
//Display values
System.out.print("ID: " + id);
System.out.print(", Age: " + age);
System.out.print(", First: " + first);
System.out.println(", Last: " + last);
}
//STEP 6: Clean-up environment
rs.close();
stmt.close();
conn.close();
} catch(SQLException se){
//Handle errors for JDBC
se.printStackTrace();
}catch(Exception e){
//Handle errors for Class.forName
e.printStackTrace();
}finally{
//finally block used to close resources
try{
if(stmt!=null)
stmt.close();
}catch(SQLException se2){
}// nothing can be done
try{
if(conn!=null)
conn.close();
}catch(SQLException se){
se.printStackTrace();
}//end finally try
}//end try
System.out.println("Goodbye!");
}//end main
}

Introduction to Servlets

A servlet is a java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers.
 Servlet can be described as follows:
     1.     Servlet is a technology which is used to create a web application.
  1. It is an API that provides many interfaces and classes including documentation.
  2. Servlet is an interface that must be implemented for creating any Servlet.

  3. It is also a class that extends the capabilities of the servers and responds to the incoming requests. It can respond to any requests.

Client Server Architecture 





Complete Servlet Life Cycle  



Create a dynamic Web Project using Servlet

Code example is given below





There are one Servlet in this project and one html page. In WEB-INF folder there is one web.xml file is present. 


In com.reshu package there is a Servlet file SumServlet present the work of this servlet is to take values of two numbers from request object given by server and then add those two numbers and show the addition to the page in the form of response to the html page


 package com.reshu;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SumServlet extends HttpServlet  {
public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException{
int i = Integer.parseInt(req.getParameter("num1"));
int j = Integer.parseInt(req.getParameter("num2"));
int k = i+j;
PrintWriter out = res.getWriter();
out.println("result is " + k);
}

}

Here below is the code of html page by which user send request to the SumServlet







the code given below is for web.xml file for servlet-mapping. In
web.xml file their is a mapping for Servlet and html page by which when user submit the page request call the servlet according to mapping in this file. In this case SumServlet.

                                            Web.xml


  

I hope you have enjoy my blog and please visit my youtube Channel for more videos in hindi.

                                   Learn With Reshu


Thanks for Reading Please subscribe for more interesting content everyday.....


Recommended Posts:

·       Overriding in Java
·       Overloading in Java
·       Interfaces in Java
·       Loops in Java
·       Variables in Java
·       Inheritance(IS-A) in Java
·       Abstraction in Java
·       Encapsulation in java
·       What is Java
·       Enabling Remote Debug

Comments

  1. Thanks for sharing a really needed post that i am looking for , if anyone looking for best java institute in delhi so join with us visit our website : https://www.htsindia.com/java-training-courses or contact us : +91-9311002620

    ReplyDelete

Post a Comment

Please do not comment any spam link in the comment box

Popular posts from this blog

Learn Complete OOPS Concepts in one Project

Spring Core