Spring - Perform Update Operation in CRUD
Last Updated :
23 Jul, 2025
CRUD (Create, Read, Update, Delete) operations are the building block for developers stepping into the software industry. CRUD is mostly simple and straight forward except that real-time scenarios tend to get complex. Among CRUD operations, the update operation requires more effort to get right compared to the other three operations. A pre-loaded database table is a pre-requisite for carrying out CRUD operations Read involves only reading data from the database and displaying it in the user interface (UI). Create is also similarly simple as it only involves taking input from the user and entering the validated input into the database.
Update and delete tend to get more complex to understand as it will involve the usage of data structures and other webpage concepts such as params, JSP page, etc. This tutorial aims to simplify the update operation for first-timers in CRUD. Before we get to the tutorial, it would be beneficial to see the visual representation of the operations in the web pages and databases involved in the operations.
The image given below shows the database that is to be populated on the webpage:
This is how the populated table will look along with the update and delete action Buttons:
Once the update button is clicked, this is how the data gets populated into the form:
Example Project
To understand how Update works, it's necessary to start with the read operation.
Java
public List<Student> getStudents() throws Exception {
List<Student> students = new ArrayList<>();
// the ArrayList students contains
// all the data from the database
return students;
}
Now the ArrayList students now get returned to the webpage via a servlet.
Note: The actual read operation has a longer code. The code depicted here is just to throw some light on the data structures used in the create operation. The List<Student> declaration uses a class named Student with all the variables, getters, and setters to initialize the ArrayList object.
Before proceeding to the servlet, it would help a little to take a look at the object structure that would be used in this code while using ArrayLists.
Student.java
Java
package com.jdbc;
public class Student {
private String name;
private String gender;
private String course;
private int id;
public Student(int id, String name,String course, String gender) {
this.name = name;
this.gender = gender;
this.course = course;
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getCourse() {
return course;
}
public void setCourse(String course) {
this.course = course;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
@Override
public String toString() {
return "Student [id=" + id + ", name" + name + ", course=" + course + ", gender=" + gender + "]";
}
}
StudentControllerServlet.java
Java
import javax.annotation.Resource;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.DataSource;
import com.jdbc.StudentDbUtil;
import com.jdbc.Student;
@WebServlet("/StudentControllerServlet")
public class StudentControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private StudentDbUtil studentDbUtil;
private void listStudents(HttpServletRequest request, HttpServletResponse response)
throws Exception {
// get students from db util
// This is where the database arraylist
// is received in the servlet
List<Student> students = studentDbUtil.getStudents();
// add students to the request
request.setAttribute("STUDENT_LIST", students);
// send to JSP page (view)
RequestDispatcher dispatcher = request.getRequestDispatcher("/CRUDform.jsp");
dispatcher.forward(request, response);
}
}
Code Explanation:
- The ArrayList 'students' is named as STUDENT_LIST using the request.setAttribute method.
- A dispatcher to the webpage (CRUDform.jsp) is initialized using 'RequestDispatcher dispatcher = request.getRequestDispatcher("/CRUDform.jsp");' and the control if forwarded to the same webpage using 'dispatcher.forward(request, response);'.
CRUDform.jsp
HTML
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib uri="http://www.oracle.com/technetwork/java/index.html" prefix="c" %>
<%@ page import="java.util.*" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Form</title>
</head>
<%
// get students from the request object (sent by servlet)
String crud = (String) request.getAttribute("COMMAND");
if(crud == null){
crud = "register";
StudentControllerServlet s = new StudentControllerServlet();
}
List<Student> theStudent = (List<Student>) request.getAttribute("STUDENT_LIST");
Student theStudents = (Student) request.getAttribute("THE_STUDENT");
%>
<body>
<table id="example" class="table table-striped" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Course</th>
<th>Gender</th>
</tr>
</thead>
<tbody>
<c:forEach var="tempStudent" items="${STUDENT_LIST}">
<!-- set up a link for each row -->
<c:url var="tempLink" value="StudentControllerServlet">
<c:param name="command" value="LOAD" />
<c:param name="studentId" value="${tempStudent.id}" />
<c:param name="crud" value="UPDATE" />
</c:url>
<!-- set up a link to delete a row -->
<c:url var="deleteLink" value="StudentControllerServlet">
<c:param name="command" value="DELETE" />
<c:param name="studentId" value="${tempStudent.id}" />
</c:url>
<tr>
<td> ${tempStudent.name} </td>
<td> ${tempStudent.course} </td>
<td> ${tempStudent.gender} </td>
<td>
<a href="${tempLink}">Update</a>
|
<a href="${deleteLink}"
onclick="if (!(confirm('Are you sure you want to delete the entry with ID ${tempStudent.studentid} and studying in ${tempStudent.standard} year?'))) return false">Delete</a>
</td>
</tr>
</tbody>
</table>
</body>
</html>
The above example would require the usage of JSTL tags, database so make sure to install and add the required libraries (postgresql-42.3.1.jar, javax.servlet.jsp.jstl-1.2.1.jar, and javax.servlet.jsp.jstl-api-1.2.1.jar) in the project.
Code Explanation:
- The ArrayList with the name "STUDENT_LIST" can be retrieved using Java code written between opening braces '<%' and closing braces'%>'. The command '(List<Student>) request.getAttribute("STUDENT_LIST");' gets the attribute 'STUDENT_LIST' from the servlet, typecasts it into an object defined in the class name Student, and then it is stored in the variable of Object type using the command 'List<Student> theStudent = (List<Student>) request.getAttribute("STUDENT_LIST");'.
- Now the ArrayList named "theStudent" is what is used to populate tables with the database entries.
- Here comes the usage of JSTL tags. The <c:forEach> tag, which can be considered as a JSTL equivalent of the Java "for loop", is used to iterate through the ArrayList "STUDENT_LIST" and the tag has to be defined as follows: <c:forEach var="tempStudent" items="${STUDENT_LIST}"> </c:forEach>.
- Between the opening and closing of <c:forEach> tag comes the code for populating the table.
- The <c:url> tag is used to format a URL into a string and store it into a variable and to perform URL rewriting when necessary. The <c:param> tag has the attributes name, value which sets the name and value of the request parameters in the URL respectively. Here, the name attribute is mandatory with no default value whereas the value parameter is not compulsory. For example, the tag '<c:url var="tempLink" value="StudentControllerServlet"><c:param name="command" value="LOAD" /><c:param name="studentId" value="${tempStudent.id}" /><c:param name="crud" value="UPDATE" /></c:url>' writes the target URL as http://localhost:8001/HibernateStudent/StudentControllerServlet?command=LOAD&studentId=k16&id=3&crud=UPDATE where the attribute command is passed with value "LOAD" which is a vital attribute.
- When the button labeled as "UPDATE" corresponding to the LOAD attribute is pressed and the controller goes to the StudentControllerServlet mentioned in the URL given above.
StudentControllerServlet.java
Refer to this article Resource Injection in Java EE to understand the first line in the code snippet given below.
Java
@Resource(name="jdbc/test")
private DataSource dataSource;
@Override
public void init() throws ServletException {
super.init();
// create our student db util ...
// and pass in the conn pool / datasource
try
{
studentDbUtil = new StudentDbUtil(dataSource);
}
catch (Exception exc) {
throw new ServletException(exc);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
String theCommand = request.getParameter("command");
switch (theCommand) {
case "LOAD":
loadStudent(request, response);
break;
}
}
catch (Exception exc) {
throw new ServletException(exc);
}
}
private void loadStudent(HttpServletRequest request, HttpServletResponse response)
throws Exception {
// read student id from form data
int id = Integer.parseInt(request.getParameter("id"));
String theStudentId = request.getParameter("studentId");
String crud = request.getParameter("crud");
// get student from database (db util)
Student theStudent = studentDbUtil.getStudent(id);
// get students from db util and control continues
List<Student> students = studentDbUtil.getStudents();
// add students to the request
request.setAttribute("STUDENT_LIST", students);
// place student in the request attribute
request.setAttribute("THE_STUDENT", theStudent);
request.setAttribute("COMMAND", "update");
// send to jsp page: CRUDform.jsp
RequestDispatcher dispatcher = request.getRequestDispatcher("/CRUDform.jsp");
dispatcher.forward(request, response);
}
Code Explanation:
- The annotation @Resource(name="jdbc/test") along with the command "private DataSource dataSource;" will be used to establish the database connection.
- The "LOAD" command declared on the previous page is received in the servlet using the "String theCommand = request.getParameter("command");" command and is accordingly the control goes into the update function as per the switch case statement.
- After entering into the loadstudent method, the attributes id, theStudentId, crud are received using requests from the previous page. Now the details corresponding to the particular ID are retrieved by invoking the "Student theStudent = studentDbUtil.getStudent(id);" by passing the ID as a parameter which is demonstrated in the code given below.
StudentDbUtil.java
Java
// point of resource injection
public DataSource dataSource;
public StudentDbUtil(DataSource theDataSource) {
dataSource = theDataSource;
}
public Student getStudent(int theStudentId) throws Exception{
Student theStudent = null;
Connection myConn = null;
PreparedStatement myStmt = null;
ResultSet myRs = null;
String studentId;
try {
// get connection to database
myConn = dataSource.getConnection();
//create sql to get selected student
String sql = "select * from students where id=?";
// create prepared statement
myStmt = myConn.prepareStatement(sql);
// set params
myStmt.setInt(1, theStudentId);
// execute statement
myRs = myStmt.executeQuery();
// retrieve data from result set row
if (myRs.next()) {
int id = myRs.getInt("id");
String name = myRs.getString("name");
String course = myRs.getString("course");
String gender = myRs.getString("gender");
// create new student object
theStudent = new Student(id, name, course, gender);
}
else {
throw new Exception("Could not find student id: " + theStudentId);
}
return theStudent;
}
finally {
close(myConn, myStmt, myRs);
}
}
Code Explanation:
- The line 'studentDbUtil.getStudent(id);' invokes the corresponding method in the StudentDbUtil.java class.
- The command 'myConn = dataSource.getConnection();' gets a connection to the database. After this command, the 'myConn' variable will be used to reference the database connectivity wherever required.
- After that, in the try block, the select query 'String sql = "select * from students where id=?";', the prepared statement 'myStmt = myConn.prepareStatement(sql);' are declared and parameters are set for retrieving the corresponding data.
- The id is set in the query using 'myStmt.setInt(1, theStudentId);' and the select query is executed with 'myRs = myStmt.executeQuery();' and stored in the result set (myRs) variable.
- The result set is iterated and an object is invoked to store the data which is to be passed to the webpage.
- The connection is closed in the finally block and now it's time to return the control to the servlet.
Java
private void loadStudent(HttpServletRequest request, HttpServletResponse response)
throws Exception {
// get students from db util and control continues
List<Student> students = studentDbUtil.getStudents();
// add students to the request
request.setAttribute("STUDENT_LIST", students);
// place student in the request attribute. This is what is used to pre-populate the form with data from the database.
request.setAttribute("THE_STUDENT", theStudent);
// the attribute command is set to update for identification purpose.
request.setAttribute("COMMAND", "update");
// send to jsp page: CRUDform.jsp
RequestDispatcher dispatcher = request.getRequestDispatcher("/CRUDform.jsp");
dispatcher.forward(request, response);
}
The control gets directed to CRUDform.jsp page and the attributes are checked within the '<%' and '%>' tags before the body tags to decide whether it is an update or list, or register operation.
HTML
<%
// get students from the request object (sent by servlet)
String crud = (String) request.getAttribute("COMMAND");
if(crud == null){
crud = "register";
StudentControllerServlet s = new StudentControllerServlet();
}
List<Student> theStudent = (List<Student>) request.getAttribute("STUDENT_LIST");
Student theStudents = (Student) request.getAttribute("THE_STUDENT");
%>
<body>
<div class="container">
<div class="title">FORM</div>
<div class="content">
<form name="myForm" action="StudentControllerServlet" method="POST" onsubmit="return validateForm()">
<%
if(crud.equals("register")){%>
<input type="hidden" name="command" value="ADD" />
<%}else if(crud.equals("update")){%>
<input type="hidden" name="command" value="UPDATE" />
<input type="hidden" name="id" value="${THE_STUDENT.id}" />
<%}
%>
<div class="user-details">
<div class="input-box">
<span class="details">Name </span>
<input type="text" name="name" placeholder="Enter name" required value="${THE_STUDENT.name}"/> <br><br>
</div>
<div class="input-box">
<span class="details">Course </span>
<select name="course" id="course">
<%if(crud.equals("register")){%>
<option value="CSE">CSE</option>
<option value="IT">IT</option>
<option value="ECE">ECE</option>
<br><br>
</select>
<%}else if(crud.equals("update")){%>
<%if(theStudents.getCourse().equals("CSE")){%>
<option value="CSE" selected>CSE</option>
<%}else{%>
<option value="CSE">CSE</option>
<%}%>
<%if(theStudents.getCourse().equals("IT")){%>
<option value="IT" selected>IT</option>
<%}else{%>
<option value="IT">IT</option>
<%}%>
<%if(theStudents.getCourse().equals("ECE")){%>
<option value="ECE" selected>ECE</option>
<%}else{%>
<option value="ECE">ECE</option>
<%}%>
<%}%>
</select>
<%if(crud.equals("register")){%>
<input type="radio" id="male" name="gender" value="Male">
<label for="male">Male </label>
<label for="male">Female </label>
<label for="male">Transgender </label>
</select>
<%}else if(crud.equals("update")){%>
<%if(theStudents.getGender().equals("Male")){%>
<input type="radio" id="male" name="gender" value="Male" checked>
<label for="male">Male </label>
<%}else{%>
<input type="radio" id="male" name="gender" value="Male">
<label for="male">Male </label>
<%}%>
<%if(theStudents.getGender().equals("Female")){%>
<input type="radio" id="female" name="gender" value="Female" checked>
<label for="female">Female </label>
<%}else{%>
<input type="radio" id="female" name="gender" value="Female">
<label for="female">Female </label>
<%}%>
<%if(theStudents.getGender().equals("Transgender")){%>
<input type="radio" id="transgender" name="gender" value="Transgender" checked>
<label for="transgender">Transgender </label>
<%}else{%>
<input type="radio" id="transgender" name="gender" value="Transgender">
<label for="transgender">Transgender </label>
<%}%>
<%}%>
</div>
<%
if(crud.equals("update")){%>
<button name="submit" value="SUBMIT" type="submit">Update</button>
<%}else if(crud.equals("register")){%>
<button name="submit" value="SUBMIT" type="submit">Register</button>
<%}%>
</form>
Code Explanation:
- The attribute "COMMAND" is received in the JSP page using 'String crud = (String) request.getAttribute("COMMAND");' and stored in the variable named 'crud'.
- The ArrayLists 'List<Student> theStudent = (List<Student>) request.getAttribute("STUDENT_LIST");' and 'Student theStudents = (Student) request.getAttribute("THE_STUDENT");' are received from the servlet.
- The value of 'crud' is checked and if it has the value "update" then a hidden input type is initiated to indicate that the operation is an "update" operation when the form is submitted.
- Auto populating a text or date picker field is straightforward enough, adding value="${THE_STUDENT.name}" to the corresponding tag will do the work. Here, THE_STUDENT denotes the ArrayList name, name denotes the 'name variable' in the ArrayList and ${} is used since it's Java code being used in HTML.
- Now comes the real challenge for beginners, the value attribute does not work in dropdown or radio buttons. This is where JSTL tags come to save the day.
- Condition checking is done and components are auto selected accordingly. For example, the command <%if(theStudents.getCourse().equals("CSE")){%> checks if the value of course in the ArrayList is equal to CSE and if the condition is satisfied then the option CSE is auto selected in the dropdown using <option value="CSE" selected>CSE</option>. If not, then the else clause is executed where the HTML tag is entered without being selected <%}else{%> <option value="CSE">CSE</option> <%}%>
- The above if and else in JSTL format can also be applied for radio buttons for auto-selecting according to the data in the database only change is the usage of "checked" keyword instead of selected as demonstrated in the code given above.
- The control goes to the servlet code given below when the form is submitted.
StudentControllerServlet.java
Java
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try {
// read the "command" parameter
String theCommand = request.getParameter("command");
// route to the appropriate method
switch (theCommand) {
case "UPDATE":
updateStudent(request, response);
break;
}
catch (Exception exc) {
throw new ServletException(exc);
}
}
private void updateStudent(HttpServletRequest request, HttpServletResponse response)
throws Exception {
// read student info from form data
int id = Integer.parseInt(request.getParameter("id"));
String name = request.getParameter("name");
String course = request.getParameter("course");
String gender = request.getParameter("gender");
// create a new student object
Student theStudent = new Student(id,name,course,gender);
// perform update on database
studentDbUtil.updateStudent(theStudent);
// get students from db util
List<Student> students = studentDbUtil.getStudents();
// add students to the request
request.setAttribute("STUDENT_LIST", students);
// send them back to the "list students" page
listStudents(request, response);
}
As demonstrated in the previous servlet example, the control goes to the database class in the line 'studentDbUtil.updateStudent(theStudent);'
StudentDbUtil.java
Java
public void updateStudent(Student theStudent) throws Exception{
Connection myConn = null;
PreparedStatement myStmt = null;
try {
// get connection to database
myConn = dataSource.getConnection();
// create SQL update statement
String sql = "update student "
+ "set name=?,gender=?,course=? "
+ "where id=?";
// prepare statement
myStmt = myConn.prepareStatement(sql);
//set params
myStmt.setString(1, theStudent.getName());
myStmt.setString(2, theStudent.getGender());
myStmt.setString(3, theStudent.getCourse());
myStmt.setInt(4, theStudent.getId());
myStmt.execute();
}
finally {
// clean up JDBC objects
close(myConn, myStmt, null);
}
}
Now the connection is established, the query is written and the query is executed in the code given above. Update is the comparatively harder part of CRUD operations, especially populating radio buttons and dropdown lists and it has been simplified to a large extent in this article. So, we're done now!
Note: It is highly recommended to create a SERIAL column named 'id' when creating the table and then use that unrelated column in the WHERE clause of SQL queries so as to avoid errors while executing queries.
Similar Reads
Java Tutorial Java is a high-level, object-oriented programming language used to build web apps, mobile applications, and enterprise software systems. Known for its Write Once, Run Anywhere capability, which means code written in Java can run on any device that supports the Java Virtual Machine (JVM).Syntax and s
10 min read
Basics
Introduction to JavaJava is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is platform-independent, which means we can write code once and run it anywhere using the Java Virtual Machine (JVM). Java is mostly used for building desktop applications, web applications, Android
4 min read
Java Programming BasicsJava is one of the most popular and widely used programming language and platform. A platform is an environment that helps to develop and run programs written in any programming language. Java is fast, reliable and secure. From desktop to web applications, scientific supercomputers to gaming console
4 min read
Java MethodsJava Methods are blocks of code that perform a specific task. A method allows us to reuse code, improving both efficiency and organization. All methods in Java must belong to a class. Methods are similar to functions and expose the behavior of objects.Example: Java program to demonstrate how to crea
7 min read
Access Modifiers in JavaIn Java, access modifiers are essential tools that define how the members of a class, like variables, methods, and even the class itself, can be accessed from other parts of our program. They are an important part of building secure and modular code when designing large applications. In this article
6 min read
Arrays in JavaIn Java, an array is an important linear data structure that allows us to store multiple values of the same type. Arrays in Java are objects, like all other objects in Java, arrays implicitly inherit from the java.lang.Object class. This allows you to invoke methods defined in Object (such as toStri
9 min read
Java StringsIn Java, a String is the type of object that can store a sequence of characters enclosed by double quotes and every character is stored in 16 bits, i.e., using UTF 16-bit encoding. A string acts the same as an array of characters. Java provides a robust and flexible API for handling strings, allowin
8 min read
Regular Expressions in JavaIn Java, Regular Expressions or Regex (in short) in Java is an API for defining String patterns that can be used for searching, manipulating, and editing a string in Java. Email validation and passwords are a few areas of strings where Regex is widely used to define the constraints. Regular Expressi
7 min read
OOPs & Interfaces
Classes and Objects in JavaIn Java, classes and objects are basic concepts of Object Oriented Programming (OOPs) that are used to represent real-world concepts and entities. A class is a template to create objects having similar properties and behavior, or in other words, we can say that a class is a blueprint for objects.An
10 min read
Java ConstructorsIn Java, constructors play an important role in object creation. A constructor is a special block of code that is called when an object is created. Its main job is to initialize the object, to set up its internal state, or to assign default values to its attributes. This process happens automaticall
10 min read
Java OOP(Object Oriented Programming) ConceptsBefore Object-Oriented Programming (OOPs), most programs used a procedural approach, where the focus was on writing step-by-step functions. This made it harder to manage and reuse code in large applications.To overcome these limitations, Object-Oriented Programming was introduced. Java is built arou
10 min read
Java PackagesPackages in Java are a mechanism that encapsulates a group of classes, sub-packages and interfaces. Packages are used for: Prevent naming conflicts by allowing classes with the same name to exist in different packages, like college.staff.cse.Employee and college.staff.ee.Employee.They make it easier
8 min read
Java InterfaceAn Interface in Java programming language is defined as an abstract type used to specify the behaviour of a class. An interface in Java is a blueprint of a behaviour. A Java interface contains static constants and abstract methods. Key Properties of Interface:The interface in Java is a mechanism to
11 min read
Collections
Exception Handling
Java Exception HandlingException handling in Java is an effective mechanism for managing runtime errors to ensure the application's regular flow is maintained. Some Common examples of exceptions include ClassNotFoundException, IOException, SQLException, RemoteException, etc. By handling these exceptions, Java enables deve
8 min read
Java Try Catch BlockA try-catch block in Java is a mechanism to handle exceptions. This make sure that the application continues to run even if an error occurs. The code inside the try block is executed, and if any exception occurs, it is then caught by the catch block.Example: Here, we are going to handle the Arithmet
4 min read
Java final, finally and finalizeIn Java, the keywords "final", "finally" and "finalize" have distinct roles. final enforces immutability and prevents changes to variables, methods, or classes. finally ensures a block of code runs after a try-catch, regardless of exceptions. finalize is a method used for cleanup before an object is
4 min read
Chained Exceptions in JavaChained Exceptions in Java allow associating one exception with another, i.e. one exception describes the cause of another exception. For example, consider a situation in which a method throws an ArithmeticException because of an attempt to divide by zero.But the root cause of the error was an I/O f
3 min read
Null Pointer Exception in JavaA NullPointerException in Java is a RuntimeException. It occurs when a program attempts to use an object reference that has the null value. In Java, "null" is a special value that can be assigned to object references to indicate the absence of a value.Reasons for Null Pointer ExceptionA NullPointerE
5 min read
Exception Handling with Method Overriding in JavaException handling with method overriding in Java refers to the rules and behavior that apply when a subclass overrides a method from its superclass and both methods involve exceptions. It ensures that the overridden method in the subclass does not declare broader or new checked exceptions than thos
4 min read
Java Advanced
Java Multithreading TutorialThreads are the backbone of multithreading. We are living in the real world which in itself is caught on the web surrounded by lots of applications. With the advancement in technologies, we cannot achieve the speed required to run them simultaneously unless we introduce the concept of multi-tasking
15+ min read
Synchronization in JavaIn multithreading, synchronization is important to make sure multiple threads safely work on shared resources. Without synchronization, data can become inconsistent or corrupted if multiple threads access and modify shared variables at the same time. In Java, it is a mechanism that ensures that only
10 min read
File Handling in JavaIn Java, with the help of File Class, we can work with files. This File Class is inside the java.io package. The File class can be used to create an object of the class and then specifying the name of the file.Why File Handling is Required?File Handling is an integral part of any programming languag
6 min read
Java Method ReferencesIn Java, a method is a collection of statements that perform some specific task and return the result to the caller. A method reference is the shorthand syntax for a lambda expression that contains just one method call. In general, one does not have to pass arguments to method references.Why Use Met
9 min read
Java 8 Stream TutorialJava 8 introduces Stream, which is a new abstract layer, and some new additional packages in Java 8 called java.util.stream. A Stream is a sequence of components that can be processed sequentially. These packages include classes, interfaces, and enum to allow functional-style operations on the eleme
15+ min read
Java NetworkingWhen computing devices such as laptops, desktops, servers, smartphones, and tablets and an eternally-expanding arrangement of IoT gadgets such as cameras, door locks, doorbells, refrigerators, audio/visual systems, thermostats, and various sensors are sharing information and data with each other is
15+ min read
JDBC TutorialJDBC stands for Java Database Connectivity. JDBC is a Java API or tool used in Java applications to interact with the database. It is a specification from Sun Microsystems that provides APIs for Java applications to communicate with different databases. Interfaces and Classes for JDBC API comes unde
12 min read
Java Memory ManagementJava memory management is the process by which the Java Virtual Machine (JVM) automatically handles the allocation and deallocation of memory. It uses a garbage collector to reclaim memory by removing unused objects, eliminating the need for manual memory managementJVM Memory StructureJVM defines va
4 min read
Garbage Collection in JavaGarbage collection in Java is an automatic memory management process that helps Java programs run efficiently. Java programs compile to bytecode that can be run on a Java Virtual Machine (JVM). When Java programs run on the JVM, objects in the heap are created, which is a portion of memory dedicated
7 min read
Memory Leaks in JavaIn programming, a memory leak happens when a program keeps using memory but does not give it back when it's done. It simply means the program slowly uses more and more memory, which can make things slow and even stop working. Working of Memory Management in JavaJava has automatic garbage collection,
3 min read
Practice Java
Java Interview Questions and AnswersJava is one of the most popular programming languages in the world, known for its versatility, portability, and wide range of applications. Java is the most used language in top companies such as Uber, Airbnb, Google, Netflix, Instagram, Spotify, Amazon, and many more because of its features and per
15+ min read
Java Programs - Java Programming ExamplesIn this article, we will learn and prepare for Interviews using Java Programming Examples. From basic Java programs like the Fibonacci series, Prime numbers, Factorial numbers, and Palindrome numbers to advanced Java programs.Java is one of the most popular programming languages today because of its
8 min read
Java Exercises - Basic to Advanced Java Practice Programs with SolutionsLooking for Java exercises to test your Java skills, then explore our topic-wise Java practice exercises? Here you will get 25 plus practice problems that help to upscale your Java skills. As we know Java is one of the most popular languages because of its robust and secure nature. But, programmers
7 min read
Java Quiz | Level Up Your Java SkillsThe best way to scale up your coding skills is by practicing the exercise. And if you are a Java programmer looking to test your Java skills and knowledge? Then, this Java quiz is designed to challenge your understanding of Java programming concepts and assess your excellence in the language. In thi
1 min read
Top 50 Java Project Ideas For Beginners and Advanced [Update 2025]Java is one of the most popular and versatile programming languages, known for its reliability, security, and platform independence. Developed by James Gosling in 1982, Java is widely used across industries like big data, mobile development, finance, and e-commerce.Building Java projects is an excel
15+ min read