Learn Java and Programming through articles, code examples, and tutorials for developers of all levels.
Friday, December 13, 2024
[Solved] 3 Examples to reverse an Array in Java - Example Tutorial
How to Find Even and Odd Number in Java - Program Tutorial Example
Wednesday, December 11, 2024
How to Find Missing Number in a Sorted Array in Java [Solved]
How to Count number of 1s (Set Bits) in a binary number in Java [Solved]
How to Print Pyramid Pattern in Java? Program Example
*
* *
* * *
* * * *
* * * * *
You need to write a Java program to print the above pyramid pattern. How many levels the pyramid triangle would have will be decided by the user input. You can print this kind of pattern by using print() and println() method from System.out object. System.out.print() just prints the String or character you passed to it, without adding a new line, useful to print stars in the same line.
Monday, December 9, 2024
Top 20 Machine Learning Libraries for AI Engineers in 2025 - Best of Lot
Artificial Intelligence (AI) has emerged as a transformative technology, revolutionizing various industries and driving innovation. With the increasing accessibility of AI, numerous free tools have become available, enabling individuals and businesses to explore and leverage AI capabilities. In this article, we present the top 20 free Machine Learning libraries to try in 2025. These tools cover a wide range of AI applications, including machine learning, natural language processing, computer vision, and more. Let's dive into the exciting world of AI tools and discover how they can empower innovation and automation.
Sunday, December 8, 2024
How to call REST API an send HTTP GET and POST Request using cURL command in Linux? Example Tutorial
Thursday, October 31, 2024
How to Create Config Server in Microservices Architecture with Spring Cloud Config Server
The ability of microservices architecture to deconstruct big monolithic programmes into smaller, independent, and controllable services has led to its enormous growth in popularity in recent years. It can be difficult to manage configuration across numerous microservices, though, as each service may call for a separate set of configurations. To solve this problem, configurations for microservices are centralised and managed by a separate Config Server. In this post, we'll examine what a Config Server is, why it's crucial for microservices, and how to use Spring Cloud Config Server to construct it.
Tuesday, October 29, 2024
Top 10 AI Tools for Bloggers and Writers in 2025
Artificial Intelligence (AI) has revolutionized various industries, and the field of writing and blogging is no exception. AI-powered tools for bloggers and writers have emerged, offering innovative solutions to enhance creativity, streamline workflows, and improve content quality. In this article, we present the top 10 AI tools specifically designed for bloggers and writers. These tools leverage AI technologies such as natural language processing, machine learning, and data analytics to help writers generate ideas, improve grammar, enhance productivity, and optimize content for better engagement. Let's explore these cutting-edge AI tools and discover how they can empower bloggers and writers.
Monday, October 28, 2024
What is Payload in REST API? How to send Payload using HTTP Post Request and HttpClient
Hello and welcome to the blog post. In this comprehensive article we are going to take a look at an interesting topic. I’m sure you all are familiar with client-server architecture. If not let me recap it quickly for you.
A Client is a machine (or a web-browser) that request for desired results from the server. In other words, clients initiate requests for services or resources, while servers provide those services or resources upon request. The client-server model forms the foundation of many networked applications and systems, where clients and servers communicate and collaborate to fulfill various tasks and deliver services.
What is a Payload?
When a client sends a request to a server, the payload typically contains the data or parameters required by the server to process the request. For example, in a client-server architecture for a web application, the payload of an HTTP request sent by the client may include parameters for a form submission, JSON data for an API request, or a file to be uploaded.
On the server side, when the server sends a response back to the client, the payload contains the data or information requested by the client. This can include HTML content, JSON responses, file attachments, or any other data relevant to the specific request made by the client.
Payload in REST API
The information supplied in the body of an HTTP request is referred to as a payload in the RESTful API architecture. It represents the data that is being sent from the client to the server or the other way around. Depending on the content type supplied in the request headers, the payload may be in one of several forms, including JSON, XML, or plain text.
The payload carries the necessary data required to perform operations on the server or to retrieve specific resources. For example, when creating a new resource, the payload would typically contain the data that needs to be stored on the server. When updating an existing resource, the payload would include the modified data.
What is an HttpClient?
HttpClient is a powerful Java package that offers quick and efficient way for submitting HTTP requests and receiving server responses. Starting with Java 11, it is a part of the Java SE standard library and offers a comprehensive API for interacting with HTTP-based services.
HttpClient's main objective is to make it easier for client applications to communicate with RESTful APIs, web services, and other HTTP-based endpoints. The low-level aspects of creating and managing connections, dealing with request and response bodies, modifying headers, controlling timeouts, and dealing with redirection are abstracted away.
You can perform various HTTP operations like GET, POST, PUT, DELETE by using HttpClient. It supports both synchronous and asynchronous request processing and offers a number of configuration options for customization.
Let’s take an example on how to send a POST request to REST API using HttpClient
import com.fasterxml.jackson.databind.ObjectMapper;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpHeaders;
import java.net.http.HttpResponse.BodyHandlers;
public class HttpClientExample {
public static void main(String[] args) throws Exception {
// Create an instance of HttpClient
HttpClient httpClient = HttpClient.newHttpClient();
// Define the URL of the REST API endpoint
String url = "http://api.example.com/users";
// Create a User object
User user = new User("John Doe", 30);
// Serialize the User object to JSON
ObjectMapper objectMapper = new ObjectMapper();
String requestBody = objectMapper.writeValueAsString(user);
// Build the HTTP request
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(url))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
.build();
// Send the request and receive the response
HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());
// Extract the User object from the response
String responseBody = response.body();
User responseUser = objectMapper.readValue(responseBody, User.class);
// Print the response User object
System.out.println("Response User: " + responseUser);
}
}
class User {
private String name;
private int age;
// Constructors, getters, and setters
@Override
public String toString() {
return "User{" +
"name='" + name + '\'' +
", age=" + age +
'}';
}
}
In this example, we have a User class representing the user object. We use the ObjectMapper from the Jackson library to serialize the User object to JSON format.
We then create an HttpRequest object with the necessary details, including the URI, headers (in this case, "Content-Type" is set to "application/json"), and the request body containing the serialized User object.
After sending the request using httpClient.send(), we receive the response as an HttpResponse object. We extract the response body as a JSON string.
Finally, we deserialize the response JSON string back into a User object using objectMapper.readValue(). The resulting User object represents the response payload, which we can use as needed.
Sending Payload to REST API using HTTP POST Request and HttpClient in Java
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpHeaders;
import java.net.http.HttpEntity;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class HttpClientExample {
public static void main(String[] args) throws Exception {
HttpClient httpClient = HttpClient.newHttpClient();
String jsonPayload = "{\"name\": \"Someone \", \"email\": \"someone@example.com\"}";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://example.com/api/resource"))
.header("Content-Type", "application/json")
.POST(BodyPublishers.ofString(jsonPayload))
.build();
HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());
int statusCode = response.statusCode();
String responseBody = response.body();
System.out.println("Status Code: " + statusCode);
System.out.println("Response Body: " + responseBody);
}
}
In the example above, we create a JSON payload using a sample data object. We set the HTTP method to POST, the request URL to "http://example.com/api/resource", and the content type to "application/json". The payload is then sent in the body of the request using the BodyPublishers.ofString() method.
Finally, we retrieve and handle the response from the server.
Remember to replace "http://example.com/api/resource" with the actual endpoint URL of the REST API you want to send the payload to, and modify the payload data according to your requirements and the API's expected format.
Let me show you how to send other types of payloads from the following example.
1) Sending a Form-UrlEncoded Payload
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpHeaders;
import java.net.http.HttpEntity;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
public class HttpClientExample {
public static void main(String[] args) throws Exception {
HttpClient httpClient = HttpClient.newHttpClient();
String payload = "name=" + URLEncoder.encode("John Doe", StandardCharsets.UTF_8)
+ "&email=" + URLEncoder.encode("johndoe@example.com", StandardCharsets.UTF_8);
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://example.com/api/resource"))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(BodyPublishers.ofString(payload))
.build();
HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());
int statusCode = response.statusCode();
String responseBody = response.body();
System.out.println("Status Code: " + statusCode);
System.out.println("Response Body: " + responseBody);
}
}
In this example, we are sending a form-urlencoded payload to the REST API endpoint "http://example.com/api/resource". The payload contains two fields, name and email, which are URL-encoded using the URLEncoder.encode() method. The Content-Type header is set to "application/x-www-form-urlencoded".
2) Sending a Plain Text Payload
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpHeaders;
import java.net.http.HttpEntity;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;
public class HttpClientExample {
public static void main(String[] args) throws Exception {
HttpClient httpClient = HttpClient.newHttpClient();
String textPayload = "This is a plain text payload.";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://example.com/api/resource"))
.header("Content-Type", "text/plain")
.POST(BodyPublishers.ofString(textPayload))
.build();
HttpResponse<String> response = httpClient.send(request, BodyHandlers.ofString());
int statusCode = response.statusCode();
String responseBody = response.body();
System.out.println("Status Code: " + statusCode);
System.out.println("Response Body: " + responseBody);
}
}
In this example, we are sending a plain text payload to the REST API endpoint "http://example.com/api/resource". The payload simply contains the text "This is a plain text payload." The Content-Type header is set to "text/plain" to indicate that the payload is in plain text format.
Summary
In summary, sending a payload to a REST API using an HTTP POST request and HttpClient in Java involves creating an HTTP request with the desired payload, specifying the necessary headers, and sending the request using the HttpClient instance. The server will process the payload and provide a response, which can be accessed and utilized accordingly.
Sunday, October 27, 2024
20 Examples of Git Commands in Linux and Windows
Version control is crucial in software development, and Git stands out as a powerful tool for managing source code. Whether you're working in a Linux or Windows environment, understanding Git commands is essential. This article explores 20 fundamental Git commands, demonstrating their application and significance. From initializing a repository to handling branches and commits, each command plays a pivotal role in maintaining a well-organized and collaborative development workflow. Whether you're a seasoned developer or a newcomer, mastering these Git commands will enhance your ability to track changes, collaborate seamlessly, and contribute effectively to software projects.
Friday, October 25, 2024
Is Frontend Master Worth It?
Frontend development has been growing rapidly in the last few years, as web applications have become more complex and interactive. Frontend Master is an online platform that provides courses and tutorials to learn front-end development. However, with so many resources available on the internet, it's difficult to know whether Frontend Master is worth investing your time and money. In this article, we'll take a closer look at what Frontend Master has to offer and whether it's worth the investment.
Saturday, October 19, 2024
Top 10 Programming Languages to Learn in 2025 [UPDATED]
Monday, October 14, 2024
5 Best DP-900 Certification Courses and Practice Test for Azure Data Fundamentals Exam in 2025
The DP-900 certification, also known as the Microsoft Azure Data Fundamentals Certification, is perfect for people who are just starting to work with data on the cloud. This certification will help you build foundational knowledge in cloud data services with Microsoft Azure. Taking the DP-900 certification exam will have many benefits. It will give you a broad overview of how data works in the cloud. It will also help you test your knowledge of cloud data within the ambit of Microsoft Azure services.
Wednesday, October 9, 2024
10 Tools Java Developers Should Learn in 2024 - (UPDATED)
Wednesday, October 2, 2024
7 Free 1Z0-803 and 1Z0-804 Sample Questions - OCAJP 7 and OCPJP 7 Mock Exams (Oracle Certified Associate Java SE 7 Programmer 1 and 2 )
Top 5 OCPJP7 books for 1Z0-804 and 1Z0-805 Exam - Java SE 7 II Certification
Monday, September 30, 2024
When to use PUT or POST in a RESTful API and Web Service? Answer
Thursday, September 19, 2024
Review - Is IT Fundamentals for Cybersecurity Specialization on Coursera Worth it?
Learning the information technology (IT) fundamentals in general and cyber security is a good investment in yourself since there is a massive demand for these skills. Companies need people to secure their infrastructure, such as their servers where they host the website and user's data, monitor their network for unauthorized access, and scan the employee computers for any trojan and viruses that could give hackers control over your system.
Tuesday, September 17, 2024
What is Backend for front-end Pattern? How to use it?
In the realm of microservices architecture, designing efficient communication between front-end applications and the back-end services is crucial. The Backend for Front-End (BFF) pattern has emerged as a useful architectural pattern to streamline this communication. In this article, we will delve into what the Backend for Front-End pattern is, its benefits, and how to effectively implement and utilize it in your microservices ecosystem.
What is Backend for front-end Pattern? How to use it?
How to Use the Backend for Front-End Pattern
Identify the Front-End Application
Understand the Front-End Requirements
Design the Backend for Front-End Service
Define Tailored APIs
Aggregate Data and Handle Complexity
Optimize Performance
Maintain Separation of Concerns
Handle Security and Authorization
Evolve and Scale
Benefits of the Backend for Front-End Pattern
Considerations for Using the Backend for Front-End Pattern
Conclusion
Review - Is IBM Data Analytics with Excel and R Professional Certificate Worth it?
Companies are always collecting data about their customer’s behavior on their platform or maybe their products review and many other standards to make better decisions to improve their services and the user experience. Still, this data needs someone who can leverage the power of the data to make decisions, which is the role of data analysts. This career is one of the hottest in this century. Analyzing the data to get insight and better understand your users and customer will help you make your business successful or maybe have a good position in a company.
Monday, September 16, 2024
Review - Is Data Science Fundamentals with Python and SQL Specialization on Coursera Worth It?
The demand for people who can analyze big data and extract meaningful information to drive decisions for companies is increasing every day. They need them to improve the quality of their services and deliver the best user experience for their customers. These actions are the responsibility and the role of the data scientists. Data scientists need to know many skills to perform the data analysis and make decisions such as the skills to collect data from different sources like the web and also extract and filter the data from the databases and clean them before performing analysis and even learn machine learning and deep learning to perform much more complex actions and make predictions but not all the data scientists know the artificial intelligence and not a mandatory skills. Still, it will be good if you have that in your belt.
Saturday, September 7, 2024
How to Print Prime Numbers from 1 to 100 in Java [Solved]
Friday, September 6, 2024
How to count a number of words in given String in Java? [Solved]
public int count(String word);
This method should return 1 if the input is "Java" and return 3 if the input is "Java, C++, Python". Similarly a call to wordCount(" ") should return 0.
Wednesday, September 4, 2024
3 ways to Find Duplicate Elements in a given Array in Java [Solved]
How to Perform Union of Two Linked Lists Using Priority Queue in Java? Example Tutorial
3 ways to Count words in Java String - Google Interview Questions with Solution
Tuesday, September 3, 2024
Review - Is Google Data Analytics Professional Certificate Really Worth it in 2024?
Hello friends, if you want to become a Data Analyst in 2024 and looking for best online courses, guides, and tutorials to learn Data Analysis then you have come to the right place. In the past, I have shared best Data Analysis courses, Books, and 2024 Data Analyst RoadMap, and in this article, I will share one of the most popular Coursera course to learn Data Analytic, Google Data Analytics Professional Certificate. With more than 800,000 enrollments on Coursera this is one of the most popular Data Analytics course on Coursera and why not? Its created from Google itself. It's also well structured, up-to-date and you will learn all essential Data Analytics skills from Google experts.
3 ways to check if a String contains SubString in Java? IndexOf, contains, and lastIndexOf Example
How to make Immutable class in Java? Mutable vs Immutable Objects
How I make immutable objects in Java? I've always thought that all objects are immutable, because if you change the content of an String example, it will always create you an new String object and point to that. However later I found that String is a special class and its specially designed as an Immutable class because its often cached. Obviously you cannot cache anything which is not constant and that make sense why String is Immutable in Java. But this encouraged me to learn more about Mutable and Immutable class in Java and how to create a custom Immutable class in Java.
Difference between StringTokenizer and Split method in Java? Example
1) The StringTokenizer is legacy, Prefer split() as more chances of its performance getting improved as happens in Java 7.
2) The StringTokenizer doesn't support regular expression, while spilt() does. However, you need to be careful, because every time you call split, it creates a new Pattern object and compiles expression into a pattern. This means if you are using the same pattern with different input, then consider using Pattern.split() method, because compiling a pattern takes more time later to check whether a given string matches a pattern or not.
5 ways to Compare String Objects in Java - Example Tutorial
Monday, September 2, 2024
4 ways to read String from File in Java - Example
Just like there are many ways for writing String to text file, there are multiple ways to read String form File in Java. You can use FileReader, BufferedReader, Scanner, and FileInputStream to read text from file. One thing to keep in mind is character encoding. You must use correct character encoding to read text file in Java, failing to do so will result in logically incorrect value, where you don't see any exception but content you have read is completely different than file's original content. Many of the method which is used to read String by default uses platform's default character encoding but they do have overloaded version which accepts character encoding.
How to download a file using HTTP in Java? Example
Hello guys, if you are looking for tutorial to understand about how to download a file using http in Java to have deep knowledge of java basics then you will definitely learn from this article. uploading and downloading files are common task but many Java developer are not aware about how to complete that. They don't know about HTTP and how to send and receive data using HTTP. Many of them also doesn't know about HttpClient which was added in JDK 11 as well as third party libraries like Apache HttpClient which you can use before JDK 11. Anyway, don't worry, we are again here with new article that is on download file using http will give all basics about the topic to our viewers or readers. Let's start with an example first.
How to read CSV file in Java without using a third-party library? FileReader Example Tutorial
How to write to a File with try-with-resource in Java? Example Tutorial
How to recursive copy directory in Java with sub-directories and files? Example
How to check if a File exists in Java with Example
How to append text to file in Java? Example Tutorial
How to work with Files and Directories in Java? Example Tutorial
Tuesday, August 27, 2024
How to escape HTML Special characters in JSP and Java? Example
How to lock a File before writing in Java? Example
Monday, August 26, 2024
Difference between Static and Dynamic binding in Java
Is Cracking the Coding Interview book still worth it in 2024? Review
Hello guys, if you are preparing for Programming Job interviews and wondering whether the classic Cracking the Coding Interview book by Gayle Laakmann McDowell is still worth it in 2024 then you have come to the right place. In the past, I have shared best books and courses for coding interviews where I mentioned this book and today, I am going to review this book in depth. This was one of the first book I used to prepare for coding interview and due to its focus on evergreen topic, I am happy to say that it's still relevant, but whether it's good enough now is another question, which we will find in this article.
Friday, August 23, 2024
Java ArrayList Tutorials and Examples for Beginners (with Java ArrayList Cheat Sheet)
How to calculate sum and difference of two complex numbers in Java? Example
Wednesday, August 21, 2024
Is System Design Interview Book Vol 1 and 2 by Alex Xu worth it in 2024? Review
Hello guys, if you are preparing for System design interviews or Software Design Interviews, then you must have come across System Design Interview - An Insider's Guide by Alex Xu, one of the most popular book on System Design after Designing Data-Intensive Applications by Martin Kleppmann. I first come across Alex Xu on Twitter when one of his image about how HTTPS works went viral. The image was quite detailed and presentable so I start following Alex and then I come across ByteByteGo, his online System design course and his book System Design Interview - An Insider's Guide.
Tuesday, August 20, 2024
7 Projects You Can Do to Become a Frontend Master
Here are some programming projects to boost your confidence and make you a better developer.
Calculator app Abacus
The program that we all use on a daily basis is the calculator. The calculator is a project that is both simple and practical. Creating a calculator app can help you learn, how to build reusable components, how to use props, and how to handle states.
Blog Website Writing hand
Building your own blog doesn't only improve your coding skill, but your online presence too. If you have a blog and share content regularly, you can get a lot of visitors which can increase your online presence.
Weather App
Having a fully-featured weather app in your portfolio can help you a lot to get clients. And if you deploy this app, not only you but many people may get benefit from it
Spotify 2.0 Multiple musical notes
You can create Spotify 2.0, your own Spotify version. You can add as many features as you can and after completing, you can deploy it online :)
Movies App Film projector
You can create a movies app from scratch where you need to show movie details, posters, trailers, and cast. I believe that you will enjoy building this project.
YouTube UI Clone DVD
If you want to learn about grids, flexbox, and handling states then it would be better if you clone the YouTube UI. You don't need to 100% do the same as YouTube, you have the freedom to redesign and create your own version of YouTube.
Chat App Speech balloon
If you want to learn about Firebase, Firestore, Real-time database and etc. This project is for you, having this project in your portfolio can make your portfolio strong.
Wednesday, July 24, 2024
3 Difference between Web Server vs Application Server vs Servlet Containers - Apache vs JBoss vs Tomcat
Sunday, July 21, 2024
10 Examples of Comparator, Comparable, and Sorting in Java 8
Hello guys, the Comparator class is used to provide code or logic for comparing objects in Java, while sorting a list of objects or a collection of objects. It's close cousin of Comparable which provides natural order sorting e.g. ascending and descending orders for numbers like int, short, long or float, and lexicographic order for String i.e. the order on which words are arranged in dictionaries. The Comparators are used while sorting arrays, lists and collections. You pass logic to compare objects and sorting methods like Collections.sort() use that logic to compare elements until they are arranged in sorted order.
Friday, June 7, 2024
How to Convert String to LocalDate, LocalTime, LocalDateTime and ZonedDateTime in Java? Example Tutorial
The JDK 8 added a new Date and Time API (JSR 310) which introduces new date and time classes like LocalDate, LocalTime, LocalDateTime, and ZonedDateTime. Now, if you have a String e.g. "2016-12-14 03:30" then how do parse it to LocalDate, LocalTime, LocalDateTime and ZonedDateTime? Similarly, if you have an instance of those classes how you can format to the String you want e.g. in dd/MM/yyyy format, or USA or UK format? Well, Java 8 provides a utility class called DateTimeFormatter which can be used to parse/format dates in Java 8. It also provides several built-in formatter e.g. ISO date format and other to facilitate formatting of dates to String.
Sunday, June 2, 2024
How to convert JSON to Map in Java 8 without using third party libraries like Jackson or Gson
Hello guys, If you are working with JSON data then you may know that JSON is collection of key value pairs and that's why many times, you also need to convert them into a Map in Java. While there are many Java libraries like Jackson and Gson which provides support of parsing JSON to Java objects, there is not much support for JSON parsing or manipulation on standard JDK. While JSON parsing is still a long overdue, starting with JDK 8u60+ the built-in Nashorn engine is capable to convert JSON content into java.util.Map. No external dependencies are required for parsing JSON in to Map as you will learn in this article.
Tuesday, May 28, 2024
Can You Override static method in Java? Method Hiding Example
Top 95 Programming Interview Questions Answers to Crack Any Coding Job Interview
Wednesday, May 22, 2024
Top 10 Online Courses to Learn Data Structure and Algorithms in 2024 - Best of Lot
Tuesday, May 21, 2024
Top 10 Free Core Spring, Spring MVC, and Spring Boot Courses for Beginners in 2024 - Best of Lot
Monday, May 20, 2024
8 Free Linux Courses for Programmers and IT Professionals to Learn Online [2024]
Sunday, May 19, 2024
Top 8 Online Courses to Learn Power BI in 2024 - Best of Lot
Saturday, May 18, 2024
Top 6 Free Database and SQL Query Courses for Beginners to Learn Online in 2024 - Best of Lot
Friday, May 17, 2024
Top 7 Free Online Courses to learn JavaScript in 2024 - Best of Lot
Top 6 Online Courses to Learn Linux and UNIX in 2024 - Best of Lot [UPDATED]
7 Free Blockchain Developer Courses and Certifications to Learn in 2024 - Best of Lot
Saturday, May 11, 2024
3 ways to check if checkbox is selected in jQuery - Example Tutorial
So, you have a checkbox and you want to check if its selected or not at runtime using jQuery. If that's what you want then continue reading. A checkbox is an HTML element with type="checkbox" and checked property is used to find out whether a checkbox is selected or not. There are several ways to find if your checkbox has this property or not in jQuery e.g. by using :checked, a pseudo selector or by using is() jQuery function or by using prop() function which is available from jQuery 1.6 onward. In this article, we will see examples of these approaches to check if a check box is checked or not.