{"id":385,"date":"2025-07-01T12:55:02","date_gmt":"2025-07-01T12:55:02","guid":{"rendered":"https:\/\/thetestdata.com\/blog\/?p=385"},"modified":"2025-07-06T09:54:36","modified_gmt":"2025-07-06T09:54:36","slug":"what-do-you-mean-by-pojo-why-we-use-pojo","status":"publish","type":"post","link":"https:\/\/thetestdata.com\/blog\/what-do-you-mean-by-pojo-why-we-use-pojo\/","title":{"rendered":"What is POJO and why we use POJO?"},"content":{"rendered":"\n<p>\ud83e\udd14 What is a POJO in Java?<\/p>\n\n\n\n<p><strong>POJO<\/strong> stands for <strong>Plain Old Java Object<\/strong>.<br>It means a simple Java class that:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Only has variables (fields)<\/strong> to store data<\/li>\n\n\n\n<li><strong>Has getter and setter methods<\/strong> to access that data<\/li>\n\n\n\n<li><strong>Doesn&#8217;t extend<\/strong> any framework classes (like <code>HttpServlet<\/code>, etc.)<\/li>\n\n\n\n<li><strong>Doesn\u2019t implement<\/strong> any special interfaces (unless needed)<\/li>\n\n\n\n<li><strong>Has no special rules or annotations<\/strong><\/li>\n<\/ul>\n\n\n\n<p>In short: a POJO is just a clean, lightweight class for <strong>holding data<\/strong>.<\/p>\n\n\n\n<p>\ud83d\udce6 Simple Example of POJO<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class Employee {\n    private int id;\n    private String name;\n\n    \/\/ Constructor\n    public Employee(int id, String name) {\n        this.id = id;\n        this.name = name;\n    }\n\n    \/\/ Getters\n    public int getId() { return id; }\n    public String getName() { return name; }\n\n    \/\/ Setters\n    public void setId(int id) { this.id = id; }\n    public void setName(String name) { this.name = name; }\n}<\/code><\/pre>\n\n\n\n<p>\ud83c\udfaf Why Do We Use POJOs?<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>To store and transfer data (like in APIs, databases, etc.)<\/li>\n\n\n\n<li>To keep classes clean and free from unnecessary logic<\/li>\n\n\n\n<li>Easy to test, easy to read<\/li>\n\n\n\n<li>Used in frameworks like Spring and Hibernate<\/li>\n<\/ul>\n\n\n\n<p>\u2705 Interview Key Points<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>Interview Question<\/th><th>Quick Answer<\/th><\/tr><\/thead><tbody><tr><td>What is a POJO?<\/td><td>A simple Java object with variables and methods<\/td><\/tr><tr><td>Does a POJO use inheritance or annotations?<\/td><td>No, it&#8217;s plain and simple<\/td><\/tr><tr><td>Where do we use POJOs?<\/td><td>In APIs, models, databases, and frameworks<\/td><\/tr><tr><td>Can we use POJO in Spring Boot?<\/td><td>Yes, it&#8217;s commonly used for request\/response<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n","protected":false},"excerpt":{"rendered":"<p>POJO (Plain Old Java Object) is a simple Java class used to encapsulate data without dependencies. It improves modularity, testability and framework.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[17],"tags":[],"class_list":["post-385","post","type-post","status-publish","format-standard","hentry","category-java-interview-questions"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/385","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/comments?post=385"}],"version-history":[{"count":4,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/385\/revisions"}],"predecessor-version":[{"id":404,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/posts\/385\/revisions\/404"}],"wp:attachment":[{"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/media?parent=385"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/categories?post=385"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thetestdata.com\/blog\/wp-json\/wp\/v2\/tags?post=385"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}