<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Perla Pawan Phanieswar on Medium]]></title>
        <description><![CDATA[Stories by Perla Pawan Phanieswar on Medium]]></description>
        <link>https://medium.com/@pawanphanieswar?source=rss-7aecce5ce941------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by Perla Pawan Phanieswar on Medium</title>
            <link>https://medium.com/@pawanphanieswar?source=rss-7aecce5ce941------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 06 Dec 2026 15:09:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pawanphanieswar/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[System Design and how to Approach it]]></title>
            <link>https://medium.com/@pawanphanieswar/system-design-and-how-to-approach-it-56b3ba71b63e?source=rss-7aecce5ce941------2</link>
            <guid isPermaLink="false">https://medium.com/p/56b3ba71b63e</guid>
            <category><![CDATA[system-design-concepts]]></category>
            <category><![CDATA[system-design-course]]></category>
            <category><![CDATA[system-design-interview]]></category>
            <dc:creator><![CDATA[Perla Pawan Phanieswar]]></dc:creator>
            <pubDate>Sun, 28 Dec 2025 17:21:22 GMT</pubDate>
            <atom:updated>2025-12-28T17:26:09.920Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*PtIUiAGZ7gAySHcHqfuKtg.jpeg" /></figure><p><strong>System Design</strong> is the process of <strong>planning and structuring a software system</strong> so that it:</p><ul><li>Solves a real-world problem</li><li>Handles users efficiently</li><li>Is scalable, reliable, and maintainable</li></ul><p>System Design mainly focuses on <strong>architecture-level decisions</strong>, not coding syntax.</p><h3>Why do we need System Design?</h3><p>Because real systems:</p><ul><li>Have <strong>millions of users</strong></li><li>Store <strong>huge amounts of data</strong></li><li>Must be <strong>fast, secure, and always available</strong></li></ul><p>Without proper design:</p><ul><li>Systems become slow</li><li>Bugs increase</li><li>Scaling becomes painful</li><li>Small changes break everything</li></ul><p>System Design is <strong>mostly about non-functional requirements</strong> which are :</p><ul><li>Scalability — handle growth</li><li>Availability — system is always up</li><li>Reliability — consistent actions</li><li>Latency — time taken for requests</li><li>Consistency — data correctness</li><li>Fault<strong> </strong>Tolerance — survive failures</li><li>Maintainability — easy to update</li><li>Security — Protect Data</li></ul><h3>Two Major Types of System Design</h3><h4>1. High-Level Design (HLD)</h4><p>Focuses on:</p><ul><li>Overall architecture</li><li>Components &amp; services</li><li>Databases, caches, queues</li><li>Communication between services</li></ul><h4>2. Low-Level Design (LLD)</h4><p>Focuses on:</p><ul><li>Classes</li><li>APIs</li><li>Data structures</li><li>Object interactions</li></ul><h3><strong>How to Approach System Design</strong></h3><p>Approaching system design means how you think and proceed step-by-step.</p><p>Never jump into components or databases immediately. Always <strong>start broad</strong>, then go deeper.</p><h4><strong>STEP 1: Know the Requirements</strong></h4><p><strong>Functional Requirements</strong></p><ul><li>What should the system do?</li><li>Core features only (not everything)</li></ul><p><strong>Non-Functional Requirements</strong></p><ul><li>Scale (users / requests per second)</li><li>Latency expectations</li><li>Availability vs consistency</li><li>Security requirements</li></ul><h3>STEP 2: Scale &amp; Constraints</h3><p><strong>Now quantify the system :</strong></p><ul><li>Daily active users</li><li>Requests per second (RPS)</li><li>Data size per day/year</li><li>Read vs write ratio</li></ul><p>This helps to decide:</p><ul><li>Database you want to use</li><li>Caching</li><li>Sharding</li><li>Replication</li></ul><h4>STEP 3: High-Level Design (HLD)</h4><p>Get the big components and a high level picture of how the system should be designed. Think of adding a Cache, Message queues, External services.</p><h4>STEP 4: Database Design</h4><p><strong>Decide what to use:</strong></p><ul><li>SQL vs NoSQL</li><li>Schema design</li><li>Indexing strategy</li><li>Sharding keys</li></ul><p><strong>Know the trade-offs :</strong></p><ul><li>Consistency vs availability</li><li>Joins vs denormalization</li></ul><h4><strong>STEP 5: Low Level Design (LLD)</strong></h4><p><strong>Get into critical parts:</strong></p><ul><li>API design</li><li>Core classes</li><li>Algorithms</li><li>Hot paths</li></ul><h4>STEP 6: Scalability &amp; Performance</h4><p><strong>Dive into :</strong></p><ul><li>Horizontal scaling</li><li>Caching layers</li><li>Load balancing strategies</li><li>Asynchronous processing</li></ul><h4>STEP 7: Reliability &amp; Fault Tolerance</h4><p><strong>Add these in the design:</strong></p><ul><li>Replication</li><li>Failover</li><li>Circuit breakers</li><li>Idempotency</li><li>Retry mechanisms</li></ul><h3>STEP 8: Security &amp; Edge Cases</h3><p><strong>Make sure the system has :</strong></p><ul><li>Authentication &amp; authorization</li><li>Rate limiting</li><li>Data encryption</li><li>Abuse prevention</li></ul><p>And that is it! You have now got to know how to design a system.</p><p>I hope you understood about system design and the steps to follow while designing a system.</p><p>Please read my other blogs to gain a better understanding of the ideas discussed there.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=56b3ba71b63e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Develop an API using Spring, GraphQL and PostgreSQL]]></title>
            <link>https://medium.com/@pawanphanieswar/develop-an-api-using-spring-graphql-and-postgresql-15401e7d8658?source=rss-7aecce5ce941------2</link>
            <guid isPermaLink="false">https://medium.com/p/15401e7d8658</guid>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[graphql]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[postgresql]]></category>
            <dc:creator><![CDATA[Perla Pawan Phanieswar]]></dc:creator>
            <pubDate>Tue, 11 Mar 2025 17:09:08 GMT</pubDate>
            <atom:updated>2025-03-11T17:09:08.849Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/724/1*ppieUDUq_qIHLVLcUStV3w.png" /></figure><p>This blog is helpful and crisp to the point if you want to create an API with Spring, GraphQL, and PostgreSQL.</p><p>Firstly, let us learn about graphQL</p><h3>GraphQL — A Query Language for APIs</h3><p>The basic need of most applications is to fetch data from the backend, which could be a database, a third-party application, NFS, etc. API interface is written to facilitate this.</p><p>REST web services are one of the most popular architectures to expose data from the backend. Previously, this was the best fit because the development pace wasn’t as fast as it is today. We are all so comfortable with REST, so the question is, “Is GraphQL better than REST?”</p><p><strong>REST vs GraphQL</strong></p><ul><li><strong>Network Performance</strong>: When UI invokes a REST API, it will not have any control over the response data, whereas GraphQL provides a mechanism to specify the fields of interest in response. This reduces network overload by fetching the smallest data possible.</li><li><strong>Endpoint</strong>: In REST, each resource is identified by a URI. This makes the client obliged to know each endpoint. In GraphQL, all resources are identified by a single endpoint. There is no hassle of maintaining multiple URI’s.</li><li><strong>Data Fetching Strategy</strong>: In GraphQL, we have only one endpoint. The client sends a single query with the required fields. This helps with improved network performance and avoids the over-fetching/under-fetching data problem.</li></ul><h3>What Is GraphQL?</h3><p>GraphQL is a query language. It gives control to the user to query what he needs, thus reducing the payload on the network.</p><p>The main terms used most commonly in GraphQL are:</p><ul><li><strong>Schema: </strong>The contract between the GraphQL client and the GraphQL server</li><li><strong>Query: </strong>Similar to GET call in REST and used by the client to query the fields</li><li><strong>Mutations: </strong>It is similar to a POST/PUT call in REST and is used by the client for any insert/update operation</li></ul><p><strong>GRAPHQL Architecture</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*q1yh16LqGKEQhbBvuo7rGg.png" /></figure><h3><strong>GraphQL API Example:</strong></h3><h4>Request (GET request to fetch a book by ID):</h4><pre>{<br>  findProductById(id: 1) {<br>    name<br>    description<br>  }<br>}</pre><h4>Response :</h4><pre>{<br>  &quot;data&quot;: {<br>    &quot;findProductById&quot;: {<br>      &quot;name&quot;: &quot;Wireless Mouse&quot;,<br>      &quot;description&quot;: &quot;Ergonomic wireless mouse with long battery life&quot;<br>    }<br>  }<br>}</pre><h3>Discussion About Our Project</h3><p>Our project is a simple product management system that allows users to perform CRUD operations via GraphQL. We will use Spring Boot as the backend framework and PostgreSQL as the database</p><h3>Project Setup</h3><p>Include all these dependencies in your pom.xml file</p><pre>&lt;dependencies&gt;<br>    &lt;dependency&gt;<br>        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>        &lt;artifactId&gt;spring-boot-starter-web&lt;/artifactId&gt;<br>    &lt;/dependency&gt;<br><br>    &lt;dependency&gt;<br>        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>        &lt;artifactId&gt;spring-boot-starter-graphql&lt;/artifactId&gt;<br>    &lt;/dependency&gt;<br><br>    &lt;dependency&gt;<br>        &lt;groupId&gt;org.projectlombok&lt;/groupId&gt;<br>        &lt;artifactId&gt;lombok&lt;/artifactId&gt;<br>        &lt;scope&gt;provided&lt;/scope&gt;<br>    &lt;/dependency&gt;<br><br>    &lt;dependency&gt;<br>        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>        &lt;artifactId&gt;spring-boot-starter-data-jpa&lt;/artifactId&gt;<br>    &lt;/dependency&gt;<br><br>    &lt;dependency&gt;<br>        &lt;groupId&gt;org.postgresql&lt;/groupId&gt;<br>        &lt;artifactId&gt;postgresql&lt;/artifactId&gt;<br>        &lt;scope&gt;runtime&lt;/scope&gt;<br>    &lt;/dependency&gt;<br><br>    &lt;dependency&gt;<br>        &lt;groupId&gt;org.springframework.boot&lt;/groupId&gt;<br>        &lt;artifactId&gt;spring-boot-devtools&lt;/artifactId&gt;<br>        &lt;scope&gt;runtime&lt;/scope&gt;<br>        &lt;optional&gt;true&lt;/optional&gt;<br>    &lt;/dependency&gt;<br>&lt;/dependencies&gt;</pre><p><strong>application.properties file:</strong></p><pre>spring.application.name=spring-graphql-postgres-api<br><br>spring.datasource.driver-class-name=org.postgresql.Driver<br>spring.datasource.url=jdbc:postgresql://localhost:5432//my_db<br>spring.datasource.username=my_username<br>spring.datasource.username=my_password<br><br>spring.jpa.show-sql=true<br>spring.jpa.hibernate.ddl-auto=update<br>spring.jpa.properties.hibernate.format_sql=true<br><br>spring.graphql.graphiql.path=/grapql<br>spring.graphql.graphiql.enabled=true<br>spring.graphql.cors.allow-credentials=true<br>spring.graphql.cors.allowed-origins=*</pre><h3>Details about the GraphQL-specific Properties</h3><p>spring.graphql.graphiql.enabled: Enables GraphiQL UI for testing queries.</p><p>spring.graphql.cors.allow-credentials: Allows CORS credentials.</p><p>spring.graphql.cors.allowed-origins: Defines allowed origins for GraphQL API.</p><h3>Defining the GraphQL Schema</h3><p>Create a GraphQL schema file at src/main/resources/graphql/schema.graphqls:</p><pre>type Product {<br>    id: ID!<br>    name: String!<br>    description: String<br>    price: Float!<br>    quantity: Int!<br>}<br><br>input ProductInput {<br>    name: String!<br>    description: String<br>    price: Float!<br>    quantity: Int!<br>}<br><br>type Query {<br>    findAllProducts: [Product]!<br>    findProductById(id: ID!): Product<br>}<br><br>type Mutation {<br>    createProduct(productInput: ProductInput!): Product!<br>    updateProduct(id: ID!, productInput: ProductInput!): Product!<br>    deleteProduct(id: ID!): Boolean!<br>}</pre><h3>Implementing the Model</h3><p>Create the Product entity:</p><pre>import jakarta.persistence.Entity;<br>import jakarta.persistence.GeneratedValue;<br>import jakarta.persistence.GenerationType;<br>import jakarta.persistence.Id;<br>import lombok.AllArgsConstructor;<br>import lombok.Data;<br>import lombok.NoArgsConstructor;<br><br>@Entity<br>@AllArgsConstructor<br>@NoArgsConstructor<br>@Data<br>// you can add your DB table here using @Table annotation<br>public class Product {<br>    @Id<br>    @GeneratedValue(strategy = GenerationType.IDENTITY)<br>    private Long id;<br>    private String name;<br>    private String description;<br>    private Double price;<br>    private Integer quantity;<br>}</pre><h4>Explanation about the Model</h4><ul><li>Uses JPA annotations (@Entity, @Id, @GeneratedValue).</li><li>Uses Lombok annotations for boilerplate code reduction.</li></ul><h3>Creating the Repository</h3><p>Create the ProductRepository interface:</p><pre>package com.example.spring-graphql-postgres-api.Repository;<br><br>import org.springframework.data.jpa.repository.JpaRepository;<br>import com.example.spring-graphql-postgres-api.Entity.Product;<br><br>public interface ProductRepository extends JpaRepository&lt;Product, Long&gt; {<br>   // create your own methods if required<br>}</pre><h4>Explanation of the Repository</h4><ul><li>Extends JpaRepository to provide CRUD operations. Implementing the Service Layer</li></ul><h3>Implementing the Service Layer</h3><p>The ProductService encapsulates business logic for interacting with the repository:</p><pre>package com.example.spring-graphql-postgres-api.Service;<br><br>import com.example.spring-graphql-postgres-api.Entity.Product;<br>import com.example.spring-graphql-postgres-api.Repository.ProductRepository;<br>import org.springframework.stereotype.Service;<br><br>import java.util.*;<br><br>@Service<br>public class ProductService {<br>    @Autowired<br>    private final ProductRepository productRepository;<br><br>    public List&lt;Product&gt; getAllProducts() {<br>        return productRepository.findAll();<br>    }<br><br>    public Product getProductById(Long id) {<br>        return productRepository.findById(id).orElseThrow();<br>    }<br><br>    public Product save(Product product) {<br>        return productRepository.save(product);<br>    }<br><br>    public Product update(Long id, Product productDetails) {<br>        Product product = findById(id);<br>        product.setName(productDetails.getName());<br>        product.setDescription(productDetails.getDescription());<br>        product.setPrice(productDetails.getPrice());<br>        product.setQuantity(productDetails.getQuantity());<br>        return productRepository.save(product);<br>    }<br><br>    public void deleteById(Long id) {<br>        productRepository.deleteById(id);<br>    }<br>}</pre><h4>Explanation of the Services</h4><ul><li>Contains business logic for handling products.</li><li>Uses ProductRepository for database interactions.</li></ul><h3>Building the GraphQL Controller</h3><p>The ProductController maps <strong>GraphQL queries and mutations</strong> to service methods:</p><pre>package com.example.spring-graphql-postgres-api.Controller;<br><br>import com.example.spring-graphql-postgres-api.Entity.Product;<br>import com.example.spring-graphql-postgres-api.Service.ProductService;<br>import org.springframework.graphql.data.method.annotation.Argument;<br>import org.springframework.graphql.data.method.annotation.MutationMapping;<br>import org.springframework.graphql.data.method.annotation.QueryMapping;<br>import org.springframework.stereotype.Controller;<br><br>import java.util.List;<br><br>@Controller<br>public class ProductController {<br>    @Autowired<br>    private final ProductService productService;<br><br>    @QueryMapping<br>    public List&lt;Product&gt; findAllProducts() {<br>        return productService.getAllProducts();<br>    }<br><br>    @QueryMapping<br>    public Product findProductById(@Argument Long id) {<br>        return productService.getProductById(id);<br>    }<br><br>    @MutationMapping<br>    public Product createProduct(@Argument ProductInput productInput) {<br>        Product product = new Product();<br>        product.setName(productInput.name());<br>        product.setDescription(productInput.description());<br>        product.setPrice(productInput.price());<br>        product.setQuantity(productInput.quantity());<br>        return productService.save(product);<br>    }<br><br>    @MutationMapping<br>    public Product updateProduct(@Argument Long id, @Argument ProductInput productInput) {<br>        Product product = new Product();<br>        product.setName(productInput.name());<br>        product.setDescription(productInput.description());<br>        product.setPrice(productInput.price());<br>        product.setQuantity(productInput.quantity());<br>        return productService.update(id, product);<br>    }<br><br>    @MutationMapping<br>    public Boolean deleteProduct(@Argument Long id) {<br>        productService.deleteById(id);<br>        return true;<br>    }<br><br>    public record ProductInput(String name, String description, Double price, Integer quantity) {}<br>}</pre><h4>Details about the Controller</h4><ul><li>Uses @Controller to define GraphQL endpoints.</li><li>Uses @QueryMapping for queries.</li><li>Uses @MutationMapping for mutations.</li><li>Uses @Argument to extract input values.</li></ul><h3>Running the Application</h3><p>Start the Spring Boot application:</p><pre>mvn spring-boot:run</pre><h3>Testing GraphQL Queries and Mutations</h3><p>Go to <a href="http://localhost:8080/graphiql">http://localhost:8080/graphiql</a>or to POSTMAN with graphql type request. You will see a GraphQL Client to test the API we have created.</p><h4>1. Create a Product</h4><pre>mutation {<br>  createProduct(productInput: {name: &quot;New Smartphone&quot;, description: &quot;Latest model with advanced features&quot;, price: 699.99, quantity: 50}) {<br>    id<br>    name<br>    description<br>  }<br>}</pre><h4>2. Query All Products</h4><pre>{<br>  findAllProducts {<br>    id<br>    name<br>    description<br>    price<br>    quantity<br>  }<br>}</pre><h4>3. Query Product by ID</h4><pre>{<br>  findProductById(id: 1) {<br>    name<br>    description<br>    price<br>    quantity<br>  }<br>}</pre><h4>4. Update a Product</h4><pre>mutation {<br>  updateProduct(id: 1, productInput: {name: &quot;Updated Smartphone&quot;, description: &quot;Upgraded version with better features&quot;, price: 799.99, quantity: 30}) {<br>    id<br>    name<br>    description<br>  }<br>}</pre><h4>5. Delete a Product</h4><pre>mutation {<br>  deleteProduct(id: 1)<br>}</pre><p>I hope you understood this article that demonstrated how to build a GraphQL CRUD API with Spring Boot and PostgreSQL. GraphQL provides a flexible and efficient way to fetch data, reducing overfetching and underfetching issues commonly found in REST APIs.</p><p>For more blogs, please check out my profile.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=15401e7d8658" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring and Spring Boot]]></title>
            <link>https://medium.com/@pawanphanieswar/spring-and-spring-boot-5baf19dfa8fb?source=rss-7aecce5ce941------2</link>
            <guid isPermaLink="false">https://medium.com/p/5baf19dfa8fb</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Perla Pawan Phanieswar]]></dc:creator>
            <pubDate>Mon, 17 Feb 2025 17:53:20 GMT</pubDate>
            <atom:updated>2025-02-17T17:53:20.875Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4RjFkoh7Y8a_FTAo7aDDMQ.png" /><figcaption>Spring vs Spring Boot</figcaption></figure><p>People often confuse between spring and springboot. I am going to explain what they are in a very clear way. While I may not deep dive into their features, this blog will give you a high-level yet easiest way to understand what is spring and springboot.</p><p>Spring and Spring Boot are both part of the Spring ecosystem, but they serve different purposes and are used in different contexts.</p><p><strong>What is Spring?</strong></p><p>Spring is a collection of prewritten code that helps developers create Enterprise applications using Java. It supports developing robust, scalable, and maintainable applications. Spring is modular, meaning you can use only the parts of it that you need.</p><p>Spring does simplify many tasks, like:</p><ul><li>Creating web applications</li><li>Working with databases</li><li>Managing transactions, etc.</li></ul><p>But setting up a spring project can still involve quite a bit of manual configuration. This is where spring boot step in.</p><p><strong>What is Spring Boot?</strong></p><p>Spring Boot is a framework (set of tools) for building applications in Java. Spring Boot is an extension of the Spring framework designed to simplify the building of production-ready applications that you can just <strong>RUN</strong>. It is built on top of Spring and provides defaults and auto-configuration to reduce the need for manual setup.</p><p>The core spring framework already reduces boilerplate code and provides a lot of helpful features for devloping Java applications.</p><p>However, Spring Boot takes this convenience to the next level by focusing specifically on setting up and configuring a Spring application.</p><pre>/* Without Spring Boot, setting up a basic RESTful <br>   API requires manual configuration.<br>*/<br><br>import org.springframework.context.ApplicationContext;<br>import org.springframework.context.annotation.AnnotationConfigApplicationContext;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.RequestMapping;<br>import org.springframework.web.bind.annotation.RestController;<br><br>// Controller<br>@RestController<br>@RequestMapping(&quot;/api&quot;)<br>public class MyController {<br>    @GetMapping(&quot;/hello&quot;)<br>    public String sayHello() {<br>        return &quot;Hello from Spring!&quot;;<br>    }<br>}<br><br>// Application Main<br>public class SpringApp {<br>    public static void main(String[] args) {<br>        ApplicationContext context = new AnnotationConfigApplicationContext(MyController.class);<br>    }<br>}</pre><pre>// With Spring Boot, the setup process is greatly simplified.<br><br>import org.springframework.boot.SpringApplication;<br>import org.springframework.boot.autoconfigure.SpringBootApplication;<br>import org.springframework.web.bind.annotation.GetMapping;<br>import org.springframework.web.bind.annotation.RestController;<br><br>// Controller<br>@RestController<br>@SpringBootApplication<br>public class SpringBootApplicationExample {<br><br>    @GetMapping(&quot;/api/hello&quot;)<br>    public String sayHello() {<br>        return &quot;Hello from Spring Boot!&quot;;<br>    }<br><br>    public static void main(String[] args) {<br>        SpringApplication.run(SpringBootApplicationExample.class, args);<br>    }<br>}</pre><p>We use the @SpringBootApplication annotation in the main class, which replaces all the manual configuration setup in the traditional spring code.</p><p>We no longer need to explicitly create an application context using the “AnnotationConfigApplicationContext” as Spring Boot handles that behind the scenes.</p><p>We use SpringApplication.run() to start the application, and Spring Boot takes care of configuring the embedded web server and other necessary components.</p><p>The @SpringBootApplication annotation alone brings in a lot of preconfigured features, including automatic component scanning and<br>embedded server configuration (tom cat server), which would have required more steps in a traditional Spring setup.</p><p>I hope you understood the differences between Spring and Spring Boot.For more blogs, please check out my profile.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5baf19dfa8fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inner Classes in Java]]></title>
            <link>https://medium.com/@pawanphanieswar/inner-classes-in-java-9f162e123cdf?source=rss-7aecce5ce941------2</link>
            <guid isPermaLink="false">https://medium.com/p/9f162e123cdf</guid>
            <category><![CDATA[advanced-java]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[core-java]]></category>
            <category><![CDATA[inner-class]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Perla Pawan Phanieswar]]></dc:creator>
            <pubDate>Sun, 29 Dec 2024 17:52:11 GMT</pubDate>
            <atom:updated>2024-12-29T18:05:54.617Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*CLB2sZnZDIQ_2dDTjv9cag.jpeg" /></figure><p>Have you ever wondered whether you can access private variables and methods declared in another class that can still be used in a new class?</p><p>Yes, you can do that by using something called Inner Classes. In this blog, you will know everything about Inner Classes, their types, practical usage, and some important points about them.</p><h4>Inner Class</h4><p>Having a class inside a class is called an Inner class. Here is an example:</p><pre>public class OuterClass {<br>  // Example of Inner Class<br>  class InnerClass {<br>    <br>  }<br>}</pre><p>But these are not inner classes</p><pre>package com.java.InnerClasses;<br><br>public class Class1 {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;Class1&quot;);<br>    }<br>}<br><br>class Class2 {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;Class2&quot;);<br>    }<br><br>}<br><br>class Class3 {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;Class3&quot;);<br>    }<br>}</pre><p>If you execute the above program, the IDE will ask you which program it should run, and it will be like this, showing you different options.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4k63utnuWtmHLw0eeBtN2g.png" /></figure><p>Inner Classes have been introduced for better restriction of properties of a class and also to limit the scope of each attribute in the class. <br><strong><em>Also, by using Inner Classes, the inner class can access the private attributes of the Outer Class.</em></strong></p><p>All Inner Classes, must have unique names, and we can also add any number of Inner Classes for a class.</p><p>The naming convention of each Inner Class file in the bin folder will be<br><strong>“Outer_Class_Name$Inner_Class_Name”</strong>.</p><p>Also, for every Inner Class, in its .class file, we will have a Nest Host section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RehWqzb6zz5ISPAWNaRVrg.png" /><figcaption>Nest Host Section in the .class file</figcaption></figure><p>So basically, if you want to know whether a class is Inner Class or Outer Class, you can see its .class files, Nested Components. For Inner Class, it will have something called Nest Host, for Outer Class it will have something called Nested Memebers.</p><p>All the Inner Classes will have a default access modifier. But we can also give public, private, protected also. The classes can be declared static, abstract, or final. Each Inner Class should not have a main method.</p><pre>package com.java.InnerClasses;<br><br>public class Class1 {<br>    public static void main(String[] args) {<br>        System.out.println(&quot;Class1&quot;);<br>    }<br><br>    public class InnerClass1 {<br>     <br>    }<br>    <br>    private class InnerClass2 {<br>     <br>    }<br>    <br>    protected class InnerClass3 {<br>     <br>    }<br>    <br>    static class InnerClass4 {<br>     <br>    }<br>    <br>    abstract class InnerClass5 {<br>     <br>    }<br>    <br>    final class InnerClass6 {<br>     <br>    }<br>}</pre><p>Now that you understand what an Inner Class is, let me tell you about the different types of Inner Classes Java provides us. <br>There are 4 types of Inner Classes in Java, they are:</p><ol><li>Non-Static Inner Classes</li><li>Static Inner Classes</li><li>Local Inner Classes</li><li>Anonymous Inner Classes</li></ol><h3>Non-Static Inner Class</h3><p>It is a class defined inside another class but outside any method or constructor.</p><p>An example of it is:</p><pre>package com.java.InnerClasses;<br><br>// Accessing inner class code.<br><br>public class OuterClass {<br>    public static void main(String[] args) {<br>        // Way 1<br>        OuterClass.InnerClass innerClass = new OuterClass().new InnerClass();<br>        innerClass.display();<br>        // Way 2<br>        OuterClass outerClass = new OuterClass();<br>        InnerClass innerClass = outerClass.new InnerClass();<br>        innerClass.display();<br>        // Way 3<br>        new OuterClass().new InnerClass().display();<br>    }<br><br>    public class InnerClass {<br>        public void display() {<br>            System.out.println(&quot;InnerClass display method&quot;);<br>        }<br>    }<br>}</pre><p><strong>Key Characteristics of Non-static Inner Classes:</strong></p><ul><li>An instance of the outer class is linked to a non-static inner class. It has access to every member of the outer class, including private members.</li><li>To instantiate a non-static inner class, you need to first create an instance of the outer class. The inner class cannot exist on its own.</li><li>The non-static inner class has direct access to the instance variables and methods of the outer class, even private ones.</li><li>Within the inner class, this refers to the current inner class object.<br>Look at this example for better understanding</li></ul><pre>package com.java.InnerClasses;<br><br>public class OuterClass {<br> int number = 101;<br>    public static void main(String[] args) {<br>        OuterClass.InnerClass innerClass = new OuterClass().new InnerClass();<br>        innerClass.display();<br>    }<br><br>    public class InnerClass {<br>     int number = 102;<br>        public void display() {<br>            int number = 103;<br>            System.out.println(number); // outputs 103<br>            System.out.println(this.number); // outputs 102<br>            System.out.println(OuterClass.this.number); // outputs 101<br>        }<br>    }<br>}</pre><p>All Inner Classes can:</p><ul><li>Extend Non-Abstract Class</li></ul><pre>package com.java.InnerClasses;<br><br>public class OuterClass {<br>    public static void main(String[] args) {<br>        OuterClass.InnerClass innerClass = new OuterClass().new InnerClass();<br>        innerClass.display();<br>    }<br>    public class InnerClass extends NonAbstractClass {<br>        public void display() {<br>            System.out.println(&quot;Inner Class Display method&quot;);<br>            nonAbstractMethod();<br>        }<br>    }<br>}<br><br>class NonAbstractClass {<br>  public void nonAbstractMethod() {<br>    System.out.println(&quot;NonAbstract method&quot;);<br>  }<br>}</pre><ul><li>Extend Abstract Class by providing an implementation for all unimplemented methods.</li></ul><pre>package com.java.InnerClasses;<br><br>public class OuterClass {<br>    public static void main(String[] args) {<br>        OuterClass.InnerClass innerClass = new OuterClass().new InnerClass();<br>        innerClass.display();<br>    }<br>    public class InnerClass extends AbstractClass {<br>        public void display() {<br>            System.out.println(&quot;Inner Class Display method&quot;);<br>            <br>        }<br><br>      @Override<br>      public void unimplementedMethod() {<br>           // TODO Auto-generated method stub<br>           throw new UnsupportedOperationException(&quot;Unimplemented method &#39;unimplementedMethod&#39;&quot;);<br>        }<br>        <br>    }<br>}<br><br><br>public abstract class AbstractClass {<br>   public abstract void unimplementedMethod();<br>}</pre><ul><li>Implement an Interface by providing an implementation for all unimplemented methods.</li></ul><pre>package com.java.InnerClasses;<br><br>public class OuterClass {<br>    public static void main(String[] args) {<br>        OuterClass.InnerClass innerClass = new OuterClass().new InnerClass();<br>        innerClass.display();<br>    }<br>    public class InnerClass implements Interface {<br>        public void display() {<br>            System.out.println(&quot;Inner Class Display method&quot;);<br>        }<br><br>        @Override<br>        public void unImplementedMethod1() {<br>            // TODO Auto-generated method stub<br>            throw new UnsupportedOperationException(&quot;Unimplemented method &#39;unImplementedMethod1&#39;&quot;);<br>        }<br><br>        @Override<br>        public void unImplementedMethod2() {<br>            // TODO Auto-generated method stub<br>            throw new UnsupportedOperationException(&quot;Unimplemented method &#39;unImplementedMethod2&#39;&quot;);<br>        }<br><br>    }<br>}<br><br>interface Interface {<br>    void unImplementedMethod1();<br>    void unImplementedMethod2();<br>}</pre><ul><li>Extend other Inner Classes.</li></ul><pre>package com.java.InnerClasses;<br><br>public class OuterClass {<br>    public static void main(String[] args) {<br>        OuterClass.InnerClass1 innerClass = new OuterClass().new InnerClass1();<br>        innerClass.display();<br>    }<br>    public class InnerClass1 extends InnerClass2 {<br>        public void display() {<br>            System.out.println(&quot;Inner Class1 Display method&quot;);<br>            print();<br>            <br>        }<br>    }<br>    public class InnerClass2  {<br>        public void print() {<br>            System.out.println(&quot;Inner Class2 Print method&quot;);<br>            <br>        }  <br>    }<br>}</pre><h3>Static Inner Classes</h3><p>A <strong>static inner class</strong> (also known as a <strong>static nested class</strong>) is a class that is declared inside another class but is marked with the static keyword.</p><p>It can be accessed without an instance of the outer class, unlike regular inner classes.</p><h4>Key Features of Static Inner Classes:</h4><ol><li><strong>Independent of Outer Class Instances</strong>: Since it’s static, you don’t need an instance of the outer class to create an object of the static inner class.</li><li><strong>Cannot Access Non-static Members of Outer Class</strong>: A static inner class can only access the static members (variables and methods) of the outer class directly. It cannot access instance variables or methods without an object of the outer class.</li><li><strong>Useful for Utility Classes</strong>: Static inner classes are often used for helper or utility classes that are only relevant to the outer class.</li></ol><pre>package com.java.InnerClasses;<br><br>class OuterClass {<br>    private static String outerStaticVar = &quot;Outer Static Variable&quot;;<br>    private String outerInstanceVar = &quot;Outer Instance Variable&quot;;<br><br>    public static void main(String[] args) {<br>        OuterClass.StaticInnerClass inner = new OuterClass.StaticInnerClass();<br>        inner.display();<br>    }<br><br>    static class StaticInnerClass {<br>        void display() {<br>            System.out.println(&quot;Accessing outer static variable: &quot; + outerStaticVar);<br>            // System.out.println(outerInstanceVar); // This would cause a compilation error<br>        }<br>    }<br>}</pre><h3>Local Inner Classes</h3><p>A <strong>Local Inner Class</strong> is a class declared within a block, inside a method, constructor, or even an initialization block. Because of its scope, a local inner class is not accessible outside the block in which it is declared. It’s a way to encapsulate functionalities that are needed only within a specific method or block, keeping the code more organised and less exposed.</p><p>Only abstract, final keywords can be used for these classes. These local classes can’t have static methods. Local Inner Class objects can be created only in the block of code where you declare them.</p><p>The Local Inner Class can possess accessibility to every variable and method outside the class scope and also has access to private properties of the Outer Class. But the Outer Class can’t access anything that is created inside the Local Inner Class.</p><pre>package com.java.InnerClasses;<br><br>public class OuterClass {<br><br>   int number = 101;<br>   static int number1 = 102;<br>   private static String name = &quot;John&quot;;<br><br>    public static void main(String[] args) {<br><br>     class InnerClass {<br>      public void display() {<br>         System.out.println(&quot;Display Method&quot;);<br>         // System.out.print(number); // can&#39;t make static reference<br>         System.out.println(number1);<br>         System.out.println(name);<br>        }<br>     }<br><br>     InnerClass innerClass = new InnerClass();<br>     innerClass.display();<br><br>    }<br>    <br>    public void method() {<br>     // throws error<br>     // InnerClass innerClass = new InnerClass();<br>    }<br>}</pre><h3>Anonymous Inner Classes</h3><p><strong>Anonymous Inner Class</strong> is a type of local inner class without a name. It is used to instantiate objects of classes or interfaces with slight changes or custom behaviour, especially when a full class declaration is not necessary. Anonymous inner classes are often used when implementing interfaces or abstract classes, especially in cases where the implementation is needed in only one place.</p><p>Anonymous Classes naming convention in bin folder will be like.<br>Outer_Class_Name&amp;1.class</p><p>They are used to override any method of a class without extending. And to implement unimplemented methods of Abstract classes and Interfaces.<br>We will not create an object for abstract classes or interfaces, but using anonymous classes, we can create an object for them with the type of that interface/abstract class name.</p><p>Example of an Anonymous Inner Class</p><pre>package com.java.InnerClasses;<br><br>public class OuterClass {<br>    public static void main(String[] args) {<br>       ClassA classA = new ClassA() {<br>          public void display() {<br>             System.out.println(&quot;Updated Display Method&quot;);<br>          }<br>       };<br>       classA.display();<br>    }<br>    <br>}<br><br>class ClassA {<br>   public void display() {<br>      System.out.println(&quot;Display Method&quot;);<br>   }<br>}</pre><p>Thanks for reading this blog. I hope you have understood about Java Inner Classes.</p><p>Check out my other blogs for some more advanced concepts in Java and to get a deep understanding of them.<br><a href="https://medium.com/@pawanphanieswar">https://medium.com/@pawanphanieswar</a></p><p>Happy Learning!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9f162e123cdf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The POJO class and the Java Bean class]]></title>
            <link>https://medium.com/@pawanphanieswar/the-pojo-class-and-the-java-bean-class-0d586212a86f?source=rss-7aecce5ce941------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d586212a86f</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[javabean]]></category>
            <category><![CDATA[pojo]]></category>
            <category><![CDATA[advanced-java]]></category>
            <dc:creator><![CDATA[Perla Pawan Phanieswar]]></dc:creator>
            <pubDate>Fri, 27 Dec 2024 06:42:36 GMT</pubDate>
            <atom:updated>2024-12-27T06:55:44.139Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/422/1*8z5znNKfvezaEu5hcLa6eA.png" /><figcaption>POJO and Java Bean classes of Java</figcaption></figure><p>In this blog, you will know everything about POJO class and Java BEAN class, with examples and rules along with their differences.</p><h3>POJO</h3><p>POJO stands for Plain Old Java Object.<br>It is a simple object that is not bound by any special restriction. POJO class doesn’t follow any special conventions or frameworks.</p><p>It’s used to represent data as an object with fields, constructors, and getter/setter methods but without any heavy frameworks or design patterns.</p><h4>Rules for a class to be a POJO class :</h4><ol><li>The class must have a “public” access modifier.</li><li>It should not implement any interface.</li><li>It should not follow Inheritance i.e., it should not extend any class.</li><li>The class should not have any annotations specified like @Override,@Entity, @Service</li><li>Java recommends making the properties of the class declared private, but not mandatory, for improved security.</li><li>If declared private, the properties must have getters and setters.</li></ol><p>We need not declare a main method also for a POJO class.</p><h4>Example of a POJO class</h4><pre>package com.java.pojoJavaBean;<br><br>public class Employee {<br>    private int id;<br>    public String name;<br>    protected double salary;<br><br>    public Employee() {<br>        System.out.println(&quot;No-arg constructor&quot;); <br>    }<br><br>    public Employee(int id) {<br>        this.id = id;<br>    }<br><br>    public void setId(int id) {<br>        this.id = id;<br>    }<br><br>    public int getId() {<br>        return id;<br>    }<br>}</pre><p>POJO classes are frequently utilised in situations such as entity classes, data transfer objects (DTOs), and more because they offer a clear, straightforward method of representing data in Java applications.</p><pre>package com.java.pojoJavaBean;<br><br>// We can use the Employee POJO class to create a user defined Datatype Employee<br><br>public class Main {<br>    public static void main(String[] args) {<br><br>        // Object of Employee is called a POJO<br><br>        Employee employee1 = new Employee();<br>        employee1.setId(101);<br>        employee1.name = &quot;John&quot;;<br>        employee1.salary = 1000.0;<br><br>        Employee employee2 = new Employee(102);<br>        employee2.name = &quot;Smith&quot;;<br>        employee2.salary = 2000.0;<br><br>        Employee employee3 = new Employee();<br>        employee3.setId(103);<br>        employee3.name = &quot;Peter&quot;;<br>        employee3.salary = 3000.0;<br><br>        Employee[] employees = new Employee[] { employee1, employee2, employee3 };<br><br>    }<br>}</pre><h3>Java Bean</h3><p>It is an extended version of the POJO class and is often referred to as the Serializable POJO class.</p><p>A Java Bean is a unique kind of Java class that follows certain guidelines and is frequently used to encapsulate data in Java applications.</p><p>Java Beans can be easily instantiated using the <strong>Class.newInstance()</strong> method.</p><h4>Rules for a class to be a Java Bean class :</h4><ol><li>It should implement a Serializable interface.</li><li>It should have a no-args constructor.</li><li>All instance variables should be declared private and have getters and setters.</li></ol><p>Example of Java Bean class:</p><pre>package com.java.pojoJavaBean;<br><br>import java.io.Serializable;<br><br>public class Student implements Serializable {<br><br>    // Object of Student is called Java Bean.<br><br>    private int id;<br>    private String name;<br>    private String name;<br><br>    public int getId() {<br>        return id;<br>    }<br><br>    public void setId(int id) {<br>        this.id = id;<br>    }<br><br>    public String getName() {<br>        return name;<br>    }<br><br>    public void setName(String name) {<br>        this.name = name;<br>    }<br><br>    public double getMarks() {<br>        return marks;<br>    }<br><br>    public void setMarks(double marks) {<br>        this.marks = marks;<br>    }<br><br>    public Student() {<br>        System.out.println(&quot;No-arg constructor&quot;);<br>    }<br>}</pre><p>The process of serialisation transforms an object into a stream of bytes that can be sent over a network or written to a file, making it simple to store, retrieve, and recreate. <br>It produces a byte stream of the object, which can be sent from one JVM to another with ease. The other JVM can then use the byte stream to easily recreate the object.</p><h4>Advantages of Java Beans</h4><ol><li><strong>Reusability</strong> of the code across applications.</li><li><strong>Framework Compatibility</strong>: Many Java frameworks (like Spring or JSP) rely on the Java Beans convention to manage objects.</li><li><strong>Manipulability</strong>: Java Beans can be manipulated in various development tools, providing setting and getting of object properties.</li></ol><h3>Difference between POJO and Java Bean:</h3><p>While both <strong>POJO</strong> and <strong>Java Bean</strong> are simple Java classes, Java Beans follow stricter conventions, such as implementing Serializable and having getter/setter methods. A POJO doesn’t necessarily need to follow these rules.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d586212a86f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java Architecture & JVM Internals]]></title>
            <link>https://medium.com/@pawanphanieswar/java-architecture-jvm-internals-e6a02187bf69?source=rss-7aecce5ce941------2</link>
            <guid isPermaLink="false">https://medium.com/p/e6a02187bf69</guid>
            <category><![CDATA[java-architecture]]></category>
            <category><![CDATA[jre]]></category>
            <category><![CDATA[jvm]]></category>
            <category><![CDATA[jdk]]></category>
            <category><![CDATA[core-java]]></category>
            <dc:creator><![CDATA[Perla Pawan Phanieswar]]></dc:creator>
            <pubDate>Wed, 25 Dec 2024 11:38:40 GMT</pubDate>
            <atom:updated>2024-12-25T12:04:24.271Z</atom:updated>
            <content:encoded><![CDATA[<p>In this blog, you will know everything about Java architecture and JVM internals. To be an equipped Java programmer, one must know the internal mechanisms of Java.<br>This blog gives a brief understanding of Java internal structures and how JVM works.</p><h3>Java Architecture</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/665/0*D26YS9W7mgpJ-Kbn.png" /><figcaption>Overview of Java Architecture</figcaption></figure><p>The Java architecture has mainly 3 components.<br>1. JDK<br>2. JRE<br>3. JVM</p><p>Let us now understand all these 3 components.</p><h3>JDK</h3><p>JDK stands for Java Development Kit.<br>It is an important toolset for Java developers, providing everything you need to develop and run Java applications.<br>It contains JRE (Java Runtime Environment), which we will be discussing in a bit, along with development tools such as compilers and debuggers.</p><p>Some of the development tools are:</p><ul><li><strong>javac</strong>: The Java compiler, which converts Java source code into bytecode that runs on the JVM. To change .java file to .class file, we need javac.</li><li><strong>java</strong>: The launcher that runs Java applications.</li><li><strong>jdb</strong>: Java debugger for finding issues at runtime.</li><li><strong>javadoc</strong>: A tool to generate API documentation from Java source code comments.</li><li><strong>jar</strong>: Tool for packaging Java files into JAR (Java ARchive) format.</li></ul><p>The below image shows all the development tools provided by the JDK.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x8nalD115Dwb1hri8fUABA.png" /><figcaption>All the development files are present in jdk/bin folder</figcaption></figure><p>Until Java 1.8, we can install both JDK and JRE separately on our systems. But, after 1.8, when we install JDK, JRE is automatically installed.</p><h3>JRE</h3><p>JRE stands for Java Runtime Environment.<br>It is the component of the Java platform that makes it possible to run Java programmes.<br>It provides the necessary libraries, the Java Virtual Machine (JVM), which we will be discussing in detail, and other components required to execute Java programs that are already compiled (i.e., converted to bytecode).</p><ul><li>The JRE comes with essential libraries and APIs that Java programs use, including classes for I/O, networking, utilities, collections, and more.</li><li>In JRE/lib we have rt.jar file which is of 62 MB and has all the libraries which we use most commonly in our java applications.</li></ul><p>The JRE provides the runtime environment needed for running java files.<br>It abstracts the complexities of the operating system. By this, the famous saying that Java is platform-independent is achieved.</p><h3>JVM</h3><p>JVM stands for Java Virtual Machine. Now, we will discuss the architecture of JVM, the various components involved, and their roles.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*bW8b4BpNh8L8HiR3.jpg" /><figcaption>Complete JVM Architecture</figcaption></figure><p>Components of JVM are:</p><ol><li>Class loader Subsystem</li><li>Runtime Data Areas</li><li>Execution Engine</li><li>Native Method Interface (JNI)</li><li>Native Method Library</li></ol><h4>Class Loader Subsystem</h4><p>Everything in the classloader subsystems extends “<strong>java.lang.ClassLoader”</strong></p><p>There are 3 main functionalities in the Class loader Subsystem.</p><ol><li>Loading</li><li>Linking</li><li>Initialization</li></ol><h4><strong>Loading</strong></h4><p>It makes all the required .class files present in our JRE/lib/rt.jar to be loaded into the RAM at the instance of running a java file.</p><p>Loading is hierarchical, and classes are lazily loaded when they are referenced for the first time. Loading generates corresponding binary data and is stored in the Method Area<strong> </strong>of the Runtime Data Areas.</p><p>Classloading begins with the program’s Main Class, and additional class loading attempts are made using the following situations:</p><ol><li>The bytecode of the class makes any static references to a class (Ex: System.out.print, System.out.println, System.err.printf, etc)</li><li>The bytecode creates an instance of an other class (Ex: ClassA obj = new ClassA();)</li><li>Any other utility classes that are used in the program are loaded.</li><li>When the class is referenced using the Reflection API.</li></ol><p><strong>Types of Class Loaders:</strong></p><p>There are 3 different types of Classloaders.</p><ol><li><strong>Bootstrap Classloader: </strong>It loads all the JDK classes from <strong>rt.jar </strong>in the bootstrap classpath. The jar includes classes to support the runtime, such as java.lang, applets, java.util, java.io, java.net etc. Basically, all these are written in C/C++ language.</li><li><strong>Extension Classloader: </strong>It loads .jarfiles present in the core Java extensions from the JDK extension library present in the “jre/lib/ext” folder, such as locales, security providers, nashom, meta-index, and other libraries. These can also include libraries present in the directories specified by the environment variable “java.ext.dirs”.<br>Also, some operating system-specific JRE files are also loaded by Extension Classloader.</li><li><strong>Application Classloader: </strong>It loads other non-java providing files that are used in our java projects. Those may include any APACHE POI files, excel files, XSSF Sheet, etc. Also, if working with Selenium, this classloader loads all standalone Selenium libraries for our java project.</li></ol><h4>Linking</h4><p>Verifying previously loaded classes, interfaces, parent classes, and interfaces after the loading phase is known as Linking.<br>The process of <strong>Linking</strong> goes through three phases:</p><ol><li><strong>Verify: </strong>In this step, <strong>Verifier</strong> checks if the bytecode is generated by a valid compiler and follows compatibility rules. Some of the checks performed by Verifier include ensuring variables are initialised before usage, ensuring final classes are not sub-classed, and ensuring final methods are not overridden.Ensure methods and classes respect access rules and methods are invoked with the correct number and type of parameters and return values. Variables and classes are assigned and initialised with values of the correct type.<br>This is used to provide security and prevent malware in java files. We can read the bytecode of our program by using <strong><em>“ javap -v Main.class”</em></strong>.<br>If any of these checks are violated, the Linker throws a <strong>VerifyError</strong> exception, and the entire process comes to a halt.</li><li><strong>Prepare: </strong>This<strong> </strong>phase is executed post the <strong>Verify</strong> phase that allocates memory and initialises static<strong> </strong>fields of the class to their default values.<br>Assigned values will be given in the stage of intilization.</li><li><strong>Resolve: </strong>It is used to change the symbolic references in our bytecode to method references and store them in the runtime constant pool in the method area.</li></ol><h4>Initialization</h4><p>This stage involves running the initialisation logic for every class, which sets all static variables to their assigned values and runs the static block for every class.</p><h3>Runtime Data Areas</h3><p>I have written a comprehensive blog covering every detail about the runtime data area.<br>You can read that blog by using this link : <a href="https://medium.com/@pawanphanishwar/java-memory-management-d524e70f5137">https://medium.com/@pawanphanishwar/java-memory-management-d524e70f5137</a></p><h3>Execution Engine</h3><p>The <strong>Execution Engine</strong> is where the bytecodes are executed using an Interpreter or JIT Compiler using the data stored in <strong>Runtime Data Area</strong>.</p><p>The <strong>Execution Engine</strong> is composed of three main components: <strong>Interpreter</strong>, <strong>JIT Compiler</strong> and <strong>Garbage Collector</strong>.</p><h3>Interpreter</h3><p>The <strong>Interpreter</strong> reads the bytecode generated by Java Compiler and executes the instruction set (opcode) line by line.</p><p>Before executing the instructions, a sequence of steps are carried out as mentioned below.</p><ol><li>Types are loaded on-demand using <strong>ClassLoader Subsystem</strong> storing metadata in <strong>Method Area</strong> and binary data on <strong>Heap</strong>.</li><li>Types are dynamically linked using the <strong>Linking</strong> module verifying the bytecodes and resolving symbolic references.</li><li>Classes are initialized with static variables and static blocks.</li></ol><p>Once these steps are executed, the opcode is ready to be executed line by line. The major shortcoming of interpreting every instruction is that when a method is called multiple times, interpretation is required every time, resulting in slower execution.</p><h3>(Just in Time) JIT Compiler</h3><p><strong>JIT Compiler</strong> solves the shortcomings of the Interpreter by compiling the frequently executed instructions from bytecode into native code and executing the native code thereby improving the performance.</p><p>JIT Compiler performs various optimizations to improve the performance of the execution.</p><ol><li><strong>Inlining </strong>is the process by which smaller methods are merged and inlined in the caller method thereby reducing the call graph, branching of methods, and stack allocation.</li><li>Various <strong>local optimizations </strong>are performed such as tail recursion elimination into the iterative process, simplification of statements, replacing variables with literals to reduce lookups, etc.</li><li><strong>Control flow optimizations </strong>by rearranging code paths to improve efficiencies such as Loop reduction, Loop unwrapping, branching reduction, etc.</li></ol><p><strong>JIT Compiler</strong> analyses the <strong>hotspots,</strong> i.e., the instructions that are frequently executed, and adds them to the eligible instructions to be compiled by JIT Compiler.</p><p><strong>JIT Compiler </strong>includes the following components:</p><ol><li><strong>Intermediate Code Generator </strong>producing intermediate code</li><li><strong>Code Optimizer </strong>for optimizing the intermediate code generated.</li><li><strong>Profiler </strong>for analyzing hotspots based on frequently executing instructions with their thresholds. This data is stored in <strong>Code Cache </strong>for subsequent analysis.</li><li><strong>Target Code Generator </strong>for generating the target binary code and storing them in the <strong>Code Cache</strong>.</li></ol><p><strong>Garbage Collection: </strong>Used objects will be collected here. A brief process of how it will be collected and all I will be writing a new blog for it!</p><h3>Java Native Interface (JNI)</h3><p>JNI is used to connect with Native Method Libraries (typically written in other programming languages such as C/C++) necessary for the execution and to provide the features of such Native Libraries.</p><p>This allows JVM to call C/C++ libraries and be called by C/C++ libraries that are hardware-specific.</p><p>I hope you have understood everything about Java architecture and JVM internals.<br>Thanks for reading. Happy Learning.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e6a02187bf69" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JAVA MEMORY MANAGEMENT]]></title>
            <link>https://medium.com/@pawanphanieswar/java-memory-management-d524e70f5137?source=rss-7aecce5ce941------2</link>
            <guid isPermaLink="false">https://medium.com/p/d524e70f5137</guid>
            <category><![CDATA[core-java]]></category>
            <category><![CDATA[memory-management]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[advanced-java]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Perla Pawan Phanieswar]]></dc:creator>
            <pubDate>Mon, 23 Dec 2024 19:21:21 GMT</pubDate>
            <atom:updated>2024-12-23T19:34:05.967Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pll_KOGQZ6DHOS7TQtohyw.png" /></figure><p>In this blog, you will know everything about memory management in Java.</p><p>But, before starting, what is actually memory management?</p><p>Well, it literally means managing the memory. Allocating and delocating the memory in RAM is called memory management. Basically, the JVM takes care of all the allocations and dealocations.<br>The operating system allocates some amount of memory in RAM to the JVM, and the amount typically is based on several factors, such as the system&#39;s available RAM and the JVM’s configuration settings, which we will talk about a bit later.</p><p>To perform all tasks efficiently, JVM uses 3 different runtime data areas.<br>1. Heap Area<br>2. Stack Area<br>3. Perm Gen/Meta Space<br>These areas perform different functionalities of memory management.</p><p>For understanding memory management in a better way, let us take a code snippet and map what comes under what.</p><pre>package MemoryManagement;<br><br>public class Employee {<br><br>    int organizationId = 101;<br>    String organizationName = &quot;ABC&quot;;<br>    String ceoName = &quot;John&quot;;<br>    int departments = 2;<br>    static double netWorth = 500.00;<br><br>    public static void main(String[] args) {<br>        int employeeId = 9164;<br>        String employeeName = &quot;Stuart&quot;;<br>        double salary = 5000.00;<br><br>        Employee employee1 = new Employee();<br>        employee1.getOrganizationId();<br>        System.out.println(Employee.getNetWorth());<br><br>        Employee employee2 = new Employee();<br>        employee2.deleteEmployee(employeeId);<br><br>    }<br><br>    public int getOrganizationId() {<br>        return organizationId;<br>    }<br><br>    public void deleteEmployee(int employeeId) {<br>        // delete employee code<br>    }<br><br>    public static double getNetWorth() {<br>        return netWorth;<br>    }<br>}</pre><h4>HEAP AREA</h4><p>It is responsible for dynamically allocating and managing objects during program execution. JVM allocates a fixed amount of memory to the heap, which is typically around 768 MB, which can be adjusted using configuration settings.</p><p>It is used to store all kinds of objects that we use in our programme, including arrays, collections, and instances of the class.<br>Heap Area also stores String pool where all the String literals are maintained.</p><p>The performance of the Heap area is less. Sometimes, it is also termed the ROM of JVM.</p><p>When a new keyword is used, an object is assigned a space in the heap, but the reference to the same exists on the stack.<em> <br></em>Usually, the kind of exceptions that we face when heap memory is full is</p><pre>java.lang.OutOfMemoryError</pre><p><strong><em>Garbage collection in the heap area is mandatory.</em></strong></p><p>In our example code, let&#39;s look at how the data is stored in the heap area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WxCoknLd2GbAOLJ_WSX7Dw.jpeg" /></figure><h4>STACK AREA</h4><p>JVM allocates a fixed amount of memory to the heap, which is typically around 1 MB, which can be adjusted using configuration settings.</p><p>Method call frames and local variables are managed in stack memory. Every time a method is called, a new frame with method-specific information such as parameters, return addresses, and local variables is pushed onto the stack.<br>Primitive data types and object references—not the actual objects themselves—are stored in the stack.<br>Data on the stack has a brief lifespan that is dependent on how the method is executed. The frame of the method is removed from the stack upon completion, and the associated data is automatically deallocated.</p><p>Usually, the kind of exceptions that we face when Stack memory is full is</p><pre>java.lang.StackOverFlowError</pre><p>The number of stacks formed in the Stack Area depends on the number of threads running in the programme at the given point in time.<br>The number of stacks = The number of threads running.<br>In our case, only one thread is running, as at the start of execution of the programme, only one thread is created.</p><p>The performance of the Stack area is high when compared to the Heap area. Sometimes, it is also termed RAM of JVM.</p><p>In our example code, let’s look at how the data is stored in the stack area.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f1-pkSVqltjRnNC1wfv7aQ.jpeg" /></figure><h4>PERMGEN/METASPACE</h4><p>Before Java 1.8, this PERMGEN used to be present in the heap area as a subpart. After 1.8, it was separated as a different area and was named METASPACE.</p><p>It is used to store all the static methods, static variables, and static blocks, along with method areas and class structures. If we use inner classes or declare any other class for usage in the main programme, all the structures of the class will be stored in the METASPACE.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*suGSqWJWuik6o8w4mm62ag.jpeg" /></figure><h4>CONFIGURATION SETTINGS</h4><p>To increase the heap memory size, you can go to configurations of the program if you are using Eclipse.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZREq-0dPXhGHGIhN98h8Q.png" /></figure><p>Go to the arguments and add -<strong><em>Xmx800m </em></strong>in the VM arguments section, and click run. This increases the heap area size to 800 MB. If you want even more, add the required number in the command followed by <strong><em>m.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1x7-JeKDtvghYdHvK_E3vQ.png" /></figure><p>To increase the stack memory size, you can go to configurations and in Arguments, add <strong><em>-Xss2m </em></strong>in the VM aruments, and click run. This increases the stack area size to 2 MB. If you want more stack space for your application or you feel there is a lot of recursion in your code, you can increase the size up to how much you might need.<br>You can use the following command: -<strong><em>Xss5m<br></em></strong>If you want even more, add the required number in the command followed by <strong><em>m.</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jrJ25r2aBIweXYgUFn6aNg.png" /></figure><p>Thanks for reading this blog. I hope you have understood the memory management in Java.</p><p>References :<br><a href="https://sematext.com/glossary/jvm-heap/">https://sematext.com/glossary/jvm-heap/</a><br><a href="https://www.geeksforgeeks.org/java-virtual-machine-jvm-stack-area/">https://www.geeksforgeeks.org/java-virtual-machine-jvm-stack-area/</a><br><a href="https://www.javatpoint.com/memory-management-in-java">https://www.javatpoint.com/memory-management-in-java</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d524e70f5137" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[My Verizon Interview Experience]]></title>
            <link>https://medium.com/@pawanphanieswar/my-verizon-interview-experience-916cb8fce996?source=rss-7aecce5ce941------2</link>
            <guid isPermaLink="false">https://medium.com/p/916cb8fce996</guid>
            <category><![CDATA[success-story]]></category>
            <category><![CDATA[interview-tips]]></category>
            <category><![CDATA[interview-experience]]></category>
            <category><![CDATA[verizon]]></category>
            <category><![CDATA[campus-placements]]></category>
            <dc:creator><![CDATA[Perla Pawan Phanieswar]]></dc:creator>
            <pubDate>Sun, 17 Nov 2024 05:29:14 GMT</pubDate>
            <atom:updated>2024-11-17T16:15:47.802Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/848/1*2aSNiFCAs8Mgf8WSKweq8Q.png" /></figure><p>Hey all, My name is Pawan Phanieswar, and I recently got placed in Verizon India as a Software Development Engineer (SDE). In this blog, I am going to share my interview experience at Verizon along with few tips to crack on campus interviews.</p><p><strong>Campus Drive :</strong></p><p>Verizon has visited our campus on September 4, 2024. The cutoff percentages for applying to this company were 70% in both X and XII and a GPA of 7.0 in the currently pursuing degree.</p><p>Though the GPA cutoff for the company is 7 GPA, the shortlisting for the online assessment round happened only for people who have a GPA above 9. <strong>So I strongly recommend students who are aiming for high-paying on-campus placements to have a GPA of above 9 (my suggestion is 9.2+) along with their skills and communication.</strong></p><p><strong>Online Assessment Round:</strong></p><p>The online assessment round happened on September 4, 2024. This assessment consisted of 4 sections.</p><p><strong>Section 1: Technical Writing</strong></p><p>This section consisted of writing about a topic that was given in 300–320 words. My suggestion is to write about the topic in a clear way, including punctuation and without grammatical errors. Use good vocabulary and highlight the main things about the topic.</p><p><strong>Section 2: Coding</strong></p><p>In this section, we were given 2 coding questions</p><p>The questions were based on strings and arrays, and the difficulty level of these questions was easy to medium. For those who have strong DSA skills, the questions are very easy, but for those who have little to no knowledge about DSA, the questions can be of medium difficulty.</p><p><strong>Section 3: Verbal Reasoning</strong></p><p>Here, all the questions were MCQ-based and mainly from the topics antonyms and synonyms, along with spot the error and correct the sentences. A few questions were based on choosing the correct spelling of the given word.<br>This round was easy, and a little concentration on the questions can do the work.</p><p><strong>Section 4: Game-Based Section</strong></p><p>Yes, this section was a game, and we need to play it. Sorry, I couldn&#39;t remember the game, but I would say to read the instructions clearly and understand about the game. You will have an ample amount of time to understand the game, and a visual representation of the game is also there to know how to play. Be careful while answering, and also, it is time-based. Those who solved more questions accurately got selected for next round.</p><p><strong>GD round:</strong></p><p>After the online assessment, all the shortlisted students were informed on September 6, 2024, that the next round was GD. The GD and all the next rounds happened on September 9, 2024.<br>The students were separated into groups, and each group had its own GD topic.<br>My suggestion for this round is to speak confidently and don’t repeat the same points. Include new points and try to speak about it with a scenario.<br>I know a typical GD has students who eagerly wait to tell their points, and everyone will try to grab the opportunity to speak. I advise you to take advantage of the opportunity to make your points as soon as possible. Try to speak at least 3–4 valid good points, and that can make you qualify for the next rounds.</p><p><strong>Technical Round:</strong></p><p>After the GD, on the same day we got the shortlist for the next round. The next round is a technical interview.</p><p>The interview started with a blowing question. The interviewer asked me to tell me about myself that is not there in my resume! I was blown away but took a few moments and answered that question. I included my hobbies and interests. The interview asked me a few questions on my interests too, and I replied with my thoughts and mentioned a few scenarios and facts. Then we moved to the technical part.</p><p>He asked about the internship that I have done and asked me to explain the project that I have done in my internship. After telling him about it, he started dwelling deep into my project. So many questions were asked on my project, and also a few scenario-based questions were added, and he asked me how my project would handle them. I answered them clearly and in a professional way.</p><p>Next, he went on to ask about my projects. He asked about two of my projects, and the same had happened. He went deep into my projects and asked a bunch of questions on the project and also asked questions on the technology stack that I used in the project. If you have good knowledge of your skills and can answer any question on your projects, it will be the deciding factor.</p><p>He then asked me two coding questions and asked me to type it on Notepad. The questions were easy. He has given me an array and asked me to check whether the array is sorted or not. It is not sorted, so he asked me to sort the array using insertion sort and asked me to explain about the sorting algorithm. The next question was also easy, and it was on arrays too.</p><p>Then, he asked about my aspirations and how a leader should be (this is because I have mentioned in my resume that I led a team in doing a project). He also asked me what was the biggest challenge I faced while doing my projects.</p><p>The interview happened for 40 minutes. The questions that were asked on my projects were a bit tough and needed good knowledge about the tech stacks used. Other than that, the interview was smooth and easy.</p><p><strong>HR round:</strong></p><p>After the technical round, I was shortlisted for the HR round. The HR round happened for only 10 minutes. He asked me to introduce myself—this time a normal introduction!!. He asked about my family background and some typical HR questions, like are you willing to relocate, and also asked me what you know about Verizon. I prepared for that question before going to the interview and answered it well. I mentioned the company in a nutshell below, and it could help you.</p><p>After the HR round, the verdict was I got selected!!<br>7 students from our college got selected.</p><p><strong>About Verizon:</strong></p><p><strong>Verizon Communications Inc.</strong> is an American telecommunications company headquartered in New York City, United States. It is the world’s second-largest telecommunications company by revenue, and its mobile network is the largest wireless carrier in the United States as of September 30, 2024. Founded in 2000, Verizon has played a pivotal role in revolutionising connectivity through its wireless, fibre-optic, and 5G technologies. The company is also a key player in digital transformation, offering enterprise solutions, IoT services, and cybersecurity innovations. Hans Vestberg has been the Chairman and CEO of Verizon since <strong>August 2018</strong>. Under his leadership, Verizon has been at the forefront of deploying <strong>5G technology</strong>, transforming connectivity for consumers and businesses worldwide.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=916cb8fce996" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[try-with-resources in Java]]></title>
            <link>https://medium.com/@pawanphanieswar/try-with-resources-in-java-7e2e112f4591?source=rss-7aecce5ce941------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e2e112f4591</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[core-java]]></category>
            <category><![CDATA[exception-handling]]></category>
            <category><![CDATA[programming-languages]]></category>
            <category><![CDATA[programming-tips]]></category>
            <dc:creator><![CDATA[Perla Pawan Phanieswar]]></dc:creator>
            <pubDate>Mon, 07 Oct 2024 08:45:00 GMT</pubDate>
            <atom:updated>2024-10-07T08:45:00.486Z</atom:updated>
            <content:encoded><![CDATA[<p>Do you forget to close your scanner object every time while writing Java code?<br>Although your IDE will warn you about it... Do you know that Java can automatically provide the close() methods even if you don’t write?</p><p>The try-with-resources statement is a feature introduced in Java 7 that allows you to manage resources more efficiently by automatically closing them after they are no longer needed.Typically, the closing of objects is necessary to avoid memory leaks or resource exhaustion and for security.</p><p>Syntax :</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/790/1*Ay9H_8xxKu9qFDe2riYOPg.png" /></figure><p>The resources declared within the parentheses in the try block are automatically closed at the end of the block, even if an exception occurs.</p><p>The resources used in try-with-resources must implement the AutoCloseable interface, which has a close() method. Only then, when the try block is finished, the close() method is automatically invoked on each resource.</p><p>Here is an example...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JqJoQjw_GK2F7fnY1Iwh-Q.png" /></figure><p>There is an obvious warning telling you to close the scanner item.Now we need to close the scanner object (sc here) by writing the code sc.close()</p><p>But if you enclose the scanner instance in a try block using the try-with-resources concept, then no warnings will be shown because Java automatically closes the objects. Here is how it can be done...</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mvY1GVsfwrqy9PxSIyFbJw.png" /></figure><p>It is evident that VScode gives no warning regarding the scanner object closure.</p><p>In the traditional try-catch-finally block, you had to manually close the resource in the finally block. The try-with-resources statement eliminates the need for the finally block.</p><p>This may be useful when you are working with large Java projects where you need to deal with resources like files, network connections, or database connections that need to be closed properly to avoid resource leaks.</p><p>So, if you use more resources in Java, you can use try-with-resources in your code for an optimised experience.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e2e112f4591" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>