<?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 Shyam Kachhadiya on Medium]]></title>
        <description><![CDATA[Stories by Shyam Kachhadiya on Medium]]></description>
        <link>https://medium.com/@shyam1.ss15?source=rss-757c5cce89c0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*HVUSGfw93Z1hsuir</url>
            <title>Stories by Shyam Kachhadiya on Medium</title>
            <link>https://medium.com/@shyam1.ss15?source=rss-757c5cce89c0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 07:42:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@shyam1.ss15/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[Customize implementation of UserDetailsService]]></title>
            <link>https://medium.com/@shyam1.ss15/customize-implementation-of-userdetailsservice-f7cc80ef803?source=rss-757c5cce89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/f7cc80ef803</guid>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-security]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[spring-boot]]></category>
            <dc:creator><![CDATA[Shyam Kachhadiya]]></dc:creator>
            <pubDate>Sun, 02 Oct 2022 20:42:23 GMT</pubDate>
            <atom:updated>2022-10-02T20:42:23.187Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*63OmOwkNkgPCBGc6FkCCiw.png" /></figure><p>Hey guys in this post, we will discuss creating our own implementation of UserDetailsService with step-by-step example. This is the continuation of the <a href="https://bushansirgur.in/spring-security-configure-users-using-jdbcuserdetailsmanager-implementation/">previous post</a>, please read that post before proceeding with this.</p><p>It is most common that when we are working with production-grade applications, we always create our own implementation of UserDetailsService so that we don’t have to rely on the JdbcUserDetailManager.</p><h3>Complete example</h3><p>Let’s create a step-by-step spring boot project and create our own implementation of UserDetailsService</p><h4>Create database and tables</h4><p>In order to create our own custom implementation of UserDetailsService, first we need to create database tables for our users. To create a database and tables execute the following query</p><pre>CREATE database springsecurity;<br><br>USE springsecurity;<br><br>CREATE TABLE tbl_employees<br>(<br>	id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,<br>    email VARCHAR(255) NOT NULL,<br>    pwd VARCHAR(255) NOT NULL,<br>    role VARCHAR(255) NOT NULL<br>);<br><br>INSERT INTO tbl_employees VALUES (NULL, &quot;bushan@gmail.com&quot;, &quot;12345&quot;, &quot;admin&quot;);</pre><blockquote>Add required maven dependencies in your pom file</blockquote><h4>Configure datasource</h4><p>Open application.properties file and add the following contents –</p><pre>spring.datasource.url=jdbc:mysql://localhost:3306/springsecurity<br>spring.datasource.username=shyam<br>spring.datasource.password=123</pre><h4>Create a Rest controller</h4><p>Create HomeController.java</p><pre>package com.example.shyam.controller;<br><br>import org.springframework.web.bind.annotation.RequestMapping;<br>import org.springframework.web.bind.annotation.RestController;<br><br>@RestController<br>public class HomeController {<br>	<br>	@RequestMapping(&quot;/home&quot;)<br>	public String showHomePage () {<br>		return &quot;displaying the home page contents&quot;;<br>	}<br>	<br>	@RequestMapping(&quot;/protected&quot;)<br>	public String protectedPage () {<br>		return &quot;displying the protected page contents&quot;;<br>	}<br>}</pre><h4>Create an entity class</h4><p>Create an entity class Employee.java inside the com.example.shyam.entity package and add the following content</p><pre>import javax.persistence.Entity;<br>import javax.persistence.GeneratedValue;<br>import javax.persistence.GenerationType;<br>import javax.persistence.Id;<br><br>@Entity(name =  &quot;tbl_employees&quot;)<br>public class Employee {<br>	<br>	@Id<br>	@GeneratedValue(strategy = GenerationType.IDENTITY)<br>	private Integer id;<br>	<br>	private String email;<br>	<br>	private String pwd;<br>	<br>	private String role;<br><br>	public Integer getId() {<br>		return id;<br>	}<br><br>	public void setId(Integer id) {<br>		this.id = id;<br>	}<br><br>	public String getEmail() {<br>		return email;<br>	}<br><br>	public void setEmail(String email) {<br>		this.email = email;<br>	}<br><br>	public String getPwd() {<br>		return pwd;<br>	}<br><br>	public void setPwd(String pwd) {<br>		this.pwd = pwd;<br>	}<br><br>	public String getRole() {<br>		return role;<br>	}<br><br>	public void setRole(String role) {<br>		this.role = role;<br>	}<br>}</pre><h4>Create a Repository</h4><p>Create an interface EmployeeRepository.java</p><pre>import java.util.List;<br><br>import org.springframework.data.jpa.repository.JpaRepository;<br>import org.springframework.stereotype.Repository;<br><br>import in.bushansirgur.springboot.entity.Employee;<br><br>@Repository<br>public interface EmployeeRepository extends JpaRepository&lt;Employee, Integer&gt; {<br>	List&lt;Employee&gt; findByEmail(String email);<br>}</pre><h4>Create a service</h4><p>Next, we need to create a service class that implements the UserDetails. Create a class EmployeeService.java</p><pre>import java.util.ArrayList;<br>import java.util.Collection;<br>import java.util.List;<br><br>import org.springframework.security.core.GrantedAuthority;<br>import org.springframework.security.core.authority.SimpleGrantedAuthority;<br>import org.springframework.security.core.userdetails.UserDetails;<br><br>import in.bushansirgur.springboot.entity.Employee;<br><br>public class EmployeeService implements UserDetails {<br><br>	/**<br>	 * <br>	 */<br>	private static final long serialVersionUID = 1L;<br>	private final Employee employee;<br>	<br>	public EmployeeService (Employee employee) {<br>		this.employee = employee;<br>	}<br>	<br>	@Override<br>	public Collection&lt;? extends GrantedAuthority&gt; getAuthorities() {<br>		List&lt;GrantedAuthority&gt; authorities = new ArrayList&lt;&gt;();<br>		authorities.add(new SimpleGrantedAuthority(employee.getRole()));<br>		return authorities;<br>	}<br><br>	@Override<br>	public String getPassword() {<br>		return employee.getPwd();<br>	}<br><br>	@Override<br>	public String getUsername() {<br>		return employee.getEmail();<br>	}<br><br>	@Override<br>	public boolean isAccountNonExpired() {<br>		return true;<br>	}<br><br>	@Override<br>	public boolean isAccountNonLocked() {<br>		return true;<br>	}<br><br>	@Override<br>	public boolean isCredentialsNonExpired() {<br>		return true;<br>	}<br><br>	@Override<br>	public boolean isEnabled() {<br>		return true;<br>	}<br><br>}</pre><p>Here we create a constructor and pass the Employee object. So in the future whoever, creating EmployeeService they need to pass the Employee object as well. With that Employee object, we will retrieve the username, password and authorities.</p><p>Next, we need to create one more service class that implements UserDetailsService because we need to tell Spring security that AppUserDetails is the implementation for UserDetailsService. Create a class AppUserDetails.java</p><pre>import java.util.List;<br><br>import org.springframework.beans.factory.annotation.Autowired;<br>import org.springframework.security.core.userdetails.UserDetails;<br>import org.springframework.security.core.userdetails.UserDetailsService;<br>import org.springframework.security.core.userdetails.UsernameNotFoundException;<br>import org.springframework.stereotype.Service;<br><br>import in.bushansirgur.springboot.entity.Employee;<br>import in.bushansirgur.springboot.repository.EmployeeRepository;<br>import in.bushansirgur.springboot.service.EmployeeService;<br><br>@Service<br>public class AppUserDetails implements UserDetailsService {<br><br>	@Autowired<br>	private EmployeeRepository eRepository;<br>	<br>	@Override<br>	public UserDetails loadUserByUsername(String email) throws UsernameNotFoundException {<br>		List&lt;Employee&gt; employees = eRepository.findByEmail(email);<br>		if (employees.size() == 0) {<br>			throw new UsernameNotFoundException(&quot;User details not found for the user &quot;+email);<br>		}<br>		return new EmployeeService(employees.get(0));<br>	}<br><br>}</pre><p>Let’s customize the spring security to deny all the URIs. Create ProjectSecurityConfig.java</p><pre>import javax.sql.DataSource;<br><br>import org.springframework.context.annotation.Bean;<br>import org.springframework.context.annotation.Configuration;<br>import org.springframework.security.config.annotation.web.builders.HttpSecurity;<br>import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;<br>import org.springframework.security.core.userdetails.UserDetailsService;<br>import org.springframework.security.crypto.password.NoOpPasswordEncoder;<br>import org.springframework.security.crypto.password.PasswordEncoder;<br>import org.springframework.security.provisioning.JdbcUserDetailsManager;<br><br>@Configuration<br>public class WebSecurityConfig extends WebSecurityConfigurerAdapter {<br><br>	@Override<br>	protected void configure(HttpSecurity http) throws Exception {<br>		http.authorizeRequests()<br>		.antMatchers(&quot;/home&quot;).permitAll()<br>		.antMatchers(&quot;/protected&quot;).authenticated()<br>		.and()<br>		.formLogin()<br>		.and()<br>		.httpBasic();<br>	}<br>	<br>	@Bean<br>	public PasswordEncoder passwordEncoder () {<br>		return NoOpPasswordEncoder.getInstance();<br>	}<br>}</pre><h3>Run the app</h3><p>Run the application using the below maven command –</p><pre>mvn spring-boot:run</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/784/1*0ITb0AJZrHri6m7ShS116A.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f7cc80ef803" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring MVC Architecture flow]]></title>
            <link>https://medium.com/@shyam1.ss15/spring-mvc-architecture-flow-5aab739e9ba3?source=rss-757c5cce89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5aab739e9ba3</guid>
            <category><![CDATA[mvc]]></category>
            <category><![CDATA[backend]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <category><![CDATA[mysql]]></category>
            <dc:creator><![CDATA[Shyam Kachhadiya]]></dc:creator>
            <pubDate>Sun, 18 Sep 2022 15:08:51 GMT</pubDate>
            <atom:updated>2022-09-18T15:08:51.698Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/844/1*sUZ-vlmmwboj-TaFUn0MGw.png" /><figcaption>Spring MVC</figcaption></figure><p>Spring is a lightweight framework. It is an open-source Java Platform that is used for developing robust Java applications very rapidly and easily. Its support is extended to various frameworks such as Struts, Hibernate, EJB, JSF, etc.</p><h4>Features of Spring Framework</h4><p>• POJO Based</p><p>• Modular.</p><p>• Integration with existing frameworks</p><p>• Testability</p><p>• Web MVC.</p><p>• Central Exception Handling.</p><h4>Spring MVC Architecture (Model-View-Controller)</h4><p>It is a Java framework that is used to build web applications. It follows the Model-View-Controller design pattern. All the basic features of a core spring framework are implemented by it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*LztIAxqlUpKHBOHGBU80eQ.png" /></figure><p><strong>a.</strong> <strong>Model</strong></p><p>It contains the data of the application. Data can be a single object or a collection of objects.</p><p><strong>b.</strong> <strong>Controller</strong></p><p>It contains the business logic of an application. Here, the @Controller annotation is used to mark the class as the controller.</p><p><strong>c.</strong> <strong>View</strong></p><p>A view represents the provided information in a particular format. Generally, JSP+JSTL is used to create a view page. Although spring also supports other view technologies such as Apache Velocity, Thyme leaf, and Free Marker.</p><h4>Front Controller Design Pattern</h4><h4>What is the Front Controller Design pattern</h4><p>We are discussing it here as Spring MVC is based on this design pattern. Front Controller is a standard design pattern where a single controller (Servlet in our context) is responsible for handling all request processing. The actual processing is done by different other configurable delegated components.</p><h4>Dispatcher Servlet</h4><p><em>DispatcherSevlet </em>(It’s a standard Java Servlet) is the front controller in Spring MVC. A dispatcher servlet can be configured by means of a <em>web.xml</em>, <em>ServletContainerInitializer, </em>or through Spring’s <em>AbstractAnnotationConfigDispatcherServletInitializer.</em></p><p><em>DispatcherServlet</em> receives all of the HTTP requests and delegates them to controller classes.</p><p><strong>Before the Servlet 3.x specification, <em>DispatcherServlet</em> would be registered in the <em>web.xml</em> file for a Spring MVC application.</strong> Since the Servlet 3.x specification, we can register servlets programmatically using <em>ServletContainerInitializer</em>.</p><p>Let’s see a <em>DispatcherServlet </em>example configuration in the<em> web.xml </em>file:</p><pre>&lt;servlet&gt;<br>    &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;<br>    &lt;servlet-class&gt;<br>        org.springframework.web.servlet.DispatcherServlet<br>    &lt;/servlet-class&gt;<br>&lt;/servlet&gt;</pre><pre>&lt;servlet-mapping&gt;<br>    &lt;servlet-name&gt;dispatcher&lt;/servlet-name&gt;<br>    &lt;url-pattern&gt;/&lt;/url-pattern&gt;<br>&lt;/servlet-mapping&gt;</pre><h4>Communication between components in Spring MVC</h4><p>In this section, we will present the interaction between various components in Spring MVC. However, before proceeding further, let us understand the actors:-</p><p><strong>User:</strong> Application user/API</p><p><strong>Front Controller: </strong>Spring <em>DispatcherServlet</em> responsible for accepting the request from users and delegating and orchestrates the request with other internal components for processing</p><p><strong>Handler Mapper: </strong>Responsible to find the appropriate controller that can serve the incoming request</p><p><strong>Controller: </strong>Processes the request. It invokes the underlying business and repository services. It warps the response data in a model</p><p><strong>View Resolver: </strong>Responsible to find the appropriate view which can handle the request</p><p><strong>View: </strong>The component on which the processed data (the model returned by the controller) is rendered</p><p>EX: of MVC calling thyme leaf HTML page.</p><pre>@Controller<br>@RequestMapping(&quot;/posts&quot;)<br><em>public class </em>PostController {<br><br>    @Autowired<br>    <em>PostRepository </em>postRepository;<br><br>    @GetMapping(&quot;create/post&quot;)<br>    <em>public </em>String getPostPage(<em>Model </em>model){<br>        System.<strong><em>out</em></strong>.println(&quot;getPostPage&quot;);<br>        String date = <em>new </em>SimpleDateFormat(&quot;dd-MM-yyyy&quot;).format(<em>new </em>Date());<br><em>//        String date = new Date().toString();<br>        </em>model.addAttribute(&quot;date&quot;, date);<br>        <em>return </em>&quot;posts/postPage&quot;;<br>    }<br>}</pre><h4>Model Creation</h4><p>Now let´s create our model classes called Post(Entity classes). Lombok is a very useful library used to generate boilerplate code manly for model/data objects.</p><p><strong>User</strong></p><p>This class includes validations based on the validations provided by Hibernate.</p><pre><em>package </em>com.example.crud_app.model;<br><br><em>import </em>org.hibernate.annotations.Cascade;<br><br><em>import </em>javax.persistence.*;<br><em>import </em>java.time.LocalDate;<br><em>import </em>java.time.LocalDateTime;<br><em>import </em>java.util.ArrayList;<br><em>import </em>java.util.<em>List</em>;<br><br>@Entity<br>@Table(name = &quot;POSTS&quot;)<br><em>public class </em>Post {<br>    @Id<br>    @GeneratedValue(strategy = GenerationType.<strong><em>AUTO</em></strong>)<br>    @Column(name = &quot;id&quot;, nullable = <em>false</em>)<br>    <em>private int </em>id;<br><br><br>    <em>private </em>String title;<br><br><br>    <em>private </em>String excerpt;<br>    <em>private </em>String content;<br>    <em>private </em>String author;<br><br>    @Override<br>    <em>public </em>String toString() {<br>        <em>return </em>&quot;Post{&quot; +<br>                &quot;id=&quot; + id +<br>                &quot;, title=&#39;&quot; + title + &#39;\&#39;&#39; +<br>                &quot;, excerpt=&#39;&quot; + excerpt + &#39;\&#39;&#39; +<br>                &quot;, content=&#39;&quot; + content + &#39;\&#39;&#39; +<br>                &quot;, author=&#39;&quot; + author + &#39;\&#39;&#39; +<br>                &quot;, tags=&quot; + tags +<br>                &quot;, publishedDate=&quot; + publishedDate +<br>                &quot;, isPublished=&quot; + isPublished +<br>                &quot;, createdAt=&quot; + createdAt +<br>                &quot;, updatedAt=&quot; + updatedAt +<br>                &#39;}&#39;;<br>    }<br><br>    @OneToMany(fetch = FetchType.<strong><em>EAGER</em></strong>,cascade = CascadeType.<strong><em>ALL</em></strong>)<br>    <em>private List</em>&lt;Tag&gt; tags;<br>    @Column(name = &quot;published_date&quot;, columnDefinition = &quot;DATE&quot;)<br>    <em>private </em>LocalDate publishedDate;<br>    <em>private boolean </em>isPublished;<br>    @Column(name = &quot;created_at&quot;, columnDefinition = &quot;TIMESTAMP&quot;)<br>    <em>private </em>LocalDateTime createdAt;<br>    @Column(name = &quot;updated_at&quot;, columnDefinition = &quot;TIMESTAMP&quot;)<br>    <em>private </em>LocalDateTime updatedAt;<br><br><br>    <em>public </em>String getTitle() {<br>        <em>return </em>title;<br>    }<br><br>    <em>public void </em>setTitle(String title) {<br>        <em>this</em>.title = title;<br>    }<br><br>    <em>public </em>String getExcerpt() {<br>        <em>return </em>excerpt;<br>    }<br><br>    <em>public void </em>setExcerpt(String excerpt) {<br>        <em>this</em>.excerpt = excerpt;<br>    }<br><br>    <em>public </em>String getContent() {<br>        <em>return </em>content;<br>    }<br><br>    <em>public void </em>setContent(String content) {<br>        <em>this</em>.content = content;<br>    }<br><br>    <em>public </em>String getAuthor() {<br>        <em>return </em>author;<br>    }<br><br>    <em>public void </em>setAuthor(String author) {<br>        <em>this</em>.author = author;<br>    }<br><br>    <em>public </em>String getPublishedDate() {<br>        <em>return </em>publishedDate == <em>null </em>? &quot;null&quot; : publishedDate.toString();<br><em>//        return publishedDate.toString().length() == 0 ? &quot;null&quot; : publishedDate.toString();<br>    </em>}<br>    <em>public void </em>setPublishedDate(LocalDate publishedDate) {<br>        <em>this</em>.publishedDate = publishedDate;<br>    }<br><br>    <em>public boolean </em>setPublished() {<br>        <em>return </em>isPublished;<br>    }<br><br>    <em>public void </em>setPublished(<em>boolean </em>published) {<br>        isPublished = published;<br>    }<br><br>    <em>public </em>LocalDateTime getCreatedAt() {<br>        <em>return </em>createdAt;<br>    }<br><br>    <em>public void </em>setCreatedAt(LocalDateTime createdAt) {<br>        <em>this</em>.createdAt = createdAt;<br>    }<br><br>    <em>public </em>String getUpdatedAt() {<br>        <em>return </em>updatedAt == <em>null </em>? &quot;null&quot; : updatedAt.toString();<br>    }<br><br>    <em>public void </em>setUpdatedAt(LocalDateTime updatedAt) {<br>        <em>this</em>.updatedAt = updatedAt;<br>    }<br><br><br>    <em>public int </em>getId() {<br>        <em>return </em>id;<br>    }<br><br>    <em>public void </em>setId(<em>int </em>id) {<br>        <em>this</em>.id = id;<br>    }<br><br>    <em>public List</em>&lt;Tag&gt; getTags() {<br>        <em>return </em>tags;<br>    }<br>    <em>public </em>String getTagsToString() {<br>        String tagsToString = &quot;&quot;;<br>        <em>if </em>(tags == <em>null</em>){<br>            <em>return </em>&quot;&quot;;<br>        }<br>        <em>for </em>(Tag tag : tags){<br>            tagsToString += (&quot;#&quot; + tag.getName() + &quot; &quot;);<br>        }<br>        <em>return </em>tagsToString;<br>    }<br>    <em>public void </em>setTags(<em>List</em>&lt;Tag&gt; tags) {<br>        <em>this</em>.tags = tags;<br>    }<br><br>}</pre><p>now we will be using JPA library, so we are creating PostRepository.java interface.</p><pre><em>package </em>com.example.crud_app.jpa;<br><br><em>import </em>com.example.crud_app.model.Post;<br><em>import </em>org.springframework.data.repository.<em>CrudRepository</em>;<br><br><em>public interface PostRepository extends <br>CrudRepository</em>&lt;Post, Integer&gt; <br>{<br>}</pre><p>Now we will be using all our application codes in such a way that, they can work with all our prev files created.</p><p>main spring file.java</p><pre><em>package </em>com.example.crud_app;</pre><pre><em>import </em>com.example.crud_app.jpa.<em>PostRepository</em>;<br><em>import </em>com.example.crud_app.model.Post;<br><em>import </em>com.example.crud_app.model.Tag;<br><em>import </em>org.springframework.boot.SpringApplication;<br><em>import </em>org.springframework.boot.autoconfigure.SpringBootApplication;<br><em>import </em>org.springframework.context.<em>ConfigurableApplicationContext</em>;</pre><pre><em>import </em>java.time.LocalDateTime;<br><em>import </em>java.util.<em>List</em>;</pre><pre>@SpringBootApplication<br><em>public class </em>CrudApplication {</pre><pre> <em>public static void </em>main(String[] args) {<br> <em>ConfigurableApplicationContext </em>configurableApplicationContext = SpringApplication.<em>run</em>(CrudApplication.<em>class</em>, args);</pre><pre> Tag tag1 = <em>new </em>Tag();<br> tag1.setName(“java”);</pre><pre> Tag tag2 = <em>new </em>Tag();<br> tag2.setName(“javaScript”);<br></pre><pre> Tag tag3 = <em>new </em>Tag();<br> tag3.setName(“Python”);</pre><pre> Post p1 = <em>new </em>Post();<br> p1.setContent(“Hello World”);<br> p1.setAuthor(“John Smith”);<br> p1.setPublished(<em>true</em>);<br> p1.setExcerpt(“settlements”);<br> p1.setTitle(“sdkjfn”);<br> p1.setCreatedAt(LocalDateTime.<em>now</em>());</pre><pre> p1.setTags(<em>List</em>.<em>of</em>(tag1, tag2, tag3));</pre><pre> <em>PostRepository </em>postRepository = configurableApplicationContext.getBean(<em>PostRepository</em>.<em>class</em>);<br> postRepository.save(p1);<br> System.<strong><em>out</em></strong>.println(p1);<br> p1.getTags().forEach(System.<strong><em>out</em></strong>::println);<br><em>// postRepository.</em></pre><pre><em> Iterable</em>&lt;Post&gt; posts = postRepository.findAll();</pre><pre> posts.forEach(post -&gt;{<br> System.<strong><em>out</em></strong>.println(post.getTags());<br> });<br> }</pre><pre>}</pre><p>The above example will be good for MVC.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5aab739e9ba3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Inversion of Control and Dependency Injection]]></title>
            <link>https://medium.com/@shyam1.ss15/inversion-of-control-and-dependency-injection-2221f2e21bed?source=rss-757c5cce89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/2221f2e21bed</guid>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[design-thinking]]></category>
            <category><![CDATA[design-patterns]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring]]></category>
            <dc:creator><![CDATA[Shyam Kachhadiya]]></dc:creator>
            <pubDate>Sun, 11 Sep 2022 15:17:31 GMT</pubDate>
            <atom:updated>2022-09-11T15:17:31.314Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/596/1*vAjiOjArAky13X1jnWz2-A.png" /><figcaption>Dipendency Injection</figcaption></figure><h4>Spring Framework</h4><p>Spring is a little framework with a lot of features. It’s sometimes referred to as a framework of frameworks because it supports a variety of frameworks, including Struts, Hibernate, Tapestry, EJB, JSF, and others. IOC, AOP, DAO, Context, ORM, WEB MVC, and other modules are part of the Spring framework.</p><p>Dependency Injection, Dependency Inversion, and Inversion of Control are 3 terms that, although related, are commonly confused and misinterpreted. In the Internet wildlands, you can find multiple articles and blog posts that depict them as being the same or relate them in an incorrect manner, causing confusion and ambiguity to replicate endlessly.</p><h4>Inversion of Control (IoC)</h4><p>Inversion of control is a programming principle that inverts the flow of control in an application. In traditional procedural programming, the code that controls the execution of the program — the main function — instantiates objects, calls methods, and even asks the user for input so that the execution can continue and the program can achieve its task. With IoC, it is a framework that does the instantiation, method calls, and triggers user actions, having full control of the flow and removing this responsibility from the main function, and as a consequence the application.</p><blockquote><em>The major difference between an object-oriented framework and a class library is that the framework calls the application code. Normally the application code calls the class library. This inversion of control is sometimes named the Hollywood principle, “Do not call us, we call You”.</em></blockquote><p>In the context of service containers, IoC is achieved by allowing the framework to do the binding and instantiation of dependencies. Instead of the application having to create and use services, it is the framework that determines the moment when the instantiation is needed, using a pre-set configuration that instructs it on how to execute these tasks.</p><h3>Dependency Injection (DI)</h3><p>Dependency Injection is a software design technique in which the creation and binding of dependencies are done outside of the dependent class. Afterward, said dependencies are provided already instantiated and ready to be used, hence the term “injection”; in contrast to the dependent class having to instantiate its dependencies internally, and having to know how to configure them, thus causing coupling.</p><p><strong>Bean:</strong> Beans are the objects in Spring that constitute the backbone of your application and are maintained by the Spring IoC container. A bean is an object that a Spring IoC container instantiates, assembles, and generally manages. A bean, on the other hand, is just one of many objects in your program. Beans and their interdependencies are reflected in the container’s configuration metadata.</p><p>Spring Beans&#39; scope is divided into five categories of which two major are as follows:</p><p><strong>Singleton:</strong> Each container will only have one instance of the bean. Spring beans have this as their default scope. If you use this scope, make sure that the bean doesn’t have any shared instance variables, as this could cause data inconsistency.</p><p><strong>Prototype: </strong>A new instance will be created every time the bean is requested.</p><p><strong>Types of dependency injections</strong></p><ol><li>Constructor Injection</li><li>Setter Injection</li><li>Field Injection</li></ol><p><strong>Constructor Injection:</strong></p><pre>package com.app;<br>import org.springframework.stereotype.Component;</pre><pre><a href="http://twitter.com/Component">@Component</a><br>public class FortuneService{ </pre><pre>public String getFortune() {<br>  return &quot;Today is your lucky day!&quot;;<br> }</pre><pre>}</pre><p>Here is a class that has the getFortune() method and we want to use this method in another class.</p><pre>package com.app;<br>import org.springframework.stereotype.Component;<br>import org.springframework.beans.factory.annotation.Autowired;</pre><pre><a href="http://twitter.com/Component">@Component</a><br>public class Coach {private FortuneService fortuneService;<br> <br> <a href="http://twitter.com/Autowired">@Autowired</a><br> public Coach(FortuneService fortuneService) {<br>  this.fortuneService = fortuneService;<br> } </pre><pre> public String getDailyWorkout() {<br>  return &quot;Do cardio daily!!&quot;;<br> } <br> <br> public String getDailyFortune() {<br>  return fortuneService.getFortune();<br> }<br>}</pre><p><strong>Setter Injection:</strong></p><pre>package com.app;<br>import org.springframework.stereotype.Component;<br>import org.springframework.beans.factory.annotation.Autowired;</pre><pre><a href="http://twitter.com/Component">@Component</a><br>public class Coach {private FortuneService fortuneService;<br>{<br> <a href="http://twitter.com/Autowired">@Autowired</a><br> public void setFortuneService(FortuneService fortuneService) {<br>  this.fortuneService = fortuneService;<br> }<br> <br> public String getDailyWorkout() {<br>  return &quot;Do cardio daily!!&quot;;<br> }<br> <br> public String getDailyFortune() {<br>  return fortuneService.getFortune();<br> }<br>}</pre><p><strong>Field Injection:</strong></p><pre>package com.app;<br>import org.springframework.stereotype.Component;<br>import org.springframework.beans.factory.annotation.Autowired;</pre><pre><a href="http://twitter.com/Component">@Component</a><br>public class Coach {</pre><pre><a href="http://twitter.com/Autowired">@Autowired</a><br>private FortuneService fortuneService;<br> public String getDailyWorkout() {<br>  return &quot;Do cardio daily!!&quot;;<br> }<br> public String getDailyFortune() {<br>  return fortuneService.getFortune();<br> }<br>}</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2221f2e21bed" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction To Servlet And JSP]]></title>
            <link>https://medium.com/@shyam1.ss15/introduction-to-servlet-and-jsp-6a43aebf38dc?source=rss-757c5cce89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6a43aebf38dc</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[serverless]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[backend]]></category>
            <dc:creator><![CDATA[Shyam Kachhadiya]]></dc:creator>
            <pubDate>Sun, 04 Sep 2022 12:28:14 GMT</pubDate>
            <atom:updated>2022-09-04T12:28:14.945Z</atom:updated>
            <content:encoded><![CDATA[<blockquote>In this article we learned about Servlet and JSP.</blockquote><h4>1 . Servlet:-</h4><p>Servlet is a Java program that runs on the web server-side or on an application server such as Apache Tomcat. Servlet handles the request received from the webserver.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/610/0*MM7Uk8fTi2PYw-Pi.jpeg" /></figure><p>Fig-Reference image for Servlet</p><p><strong>Steps involve in servlet:-</strong></p><ol><li>The web server receives the request.</li><li>The web server passes the request to the corresponding servlet.</li><li>The <a href="https://www.java67.com/2021/07/servlet-and-filter-interview-questions-answers-java-.html">servlet </a>processes the request and generates the response in the form of output.</li><li>The servlet sends the response back to the webserver.</li><li>The web server sends the response back to the client and the client browser displays it on the screen.</li></ol><p>Servlet uses HTTP protocol for handling requests and responses. The HTTP protocol is a stateless protocol.</p><p><strong>Servlet life cycle:-</strong></p><p>The Servlet life cycle mainly goes through four stages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*tuQen5q5IgK3X1Fb.png" /><figcaption>Servlet Life cycle</figcaption></figure><h3>Java Server Pages (JSP)</h3><p>JSP or Java Server Pages are used to create applications just like Servlet. JSP’s are compiled to serverlets and usually a mixture of text, scripts and directives.</p><p>JSP provide more functionality than a servlet with features such as expression language, Java Standard Tag Library (JSTL), Directives etc.</p><p>JSP stands for JavaServer Pages, and it’s a technology for creating dynamic Web pages. This allows developers to embed java code in HTML pages by using specific JSP tags, the majority of which begin with &lt;% and end with % &gt;. The only benefit of JSP is that it is simple to write JSP code for developers.</p><p>JSP is internally converted into a servlet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/739/0*CUpTH-KAmTFTlbdY.png" /></figure><p>JSP conversion</p><p>Servlets are designed for dynamic web content, after all. However, there is no effective way to represent dynamic web content on a web page using Servlets. There are so many that we need to write down out.print() statements. There can’t be simply one web page in a web application. It’s a collection of web pages, actually. It is not suggested to create web pages in this manner.</p><p><strong>Scriptlet tag: </strong>Whatever is written into this tag is converted into a service function in the servlet. The business logic is written into this.</p><pre>&lt;%  java source code %&gt;</pre><p><strong>Directive tag:</strong> This element is used to declare anything that is used by the entire page, such as importing a file.</p><pre>&lt;%@ directive attribute=&quot;value&quot; %&gt;</pre><p><strong>Declarative tag:</strong> This tag is used to declare all variables and statements outside of the service function but within the class.</p><pre><strong>&lt;</strong>%!  field or method declaration %<strong>&gt;</strong></pre><p><strong>Expression tag: </strong>Everything inside this tag is printed on the screen.</p><pre><strong>&lt;</strong>%=  statement %<strong>&gt;</strong></pre><p><strong>Advantages Of JSP:-</strong></p><ol><li>JSP offers an efficient and more straightforward approach for coding dynamic web pages.</li><li>JSP doesn’t need to have additional files such as java class files, web.xml, etc.</li><li>Web Container (or <a href="http://javarevisited.blogspot.sg/2012/05/5-difference-between-application-server.html">application server</a> like tomcat) handled changes when changes are done in the JSP code, and it does not need recompilation.</li><li>Direct access to JSP pages is possible, and hence web.xml mapping is not necessary as you have to do in servlets.</li><li>JSP codes are easy to write and maintain.</li><li>Development speed becomes fast, and there is no need for recompilation and redeployment.</li><li>It has high performance and scalability compared to other dynamic web development tools.</li><li>JSP is constructed on Java technology, which makes it platform-independent.</li></ol><p><strong>Disadvantages of JSP:-</strong></p><ol><li>Difficult to debug for errors.</li><li>First-time access leads to wastage of time</li><li>Its output is HTML which lacks features.</li></ol><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6a43aebf38dc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Normalization in SQL with ease.]]></title>
            <link>https://medium.com/@shyam1.ss15/normalization-in-sql-with-ease-e401ec6d0671?source=rss-757c5cce89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/e401ec6d0671</guid>
            <category><![CDATA[normalization]]></category>
            <category><![CDATA[sql]]></category>
            <category><![CDATA[database]]></category>
            <category><![CDATA[dbms]]></category>
            <dc:creator><![CDATA[Shyam Kachhadiya]]></dc:creator>
            <pubDate>Sun, 28 Aug 2022 08:59:15 GMT</pubDate>
            <atom:updated>2022-08-28T12:05:57.077Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/0*4Wa4fETJrN1L9fhj" /><figcaption>DBMS Normalization</figcaption></figure><p>Data in the Database is stored in terms of enormous quantities. Retrieving certain data will be a tedious task if the data is not organized correctly. With the help of Normalization, we can organize this data and reduce the redundant data. Through the medium of this article, I will give you a complete insight into Normalization in SQL.</p><p>The following topics will be covered in this article:</p><ol><li>What is Normalization in a Database?</li></ol><p>2. What are 1NF, 2NF, 3NF, and BCNF Normal Forms?</p><ul><li>1st Normal Form (1NF)</li><li>2nd Normal Form (2NF)</li><li>3rd Normal Form (3NF)</li><li>Boyce-Codd Normal Form(BCNF)</li></ul><h4>What is Normalization in a Database?</h4><p>It is the process of reducing the redundancy of data in the table and also improving the data integrity. So why is this required? without Normalization in SQL, we may face many issues such as</p><ol><li><strong><em>Insertion anomaly</em></strong>: It occurs when we cannot insert data into the table without the presence of another attribute</li><li><strong><em>Update anomaly</em></strong>: It is a data inconsistency that results from data redundancy and a partial update of data.</li><li><strong><em>Deletion Anomaly</em></strong>: It occurs when certain attributes are lost because of the deletion of other attributes.</li></ol><p>In brief, normalization is a way of organizing the data in the database. Normalization entails organizing the columns and tables of a database to ensure that their dependencies are adequately enforced by database integrity constraints.</p><p>It usually divides a large table into smaller ones, so it is more efficient. In 1970 the First Normal Form was defined by <em>Edgar F Codd</em> and eventually, other Normal Forms were prescribed.</p><p>One question that arises in between is, what does SQL have to do with Normalization? Well SQL is the language that is used to interact with the database. To initiate any interaction the data present in the database has to be of Normalized Form. Else we cannot proceed further as it results in anomalies.</p><p>Normalization in SQL will enhance the distribution of data. Now let’s understand every Normal Form with examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*3FvwwaioST4Lqs8v.png" /></figure><h4>1st Normal Form (1NF)</h4><p>In this Normal Form, we tackle the problem of atomicity. Here atomicity means values in the table should not be further divided. In simple terms, a single cell cannot hold multiple values. If a table contains a composite or multi-valued attribute, it violates the First Normal Form.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/505/0*9pN0eKsmCoPTM546.png" /></figure><p>In the above table, we can see that the Phone Number column has two values. Thus it violated the 1st NF. Now if we apply the 1st NF to the above table we get the below table as the result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/0*psNqpac18leLp8iR.png" /></figure><p>By this, we have achieved atomicity and also every column has unique values.</p><h4>2nd Normal Form (2NF)</h4><p>The first condition in the 2nd NF is that the table has to be in the 1st NF. The table also should not contain partial dependency. Here partial dependency means the proper subset of candidate key determines a non-prime attribute. To understand in a better way let&#39;s look at the below example.</p><p>Consider the table</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/459/0*-B759Jcau7vsBcTk.png" /></figure><p>This table has a composite primary key <strong>Emplyoee ID</strong>, <strong>Department ID</strong>. The non-key attribute is <strong>Office Location</strong>. In this case, <strong>Office Location</strong> only depends on <strong>Department ID</strong>, which is only part of the primary key. Therefore, this table does not satisfy the second Normal Form.</p><p>To bring this table to Second Normal Form, we need to break the table into two parts. This will give us the below tables:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/701/0*mQp3kswP3DzQ-6iC.png" /></figure><p>As you can see we have removed the partial functional dependency that we initially had. Now, in the table, the column <strong>Office Location</strong> is fully dependent on the primary key of that table, which is <strong>Department ID</strong>.</p><p>Now that we have learned 1st and 2nd normal forms let&#39;s head to the next part of this Normalization in SQL article.</p><h4>3rd Normal Form (3NF)</h4><p>The same rule applies as before i.e, the table has to be in 2NF before proceeding to 3NF. The other condition is there should be no transitive dependency for non-prime attributes. That means non-prime attributes (which don’t form a candidate key) should not be dependent on other non-prime attributes in a given table. So a transitive dependency is a functional dependency in which X → Z (X determines Z) indirectly, by X → Y and Y → Z (where it is not the case that Y → X)</p><p>Let’s understand this more clearly with the help of an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/0*KGPCvAAyjwr1iIl5.png" /></figure><p>In the above table, <strong>Student ID</strong> determines <strong>Subject ID</strong>, and <strong>Subject ID</strong> determines <strong>Subject</strong>. Therefore, <strong>Student ID</strong> determines <strong>Subject</strong> via <strong>Subject ID. </strong>This implies that we have a transitive functional dependency, and this structure does not satisfy the third normal form.</p><p>Now to achieve the third normal form, we need to divide the table as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/528/0*pXxTmkfEBUmkGUmm.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*n7RNSp32Rpq6wvcw.png" /></figure><p>As you can see from the above tables all the non-key attributes are now fully functional and dependent only on the primary key. In the first table, columns <strong>Student Name, </strong><strong>Subject ID</strong> and <strong>Address</strong> are only dependent on <strong>Student ID</strong>. The second table <strong>Subject</strong> is only dependent on <strong>Subject ID</strong>.</p><h3>Boyce Codd Normal Form (BCNF)</h3><p>This is also known as 3.5 NF. It&#39;s the higher version of 3NF and was developed by Raymond F. Boyce and Edgar F. Codd to address certain types of anomalies that were not dealt with in 3NF.</p><p>Before proceeding to BCNF the table has to satisfy the 3rd Normal Form.</p><p>In BCNF if every functional dependency <strong>A → B</strong>, then <strong>A</strong> has to be the <strong>Super Key</strong> of that particular table.</p><p>Consider the below table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/503/0*Df6whwBMaiEcuocu.png" /></figure><ul><li>One student can enroll in multiple subjects.</li><li>There can be multiple professors teaching one subject</li><li>And, For each subject, a professor is assigned to the student</li></ul><p>In this table, all the normal forms are satisfied except BCNF. Why?</p><p>As you can see<strong>Student ID,</strong> and<strong> Subject</strong>form the primary key, which means the <strong>Subject</strong>column is a <strong>prime attribute</strong>. But, there is one more dependency,→<strong>Subject</strong>.</p><p>And while<strong>Subject</strong>is a prime attribute,<strong>Professor</strong>is a <strong>non-prime attribute</strong>, which is not allowed by BCNF.</p><p>Now to satisfy the BCNF, we will be dividing the table into two parts. One table will hold what already exists and a newly created column <strong>Professor ID</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/483/0*Tik3uf2OwlMqzz09.png" /></figure><p>And in the second table, we will have the columns Professor ID, Professor and Subject.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*1_j7aJ5kyNuO_72S.png" /></figure><p>By doing this we are satisfied with the Boyce Codd Normal Form.</p><p>Thus this brings us to the end of the Normalization in SQL article. I hope now you have a clear idea about Normalization concepts.</p><h3>How to use basic commands</h3><p>If Data Scientist really is the <a href="https://hbr.org/2012/10/data-scientist-the-sexiest-job-of-the-21st-century">sexiest job</a> in the world, <strong>SQL </strong>is the decidedly unsexy tool that you’ll use to do most of your work. Based on job descriptions, SQL is even more in demand than other popular programming languages like Python and Java.</p><p><strong>TL,DR </strong>— go to the summary table of basic commands at the end</p><h3>What is SQL</h3><p>SQL is the most commonly used language for interacting with databases. Why? It is relatively easy to understand and allows us to access data directly where it is stored.</p><p>SQL can be pronounced in two different ways. You can say the letters individually “S”, “Q”, “L”, or like the word “Sequel”. Either way is fine, although be warned … you may come across some people that adamantly insist that their pronunciation is the correct one. Even the big tech companies seem to disagree on this: Microsoft and Oracle databases use “Sequel”, while IBM and most open source databases use “S.Q.L”</p><h4>What are data, databases, and tables?</h4><p><strong>Data </strong>are a collection of facts relating to an object. Data could be numbers, words, measurements, or even an image, a sound, or a video.</p><p>A <strong>database </strong>is an organized collection of data. It is a way to store information so that it can be accessed later. There are many different types of databases. Some examples are relational, object-oriented, NoSQL, and graph … In this blog, we’ll be discussing relational databases — where the data are stored in tables that are related to each other.</p><p><strong>What’s a table?</strong> This is where data is grouped in rows and columns. If you are familiar with excel or Google sheets, tables are similar.</p><h4>How to use SQL</h4><p>SQL is written in statements. The statement that we’ll be using is SELECT — this allows us to access and display data. SELECT statements are known as a query. SQL is not case sensitive but it is best practice to capitalize SQL keywords so that they stand out from other parts of the query.</p><h4>First steps</h4><p>To view all the data in a table we would write:</p><p><strong>SELECT * FROM table;</strong></p><p>Some databases are huge — millions or even billions of rows. It would take a long time to retrieve all this data. Fortunately, if we only want to see what the data in the table looks like, we don’t have to retrieve everything. We can use the LIMIT command to return only the number of rows that we specify.</p><pre>SELECT *<br>  FROM table<br> LIMIT 10;</pre><p>Maybe we’d like to see who were the highest-scoring players from a game. We can sort the data using the <strong>ORDER BY</strong> clause on the column that we would like to sort. To sort the highest scorers at the top, we’d follow the column name with <strong>DESC</strong> for descending. In our SQL query ORDER BY comes after we have applied filters — which we’ll learn about next.</p><h4>Filtering our results</h4><p>It’s one thing to sort the data, but what if we have something specific that we’re searching for — for example back to our basketball example we’d like to find all the players who scored more than 30 points in a game. To do that we can filter the data using the <strong>WHERE </strong>clause. WHERE gives us a subset of the data that meets the condition that we specify. We can use numeric filters like equal to, not equal to, greater than, less than; or non-numeric filters — LIKE, IN, NOT …</p><h4>LIKE</h4><p><strong>LIKE </strong>allows us to filter on similar values, rather than exact values. What makes LIKE especially powerful is that we can use wildcards as a substitute for a character or series of characters. The wildcard “%” represents any sequence of characters. It can be applied before or after the values that we are filtering on. The wildcard “_” is a substitute for a single character. WE can also use ILIKE, which works in the same way as LIKE, but ignores the character’s case.</p><pre>SELECT last_name, height<br>  FROM players<br> WHERE last_name ILIKE ‘jam%’;</pre><h4>IN</h4><p><strong>IN </strong>allows us to filter on a list of values that we would like to include. In the example below</p><pre>SELECT *<br>  FROM games<br> WHERE month IN (‘May’, ‘June’);</pre><h4>NOT</h4><p>We put <strong>NOT</strong> before a conditional statement to select rows where the statement is false. NOT is often used with LIKE and IN.</p><pre>SELECT *<br>  FROM games<br> WHERE month NOT IN (‘May’, ‘June’);</pre><h4>BETWEEN</h4><p>This is used to filter rows where the values in the column are within a specific range. While we could replicate the same thing using AND / OR, using <strong>BETWEEN </strong>is more intuitive. Note that BETWEEN is inclusive, it includes the values that we specify.</p><pre>SELECT *<br>  FROM games<br> WHERE date BETWEEN ‘2020–01–01’ AND ‘2020–04–01’;</pre><h4>NULL</h4><p>We can use IS <strong>NULL </strong>to identify rows that do not have data. This is a useful step in checking for missing data. Note we can’t use = NULL.</p><pre>SELECT *<br>  FROM players<br> WHERE last_name IS NULL;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e401ec6d0671" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object-Oriented Programming in Java — Java OOPs Concepts]]></title>
            <link>https://medium.com/@shyam1.ss15/object-oriented-programming-in-java-java-oops-concepts-5713714d3bfe?source=rss-757c5cce89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/5713714d3bfe</guid>
            <category><![CDATA[java8]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[oops-concepts]]></category>
            <dc:creator><![CDATA[Shyam Kachhadiya]]></dc:creator>
            <pubDate>Mon, 22 Aug 2022 03:33:39 GMT</pubDate>
            <atom:updated>2022-08-22T03:33:39.601Z</atom:updated>
            <content:encoded><![CDATA[<h3>Object-Oriented Programming in Java — Java OOPs Concepts</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xUxlQKWf9AyaRDPZnr87xQ.png" /><figcaption>Object Oriented Programming</figcaption></figure><p>Object-Oriented Programming is a programming style associated with the concepts like class, object, Inheritance, Encapsulation, Abstraction, and Polymorphism. Most popular programming languages like Java, C++, C#, Ruby, etc. follow an object-oriented programming paradigm. In this blog, I will talk about object-oriented programming concepts in Java. An object-based application in Java is based on declaring classes, creating objects from them, and interacting between these objects. In this blog, we will understand the below core concepts of Object-oriented Programming in the following sequence:</p><ol><li>Inheritance</li><li>Encapsulation</li><li>Abstraction</li><li>Polymorphism</li></ol><p>Let’s get started with the first Object Oriented Programming concept i.e. <strong>Inheritance</strong>.</p><h4>Inheritance</h4><p>In OOP, computer programs are designed so that everything is an object that interacts with one another. Inheritance is one such concept where the properties of one class can be inherited by the other. It helps to reuse the code and establish a relationship between different classes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tRecFEaiPYyI7qoqr5aDFw.png" /><figcaption>Parent class &amp; Derived Class</figcaption></figure><p>As we can see in the image, a child inherits the properties from his father. Similarly, in Java, there are two classes:</p><p><strong><em>1. Parent class ( Super or Base class)</em></strong></p><p><strong><em>2. Child class (Subclass or Derived class )</em></strong></p><p>A class that inherits the properties is known as Child Class whereas a class whose properties are inherited is known as Parent class.</p><p><strong><em>Inheritance is further classified into 4 types:</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IB2yG-WVxhGLwO6eD_ETkQ.png" /><figcaption>type of Inheritance in java</figcaption></figure><h4>Single Inheritance:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/144/0*akoDaNq-C5rsWsKR.png" /></figure><p>In single inheritance, one class inherits the properties of another. It enables a derived class to inherit the properties and behavior of a single-parent class. This will, in turn, enable code re-usability as well as add new features to the existing code.</p><p>Here, Class A is your parent class and Class B is your child class which inherits the properties and behavior of the parent class.</p><p>Let’s see the syntax for single inheritance:</p><pre>Class A<br>{<br>---<br>}<br>Class B extends A {<br>---<br>}</pre><h4>Multilevel Inheritance:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/204/0*7cUJH7BJM6s-rvYK.png" /></figure><p>When a class is derived from a class that is also derived from another class, i.e. a class having more than one parent class but at different levels, such type of inheritance is called Multilevel Inheritance.</p><p>If we talk about the flowchart, class B inherits the properties and behavior of class A and class C inherits the properties of class B. Here A is the parent class for B and class B is the parent class for C. So in this case class C implicitly inherits the properties and methods of class A along with Class B. That’s what is multilevel inheritance.</p><p>Let’s see the syntax for multilevel inheritance in Java:</p><pre>Class A{<br>---<br>}<br>Class B extends A{<br>---<br>}<br>Class C extends B{<br>---<br>}</pre><h4>Hierarchical Inheritance:</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*-LgjwEdjUDBIWW-o.png" /></figure><p>When a class has more than one child class (subclasses) or in other words, more than one child classes have the same parent class, then such kind of inheritance is known as <strong>hierarchical</strong>.</p><p>If we talk about the flowchart, classes B and C are the child classes that are inherited from the parent class i.e Class A.</p><p>Let’s see the syntax for hierarchical inheritance in Java:</p><pre>Class A{<br>---<br>}<br>Class B extends A{<br>---<br>}<br>Class C extends A{<br>---<br>}</pre><h4>Hybrid Inheritance:</h4><p>Hybrid<strong> </strong>inheritance is a combination of <em>multiple </em>inheritance and <em>multilevel</em> inheritance. Since multiple inheritances are not supported in Java as it leads to ambiguity, so this type of inheritance can only be achieved through the use of the interfaces.</p><p>If we talk about the flowchart, class A is a parent class for class B and C, whereas Class B and C are the parent class of D which is the only child class of B and C.</p><p>Now we have learned about inheritance and its different types. Let’s switch to another object-oriented programming concept i.e <strong>Encapsulation</strong>.</p><h4>Encapsulation</h4><p>Encapsulation is a mechanism where you bind your data and code together as a single unit. It also means hiding your data in order to make it safe from any modification. What does this mean? The best way to understand encapsulation is to look at the example of a medical capsule, where the drug is always safe inside the capsule. Similarly, through encapsulation, the methods and variables of a class are well hidden and safe.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*UuSXreyAdtHRTCfi.png" /><figcaption>Encapsulation in Java — Object Oriented Programming</figcaption></figure><p><strong><em>We can achieve encapsulation in Java by:</em></strong></p><ul><li>Declaring the variables of a class as private.</li><li>Providing public setter and getter methods to modify and view the values of the variables.</li></ul><p>Let us look at the code below to get a better understanding of encapsulation:</p><pre>public class Employee {<br> private String name;<br> public String getName() {<br> return name;<br> }<br> public void setName(String name) {<br> this.name = name;<br> }<br> public static void main(String[] args) {<br> }<br>}</pre><p>Let us try to understand the above code. I have created a class Employee which has a private variable <strong>name. </strong>We have then created a <strong>getter</strong> and <strong>setter method</strong> through which we can get and set the name of an employee. Through these methods, any class which wishes to access the name variable has to do it using these getter and setter methods.</p><p>Let’s move forward to our third Object-oriented programming concept i.e. <strong>Abstraction</strong>.</p><h4>Abstraction</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/192/0*JcjNn3IOQqo3pss2.png" /></figure><p>Abstraction refers to the quality of dealing with ideas rather than events. It basically deals with hiding the details and showing the essential things to the user. If you look at the image here, whenever we get a call, we get an option to either pick it up or just reject it. But in reality, there is a lot of code that runs in the background. So you don’t know the internal processing of how a call is generated, that’s the beauty of abstraction. Therefore, abstraction helps to reduce complexity.</p><h4>Polymorphism</h4><p>Polymorphism means taking many forms, where ‘<strong>poly</strong>’ means many and ‘morph’ means forms. It is the ability of a variable, function, or object to take on multiple forms. In other words, polymorphism allows you to define one interface or method and have multiple implementations.</p><p>Let’s understand this by taking a real-life example and how this concept fits into Object-oriented programming.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/654/1*e31cOSFAsgXx3IfvmKvU2Q.png" /></figure><p>Let’s consider this real-world scenario in cricket, we know that there are different types of bowlers i.e. Fast bowlers, Medium pace bowlers and spinners. As you can see in the above figure, there is a parent class- <strong>BowlerClass</strong> and it has three child classes: <strong>FastPacer</strong>, <strong>MediumPacer, </strong>and <strong>Spinner</strong>. Bowler class has <strong>bowlingMethod()</strong> where all the child classes are inheriting this method. As we all know that a fast bowler will be going to bowl differently as compared to medium pacer and spinner in terms of bowling speed, long run up and way of bowling, etc. Similarly, a medium pacer’s implementation of <strong>bowlingMethod()</strong> is also going to be different as compared to other bowlers. And the same happens with spinner class.</p><p>The point of the above discussion is simply that the same name tends to multiple forms. All the three classes above inherited the <strong>bowlingMethod()</strong> but their implementation is totally different from one another.</p><p><strong><em>Polymorphism in Java is of two types:</em></strong></p><ol><li>Runtime polymorphism</li><li>Compile time polymorphism</li></ol><h4>Runtime Polymorphism:</h4><p>In Java, runtime polymorphism refers to a process in which a call to an overridden method is resolved at runtime rather than at compile-time. In this, a reference variable is used to call an overridden method of a superclass at runtime. Method overriding is an example of runtime polymorphism. Let us look the following code to understand how the method overriding works:</p><pre>public Class BowlerClass{<br>void bowlingMethod()<br>{<br>System.out.println(&quot; bowler &quot;);<br>}<br>public Class FastPacer{<br>void bowlingMethod()<br>{<br>System.out.println(&quot; fast bowler &quot;);<br>}<br>Public static void main(String[] args)<br>{<br>FastPacer obj= new FastPacer();<br>obj.bowlingMethod();<br>}<br>}</pre><h4>Compile Time Polymorphism:</h4><p>In Java, compile-time polymorphism refers to a process in which a call to an overloaded method is resolved at compile time rather than at runtime. Method overloading is an example of compile time polymorphism.<strong> </strong>Method Overloading is a feature that allows a class to have two or more methods having the same name but the arguments passed to the methods are different.</p><p><strong><em>Unlike method overriding, arguments can differ in:</em></strong></p><ol><li>Number of parameters passed to a method</li><li>Datatype of parameters</li><li>The sequence of datatypes when passed to a method.</li></ol><p>Let us look at the following code to understand how the method overloading works:</p><pre>class Adder {<br>Static int add(int a, int b)<br>{<br>return a+b;<br>}<br>static double add( double a, double b)<br>{<br>return a+b;<br>}<br> <br>public static void main(String args[])<br>{<br>System.out.println(Adder.add(11,11));<br>System.out.println(Adder.add(12.3,12.6));<br>}<br>}</pre><p>Thankyou for reading the article &amp; having time here.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5713714d3bfe" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Java coding Standards & coding Conventions]]></title>
            <link>https://medium.com/@shyam1.ss15/java-coding-standards-coding-conventions-ea1661eb67fb?source=rss-757c5cce89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ea1661eb67fb</guid>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[java]]></category>
            <category><![CDATA[refactoring]]></category>
            <dc:creator><![CDATA[Shyam Kachhadiya]]></dc:creator>
            <pubDate>Mon, 15 Aug 2022 13:22:53 GMT</pubDate>
            <atom:updated>2022-08-15T13:22:53.814Z</atom:updated>
            <content:encoded><![CDATA[<p>Java is one of the most popular and widely used programming languages and platforms, thus the code will be readed by multiple peoples, so it’s atmost necessary that the code must be readable &amp; understandable from junior developers to senior developers.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/327/1*9QLSBQzli-cHt9aeBTh0QA.jpeg" /><figcaption>Golden words from Martin fowler</figcaption></figure><p>Our Goal is to write code such a way that end reader reads only minimal code &amp; understands it fully. such practises require some knowledge of coding standards &amp; conventions mentioned below.</p><h3>Why Coding Guidelines?</h3><p>The coding guidelines are important because most of the software cost goes towards maintenance. And also, the software is not always developed by a single developer. Therefore, maintaining a convention for writing software increases the readability of the program.</p><ol><li><a href="https://www.geeksforgeeks.org/java-naming-conventions/"><strong>Naming Conventions</strong></a><strong>: </strong>We generally follow the camel case convention in java programming.</li></ol><ul><li>Method names should start with small letters.</li><li>Method names are usually verbs.</li><li>If method contains multiple words, every inner word should start with uppercase letter. Ex : toString()</li><li>Method name must be combination of verb and noun Ex : getCarName(),getCarNumber()</li><li><strong>Curly Braces:</strong> Curly braces are used to define the bodies of classes, methods, and loops. There are two standard formats for the usage of curly braces, either of which is used.</li><li>No blank lines should be present after the opening brace or before the closing brace.</li></ul><pre>class MountBlue{<br>   ... MountBlue(){<br>    // Constructor<br>       ...<br>   }<br><br>   int Mountainain(int a, float b){<br>   <br>       ... for (int i = 0; i &lt; Field; i++){<br>           ....<br>       }<br>   }<br>}</pre><ul><li>A curly brace is applied at the end of the line that starts the class, method, loop, etc., and the closing brace is on a line by itself.<br>Each curly brace is added on a new line, and the pair is aligned vertically.</li></ul><p><strong>2. Indentation:</strong> The unit of indentation should be 4 spaces &amp; 8 tabs.</p><ul><li>Apply indentation to alike items in a vertical list (such as end-of-line comments, and identifiers in declarations).</li><li>Surround the binary operators (including assignment) by spaces.</li><li>Follow a semicolon or comma by a space.</li><li>Add a space between a keyword(“if”, “while”, “return”, “catch”, “switch”, “for”) and a succeeding parenthesis.</li><li>Insert blank lines to differentiate between the important parts of the code.</li></ul><p><strong>3. White Space:</strong> White spaces also play a major part in readability as follows:</p><ul><li><a href="https://www.geeksforgeeks.org/operators-in-java/">Operators</a> should be surrounded by a space character.</li></ul><pre><em>The operation should be written as: <br></em><strong><em>a = (b + c) * d;</em></strong><em><br>And not as: <br></em><strong><em>a=(b+c)*d</em></strong></pre><ul><li><a href="https://www.geeksforgeeks.org/list-of-all-java-keywords/">Reserved words of Java</a> should be followed by white space. For example:</li></ul><pre>The loop must be initialized as: <br>while (true) {…} <br>And not as: <br>while(true){…}</pre><ul><li>Commas should be followed by white space. For example:</li></ul><pre>The functions must be initialized as: <br>fun(a, b, c, d); <br>And not as: <br>fun(a, b, c, d);</pre><ul><li>Colons should be surrounded by white space. For example:</li></ul><pre>The case statements must be initialized as: <br>case 100 : break; <br>And not as: <br>case 100:break;</pre><ul><li><a href="https://www.geeksforgeeks.org/role-of-semicolon-in-various-programming-languages/">Semicolons</a> in for statements should be followed by a space character. For example:</li></ul><pre>The for loop must be initialized as: <br>for (i = 0; i &lt; n; i++) <br>And not as: <br>for(i=0;i&lt;n;i++)</pre><p><a href="https://www.geeksforgeeks.org/comments-in-java/"><strong>5.Comments</strong></a><strong>:</strong> Java programs can have two types of comments.</p><ul><li><strong>Implementation Comments:</strong> Implementation comments are delimited by <strong>//</strong>. Java also allows the use of /*…*/ for implementation comments.</li><li><strong>Block comments</strong> are used to provide descriptions of files, methods, data structures, and algorithms.</li><li><strong>Single-line comments</strong> can appear on a single line indented to the level of the code that follows. If a comment can not be written in a single line, it should follow the block comment format.</li><li><strong>Trailing(very short) comments</strong> can appear on the same line of the code they describe but should be separated from the code at a far off distance.</li><li><strong>Documentation Comments:</strong> Documentation comments describe <a href="https://www.geeksforgeeks.org/classes-objects-java/">Java classes</a>, <a href="https://www.geeksforgeeks.org/interfaces-in-java/">interfaces</a>, <a href="https://www.geeksforgeeks.org/constructors-in-java/">constructors</a>, <a href="https://www.geeksforgeeks.org/methods-in-java/">methods</a>, and fields. They are delimited by <strong>/**…*/</strong>. Note the double-asterisk (**) at the beginning with one comment per class, interface, or member. This comment should appear just before the declaration with no space between the comment and the code it refers to. Documentation comments can be extracted to HTML files using the <em>javadoc</em> tool.</li></ul><pre><em>/** This is a java documentation comment */<br>private int comments_;</em></pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ea1661eb67fb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Learning Git with awesomeness]]></title>
            <link>https://medium.com/@shyam1.ss15/learning-git-with-awesomeness-6f20b0bdbedc?source=rss-757c5cce89c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/6f20b0bdbedc</guid>
            <category><![CDATA[development]]></category>
            <category><![CDATA[learning-to-code]]></category>
            <category><![CDATA[git]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[github]]></category>
            <dc:creator><![CDATA[Shyam Kachhadiya]]></dc:creator>
            <pubDate>Sun, 07 Aug 2022 10:49:57 GMT</pubDate>
            <atom:updated>2022-08-07T10:49:57.973Z</atom:updated>
            <content:encoded><![CDATA[<p>Well Learning Git is hard &amp; playing with it is even harder, so let’s learn it for our daily tasks.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7Tyg4rTjW8MgkJDTZFmCZA.png" /></figure><p>This article will cover your basics &amp; make you capable to start working with git. okay, so let’s start from beggining, what is git? why is it used for? Git is a version control system used in software development,well git is invented to help group of developers to collabrate &amp; track all the changes made to files &amp; feature, okay let’s say you are a senior developer also you have made an photo editing feature on your app &amp; One of your friend has made video editing feature, well now how can you merge your features in your app ???</p><p>Here comes the git, you &amp; your friend will share your code in cloud &amp; the coded files will be merged.</p><p>okay, enough talking let’s make our hands dirty by installing git &amp; sync login details with github, please follow this youtube tutorial <a href="https://www.youtube.com/watch?v=xEZ5cvm5Stk&amp;ab_channel=SoftwareTestingMentor"><strong>(click me)</strong></a> &amp; come back here after installation.</p><h4>Let’s Get Started</h4><p>Some terminologies for better understanding<br><strong>Repositories AKA. Repo: </strong>It is a place where all your codes will stay on cloud/ Github.<br><strong>Local Repo &amp; Remote Repo: </strong>Both this Repos work in sync, they communicate with each other using some magical commands discussed below, say you are done with your feature &amp; you want to share that feature to team then you have to first save code Local Repo then send it to Remote Repo.<br><strong>Commit: </strong>We do this very often when we want to save some feature or import bug has been solved this well help us know at what stage the project &amp; code saved.<br><strong>.gitignore: </strong>This is an file where you can specify whom to ignore files to be shared on git/ github. I mean some files where our credentials resides should not be on cloud right, so the files or folders should be mentioned in .gitignore file, which will be ignored by git<br><strong>git init: </strong>This command will initialize git in working directory<strong><br>Staging area: </strong>The Files are ready to be commited are staying on stagin area, it can be acheived using.<br><strong>Git Branches: </strong>Branches are used to seperate the developement of projects, say feature/video-editing branch &amp; feature/audio-editing branch.</p><pre>git init <br>echo &quot;##My cool project&quot; &gt; README.md<br>git add .</pre><p>upto this stage we have added all our files to staging area, Now let’s commit it</p><pre>git commit -m &quot;This is my first commit msg&quot;</pre><p>Okay, upto this point you have learned the basic usage of git &amp; how to work locally, now let’s go remote &amp; work with it.<br>Let’s download github desktop application to work smoothly with git <a href="https://desktop.github.com/"><strong>(download github desktop)</strong></a>. <br>Try resolving all the login process and complete the installation setup with your github account and you are good to go.</p><p>Using git desktop you can manage all the work with git so easily.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/788/1*SmRTOTWjWJU3UzLO121BRw.jpeg" /><figcaption>Creating new repository using git desktop</figcaption></figure><p>well let’s create an repo using git desktop &amp; then push it to the remote, yes it’s that simple &amp; your repo will be created and your commits from desktop or cli will be saved in remote repo.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SVk8nsA6p3_tOhqNjdBJqg.png" /><figcaption>Push local commits to remote repo</figcaption></figure><p>Thankyou for learning git for it’s daily usage, you can now play more with git for daily usage, also if you want to learn more you can try here with <a href="https://learngitbranching.js.org/"><strong>learngitbranching click me</strong></a><strong>.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6f20b0bdbedc" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>