<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: akhilreddy0401</title>
    <description>The latest articles on DEV Community by akhilreddy0401 (@akhilreddy0401).</description>
    <link>https://dev.to/akhilreddy0401</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F627115%2Fcb6b2135-beda-4486-98d1-92e1fdd8c38f.png</url>
      <title>DEV Community: akhilreddy0401</title>
      <link>https://dev.to/akhilreddy0401</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/akhilreddy0401"/>
    <language>en</language>
    <item>
      <title>Inheritance in Java</title>
      <dc:creator>akhilreddy0401</dc:creator>
      <pubDate>Mon, 25 Oct 2021 15:05:04 +0000</pubDate>
      <link>https://dev.to/akhilreddy0401/inheritance-in-java-49n4</link>
      <guid>https://dev.to/akhilreddy0401/inheritance-in-java-49n4</guid>
      <description>&lt;p&gt;Inheritance is an important pillar of OOP(Object-Oriented Programming). It is the mechanism in java by which one class is allowed to inherit the features(fields and methods) of another class. &lt;/p&gt;

&lt;p&gt;Important terminology: &lt;/p&gt;

&lt;p&gt;Super Class: The class whose features are inherited is known as superclass(or a base class or a parent class).&lt;br&gt;
Sub Class: The class that inherits the other class is known as a subclass(or a derived class, extended class, or child class). The subclass can add its own fields and methods in addition to the superclass fields and methods.&lt;br&gt;
Reusability: Inheritance supports the concept of “reusability”, i.e. when we want to create a new class and there is already a class that includes some of the code that we want, we can derive our new class from the existing class. By doing this, we are reusing the fields and methods of the existing class.&lt;br&gt;
How to use inheritance in Java&lt;/p&gt;

&lt;p&gt;The keyword used for inheritance is extends. &lt;/p&gt;

&lt;p&gt;Syntax : &lt;/p&gt;

&lt;p&gt;class derived-class extends base-class&lt;br&gt;&lt;br&gt;
{&lt;br&gt;&lt;br&gt;
   //methods and fields&lt;br&gt;&lt;br&gt;
}&lt;br&gt;&lt;br&gt;
Example:&lt;br&gt;
 In the below example of inheritance, class Bicycle is a base class, class MountainBike is a derived class that extends Bicycle class and class Test is a driver class to run program. &lt;/p&gt;

&lt;p&gt;Java&lt;br&gt;
// Java program to illustrate the&lt;br&gt;
// concept of inheritance&lt;/p&gt;

&lt;p&gt;// base class&lt;/p&gt;

&lt;p&gt;class Bicycle {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// the Bicycle class has two fields

public int gear;

public int speed;


// the Bicycle class has one constructor

public Bicycle(int gear, int speed)

{

    this.gear = gear;

    this.speed = speed;

}


// the Bicycle class has three methods

public void applyBrake(int decrement)

{

    speed -= decrement;

}


public void speedUp(int increment)

{

    speed += increment;

}


// toString() method to print info of Bicycle

public String toString()

{

    return ("No of gears are " + gear + "\n"

            + "speed of bicycle is " + speed);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;// derived class&lt;/p&gt;

&lt;p&gt;class MountainBike extends Bicycle {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// the MountainBike subclass adds one more field

public int seatHeight;


// the MountainBike subclass has one constructor

public MountainBike(int gear, int speed,

                    int startHeight)

{

    // invoking base-class(Bicycle) constructor

    super(gear, speed);

    seatHeight = startHeight;

}


// the MountainBike subclass adds one more method

public void setHeight(int newValue)

{

    seatHeight = newValue;

}


// overriding toString() method

// of Bicycle to print more info

@Override public String toString()

{

    return (super.toString() + "\nseat height is "

            + seatHeight);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;// driver class&lt;/p&gt;

&lt;p&gt;public class Test {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public static void main(String args[])

{


    MountainBike mb = new MountainBike(3, 100, 25);

    System.out.println(mb.toString());

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
Output&lt;br&gt;
No of gears are 3&lt;br&gt;
speed of bicycle is 100&lt;br&gt;
seat height is 25&lt;br&gt;
In the above program, when an object of MountainBike class is created, a copy of all methods and fields of the superclass acquire memory in this object. That is why by using the object of the subclass we can also access the members of a superclass.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Stacks:</title>
      <dc:creator>akhilreddy0401</dc:creator>
      <pubDate>Fri, 07 May 2021 11:09:35 +0000</pubDate>
      <link>https://dev.to/akhilreddy0401/stacks-12la</link>
      <guid>https://dev.to/akhilreddy0401/stacks-12la</guid>
      <description>&lt;p&gt;A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc.&lt;/p&gt;

&lt;p&gt;Stack Example&lt;br&gt;
A real-world stack allows operations at one end only. For example, we can place or remove a card or plate from the top of the stack only. Likewise, Stack ADT allows all data operations at one end only. At any given time, we can only access the top element of a stack.&lt;/p&gt;

&lt;p&gt;This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element which is placed (inserted or added) last, is accessed first. In stack terminology, insertion operation is called PUSH operation and removal operation is called POP operation.&lt;/p&gt;

&lt;p&gt;Stack Representation&lt;br&gt;
The following diagram depicts a stack and its operations −&lt;/p&gt;

&lt;p&gt;Stack Representation&lt;br&gt;
A stack can be implemented by means of Array, Structure, Pointer, and Linked List. Stack can either be a fixed size one or it may have a sense of dynamic resizing. Here, we are going to implement stack using arrays, which makes it a fixed size stack implementation.&lt;/p&gt;

&lt;p&gt;Basic Operations&lt;br&gt;
Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations −&lt;/p&gt;

&lt;p&gt;push() − Pushing (storing) an element on the stack.&lt;/p&gt;

&lt;p&gt;pop() − Removing (accessing) an element from the stack.&lt;/p&gt;

&lt;p&gt;When data is PUSHed onto stack.&lt;/p&gt;

&lt;p&gt;To use a stack efficiently, we need to check the status of stack as well. For the same purpose, the following functionality is added to stacks −&lt;/p&gt;

&lt;p&gt;peek() − get the top data element of the stack, without removing it.&lt;/p&gt;

&lt;p&gt;isFull() − check if stack is full.&lt;/p&gt;

&lt;p&gt;isEmpty() − check if stack is empty.&lt;/p&gt;

&lt;p&gt;At all times, we maintain a pointer to the last PUSHed data on the stack. As this pointer always represents the top of the stack, hence named top. The top pointer provides top value of the stack without actually removing it.&lt;/p&gt;

&lt;p&gt;First we should learn about procedures to support stack functions −&lt;/p&gt;

&lt;p&gt;peek()&lt;br&gt;
Algorithm of peek() function −&lt;/p&gt;

&lt;p&gt;begin procedure peek&lt;br&gt;
return stack[top]&lt;br&gt;
end procedure&lt;br&gt;
Implementation of peek() function in C programming language −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;int peek() {&lt;br&gt;
return stack[top];&lt;br&gt;
}&lt;br&gt;
isfull()&lt;br&gt;
Algorithm of isfull() function −&lt;/p&gt;

&lt;p&gt;begin procedure isfull&lt;/p&gt;

&lt;p&gt;if top equals to MAXSIZE&lt;br&gt;
return true&lt;br&gt;
else&lt;br&gt;
return false&lt;br&gt;
endif&lt;/p&gt;

&lt;p&gt;end procedure&lt;br&gt;
Implementation of isfull() function in C programming language −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;bool isfull() {&lt;br&gt;
if(top == MAXSIZE)&lt;br&gt;
return true;&lt;br&gt;
else&lt;br&gt;
return false;&lt;br&gt;
}&lt;br&gt;
isempty()&lt;br&gt;
Algorithm of isempty() function −&lt;/p&gt;

&lt;p&gt;begin procedure isempty&lt;/p&gt;

&lt;p&gt;if top less than 1&lt;br&gt;
return true&lt;br&gt;
else&lt;br&gt;
return false&lt;br&gt;
endif&lt;/p&gt;

&lt;p&gt;end procedure&lt;br&gt;
Implementation of isempty() function in C programming language is slightly different. We initialize top at -1, as the index in array starts from 0. So we check if the top is below zero or -1 to determine if the stack is empty. Here's the code −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;bool isempty() {&lt;br&gt;
if(top == -1)&lt;br&gt;
return true;&lt;br&gt;
else&lt;br&gt;
return false;&lt;br&gt;
}&lt;br&gt;
Push Operation&lt;br&gt;
The process of putting a new data element onto stack is known as a Push Operation. Push operation involves a series of steps −&lt;/p&gt;

&lt;p&gt;Step 1 − Checks if the stack is full.&lt;/p&gt;

&lt;p&gt;Step 2 − If the stack is full, produces an error and exit.&lt;/p&gt;

&lt;p&gt;Step 3 − If the stack is not full, increments top to point next empty space.&lt;/p&gt;

&lt;p&gt;Step 4 − Adds data element to the stack location, where top is pointing.&lt;/p&gt;

&lt;p&gt;Step 5 − Returns success.&lt;/p&gt;

&lt;p&gt;Stack Push Operation&lt;br&gt;
If the linked list is used to implement the stack, then in step 3, we need to allocate space dynamically.&lt;/p&gt;

&lt;p&gt;Algorithm for PUSH Operation&lt;br&gt;
A simple algorithm for Push operation can be derived as follows −&lt;/p&gt;

&lt;p&gt;begin procedure push: stack, data&lt;/p&gt;

&lt;p&gt;if stack is full&lt;br&gt;
return null&lt;br&gt;
endif&lt;/p&gt;

&lt;p&gt;top ← top + 1&lt;br&gt;
stack[top] ← data&lt;/p&gt;

&lt;p&gt;end procedure&lt;br&gt;
Implementation of this algorithm in C, is very easy. See the following code −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;void push(int data) {&lt;br&gt;
if(!isFull()) {&lt;br&gt;
top = top + 1;&lt;/p&gt;

&lt;p&gt;stack[top] = data;&lt;br&gt;
} else {&lt;br&gt;
printf("Could not insert data, Stack is full.\n");&lt;br&gt;
}&lt;br&gt;
}&lt;br&gt;
Pop Operation&lt;br&gt;
Accessing the content while removing it from the stack, is known as a Pop Operation. In an array implementation of pop() operation, the data element is not actually removed, instead top is decremented to a lower position in the stack to point to the next value. But in linked-list implementation, pop() actually removes data element and deallocates memory space.&lt;/p&gt;

&lt;p&gt;A Pop operation may involve the following steps −&lt;/p&gt;

&lt;p&gt;Step 1 − Checks if the stack is empty.&lt;/p&gt;

&lt;p&gt;Step 2 − If the stack is empty, produces an error and exit.&lt;/p&gt;

&lt;p&gt;Step 3 − If the stack is not empty, accesses the data element at which top is pointing.&lt;/p&gt;

&lt;p&gt;Step 4 − Decreases the value of top by 1.&lt;/p&gt;

&lt;p&gt;Step 5 − Returns success.&lt;/p&gt;

&lt;p&gt;Stack Pop Operation&lt;br&gt;
Algorithm for Pop Operation&lt;br&gt;
A simple algorithm for Pop operation can be derived as follows −&lt;/p&gt;

&lt;p&gt;begin procedure pop: stack&lt;/p&gt;

&lt;p&gt;if stack is empty&lt;br&gt;
return null&lt;br&gt;
endif&lt;/p&gt;

&lt;p&gt;data ← stack[top]&lt;br&gt;
top ← top - 1&lt;br&gt;
return data&lt;/p&gt;

&lt;p&gt;end procedure&lt;br&gt;
Implementation of this algorithm in C, is as follows −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;int pop(int data) {&lt;/p&gt;

&lt;p&gt;if(!isempty()) {&lt;br&gt;
data = stack[top];&lt;br&gt;
top = top - 1;&lt;/p&gt;

&lt;p&gt;return data;&lt;br&gt;
} else {&lt;br&gt;
printf("Could not retrieve data, Stack is empty.\n");&lt;br&gt;
}&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>pushercontest</category>
      <category>pull</category>
    </item>
    <item>
      <title>Stacks:</title>
      <dc:creator>akhilreddy0401</dc:creator>
      <pubDate>Fri, 07 May 2021 11:03:39 +0000</pubDate>
      <link>https://dev.to/akhilreddy0401/stacks-32ln</link>
      <guid>https://dev.to/akhilreddy0401/stacks-32ln</guid>
      <description>&lt;p&gt;A stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc.&lt;/p&gt;

&lt;p&gt;Stack Example&lt;br&gt;
A real-world stack allows operations at one end only. For example, we can place or remove a card or plate from the top of the stack only. Likewise, Stack ADT allows all data operations at one end only. At any given time, we can only access the top element of a stack.&lt;/p&gt;

&lt;p&gt;This feature makes it LIFO data structure. LIFO stands for Last-in-first-out. Here, the element which is placed (inserted or added) last, is accessed first. In stack terminology, insertion operation is called PUSH operation and removal operation is called POP operation.&lt;/p&gt;

&lt;p&gt;Stack Representation&lt;br&gt;
The following diagram depicts a stack and its operations −&lt;/p&gt;

&lt;p&gt;Stack Representation&lt;br&gt;
A stack can be implemented by means of Array, Structure, Pointer, and Linked List. Stack can either be a fixed size one or it may have a sense of dynamic resizing. Here, we are going to implement stack using arrays, which makes it a fixed size stack implementation.&lt;/p&gt;

&lt;p&gt;Basic Operations&lt;br&gt;
Stack operations may involve initializing the stack, using it and then de-initializing it. Apart from these basic stuffs, a stack is used for the following two primary operations −&lt;/p&gt;

&lt;p&gt;push() − Pushing (storing) an element on the stack.&lt;/p&gt;

&lt;p&gt;pop() − Removing (accessing) an element from the stack.&lt;/p&gt;

&lt;p&gt;When data is PUSHed onto stack.&lt;/p&gt;

&lt;p&gt;To use a stack efficiently, we need to check the status of stack as well. For the same purpose, the following functionality is added to stacks −&lt;/p&gt;

&lt;p&gt;peek() − get the top data element of the stack, without removing it.&lt;/p&gt;

&lt;p&gt;isFull() − check if stack is full.&lt;/p&gt;

&lt;p&gt;isEmpty() − check if stack is empty.&lt;/p&gt;

&lt;p&gt;At all times, we maintain a pointer to the last PUSHed data on the stack. As this pointer always represents the top of the stack, hence named top. The top pointer provides top value of the stack without actually removing it.&lt;/p&gt;

&lt;p&gt;First we should learn about procedures to support stack functions −&lt;/p&gt;

&lt;p&gt;peek()&lt;br&gt;
Algorithm of peek() function −&lt;/p&gt;

&lt;p&gt;begin procedure peek&lt;br&gt;
   return stack[top]&lt;br&gt;
end procedure&lt;br&gt;
Implementation of peek() function in C programming language −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;int peek() {&lt;br&gt;
   return stack[top];&lt;br&gt;
}&lt;br&gt;
isfull()&lt;br&gt;
Algorithm of isfull() function −&lt;/p&gt;

&lt;p&gt;begin procedure isfull&lt;/p&gt;

&lt;p&gt;if top equals to MAXSIZE&lt;br&gt;
      return true&lt;br&gt;
   else&lt;br&gt;
      return false&lt;br&gt;
   endif&lt;/p&gt;

&lt;p&gt;end procedure&lt;br&gt;
Implementation of isfull() function in C programming language −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;bool isfull() {&lt;br&gt;
   if(top == MAXSIZE)&lt;br&gt;
      return true;&lt;br&gt;
   else&lt;br&gt;
      return false;&lt;br&gt;
}&lt;br&gt;
isempty()&lt;br&gt;
Algorithm of isempty() function −&lt;/p&gt;

&lt;p&gt;begin procedure isempty&lt;/p&gt;

&lt;p&gt;if top less than 1&lt;br&gt;
      return true&lt;br&gt;
   else&lt;br&gt;
      return false&lt;br&gt;
   endif&lt;/p&gt;

&lt;p&gt;end procedure&lt;br&gt;
Implementation of isempty() function in C programming language is slightly different. We initialize top at -1, as the index in array starts from 0. So we check if the top is below zero or -1 to determine if the stack is empty. Here's the code −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;bool isempty() {&lt;br&gt;
   if(top == -1)&lt;br&gt;
      return true;&lt;br&gt;
   else&lt;br&gt;
      return false;&lt;br&gt;
}&lt;br&gt;
Push Operation&lt;br&gt;
The process of putting a new data element onto stack is known as a Push Operation. Push operation involves a series of steps −&lt;/p&gt;

&lt;p&gt;Step 1 − Checks if the stack is full.&lt;/p&gt;

&lt;p&gt;Step 2 − If the stack is full, produces an error and exit.&lt;/p&gt;

&lt;p&gt;Step 3 − If the stack is not full, increments top to point next empty space.&lt;/p&gt;

&lt;p&gt;Step 4 − Adds data element to the stack location, where top is pointing.&lt;/p&gt;

&lt;p&gt;Step 5 − Returns success.&lt;/p&gt;

&lt;p&gt;Stack Push Operation&lt;br&gt;
If the linked list is used to implement the stack, then in step 3, we need to allocate space dynamically.&lt;/p&gt;

&lt;p&gt;Algorithm for PUSH Operation&lt;br&gt;
A simple algorithm for Push operation can be derived as follows −&lt;/p&gt;

&lt;p&gt;begin procedure push: stack, data&lt;/p&gt;

&lt;p&gt;if stack is full&lt;br&gt;
      return null&lt;br&gt;
   endif&lt;/p&gt;

&lt;p&gt;top ← top + 1&lt;br&gt;
   stack[top] ← data&lt;/p&gt;

&lt;p&gt;end procedure&lt;br&gt;
Implementation of this algorithm in C, is very easy. See the following code −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;void push(int data) {&lt;br&gt;
   if(!isFull()) {&lt;br&gt;
      top = top + 1;&lt;br&gt;&lt;br&gt;
      stack[top] = data;&lt;br&gt;
   } else {&lt;br&gt;
      printf("Could not insert data, Stack is full.\n");&lt;br&gt;
   }&lt;br&gt;
}&lt;br&gt;
Pop Operation&lt;br&gt;
Accessing the content while removing it from the stack, is known as a Pop Operation. In an array implementation of pop() operation, the data element is not actually removed, instead top is decremented to a lower position in the stack to point to the next value. But in linked-list implementation, pop() actually removes data element and deallocates memory space.&lt;/p&gt;

&lt;p&gt;A Pop operation may involve the following steps −&lt;/p&gt;

&lt;p&gt;Step 1 − Checks if the stack is empty.&lt;/p&gt;

&lt;p&gt;Step 2 − If the stack is empty, produces an error and exit.&lt;/p&gt;

&lt;p&gt;Step 3 − If the stack is not empty, accesses the data element at which top is pointing.&lt;/p&gt;

&lt;p&gt;Step 4 − Decreases the value of top by 1.&lt;/p&gt;

&lt;p&gt;Step 5 − Returns success.&lt;/p&gt;

&lt;p&gt;Stack Pop Operation&lt;br&gt;
Algorithm for Pop Operation&lt;br&gt;
A simple algorithm for Pop operation can be derived as follows −&lt;/p&gt;

&lt;p&gt;begin procedure pop: stack&lt;/p&gt;

&lt;p&gt;if stack is empty&lt;br&gt;
      return null&lt;br&gt;
   endif&lt;/p&gt;

&lt;p&gt;data ← stack[top]&lt;br&gt;
   top ← top - 1&lt;br&gt;
   return data&lt;/p&gt;

&lt;p&gt;end procedure&lt;br&gt;
Implementation of this algorithm in C, is as follows −&lt;/p&gt;

&lt;p&gt;Example&lt;/p&gt;

&lt;p&gt;int pop(int data) {&lt;/p&gt;

&lt;p&gt;if(!isempty()) {&lt;br&gt;
      data = stack[top];&lt;br&gt;
      top = top - 1;&lt;br&gt;&lt;br&gt;
      return data;&lt;br&gt;
   } else {&lt;br&gt;
      printf("Could not retrieve data, Stack is empty.\n");&lt;br&gt;
   }&lt;br&gt;
}&lt;/p&gt;

</description>
      <category>pushercontest</category>
      <category>pull</category>
    </item>
  </channel>
</rss>
