<?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: Supriya Kolhe</title>
    <description>The latest articles on DEV Community by Supriya Kolhe (@supriya2371997).</description>
    <link>https://dev.to/supriya2371997</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%2F449507%2Ff2247908-c409-4ac4-a9af-25819ad77fe4.png</url>
      <title>DEV Community: Supriya Kolhe</title>
      <link>https://dev.to/supriya2371997</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/supriya2371997"/>
    <language>en</language>
    <item>
      <title>C : Jump Statements</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Mon, 15 Mar 2021 18:06:21 +0000</pubDate>
      <link>https://dev.to/supriya2371997/c-jump-statements-5b8k</link>
      <guid>https://dev.to/supriya2371997/c-jump-statements-5b8k</guid>
      <description>&lt;ol&gt;
&lt;li&gt;What are jump statements?&lt;/li&gt;
&lt;li&gt;Types (Break, Continue, GoTo, Return)&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;1.&lt;strong&gt;What are jump statements :-&lt;/strong&gt; Jump statements are used to interrupt the normal flow of program. They makes the control jump to another section of the program when encountered. It is usually used to terminate the loop or switch-case instantly. It is also used to escape the execution of a section of the program.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Break :&lt;/strong&gt;&lt;br&gt;
-&amp;gt;Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;break;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;The break statement is also used with if...else statement inside the loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
int main() 
{
int num = 5;
while (num &amp;gt; 0) 
  {
  if (num == 3)
    break;
  printf("%d\n", num);
  num--;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Continue :&lt;/strong&gt; The continue statement skips the current iteration of the loop and continues with the next iteration. Its syntax is:
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;continue;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;The continue statement is almost always used with the if...else statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
int main() 
{
int nb = 7;
while (nb &amp;gt; 0) 
{
  nb--;
  if (nb == 5)
    continue;
 printf("%d\n", nb);
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Go to:&lt;/strong&gt;
-&amp;gt;Transfers control to the labeled statement.
-&amp;gt;The label is an identifier. When the goto statement is encountered, the control of the program jumps to label: and starts executing the code.
-&amp;gt;Here label can be any plain text except C keyword and it can be set anywhere in the C program above or below to goto statement.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;goto label;
... .. ...
... .. ...
label: 
statement;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example:*/
#include &amp;lt;stdio.h&amp;gt;

int main () {

   int a = 10;
   LOOP:do 
       {
         if( a == 15) 
         {
             a = a + 1;
             goto LOOP;
         }
         printf("value of a: %d\n", a);
         a++;
       }while( a &amp;lt; 20 );
   return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE :&lt;/strong&gt; Use of the goto statement is highly discouraged in any programming language because it makes it difficult to trace the control flow of a program, making the program hard to understand and hard to modify. Any program that uses a goto can be rewritten to avoid them.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Return :&lt;/strong&gt;
-&amp;gt;usually used at the end of a function to end or terminate it with or without a value. 
-&amp;gt;It takes the control from the calling function back to the main function(main function itself can also have a return).
-&amp;gt;return can only be used in functions that is declared with a return type such as int, float, double, char, etc.
-&amp;gt;The functions declared with void type does not return any value. Also, the function returns the value that belongs to the same data type as it is declared.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;return [value/variable];
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example:*/
#include &amp;lt;stdio.h&amp;gt;
char func(int ascii) 
{
  return ((char) ascii);
}
int main() 
{
  int ascii;
  char ch;
  printf("Enter any ascii value in decimal: \n");
  scanf("%d", &amp;amp; ascii);
  ch = func(ascii);
  printf("The character is : %c", ch);
  return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;In this program, we have two functions that have a return type but only one function is returning a value[func()] and the other is just used to terminate the function[main()].&lt;/p&gt;

&lt;p&gt;The function func() is returning the character value of the given number(here 110). We also see that the return type of func() is char because it is returning a character value.&lt;/p&gt;

&lt;p&gt;The return in main() function returns zero because it is necessary to have a return value here because main has been given the return type int.&lt;/p&gt;

</description>
      <category>cpp</category>
      <category>programming</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>C : Loops and Control Statements</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Mon, 15 Mar 2021 17:53:17 +0000</pubDate>
      <link>https://dev.to/supriya2371997/c-loops-aob</link>
      <guid>https://dev.to/supriya2371997/c-loops-aob</guid>
      <description>&lt;ol&gt;
&lt;li&gt;What are loops?&lt;/li&gt;
&lt;li&gt;Types (entry and exit controlled loop)&lt;/li&gt;
&lt;li&gt;What is infinite/endless loop?&lt;/li&gt;
&lt;li&gt;Types of loop constructs (while, do...while, for)&lt;/li&gt;
&lt;li&gt;For loop in more detail&lt;/li&gt;
&lt;li&gt;Nested loop&lt;/li&gt;
&lt;li&gt;What are Loop Control Statements&lt;/li&gt;
&lt;li&gt;Types (break, continue, goto)&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;1.&lt;strong&gt;Loops :&lt;/strong&gt;  Loop executes the sequence of statements many times until the stated condition becomes false. A loop consists of two parts, a body of a loop and a control statement. The control statement is a combination of some conditions that direct the body of the loop to execute until the specified condition becomes false. The purpose of the loop is to repeat the same code a number of times.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Types:&lt;/strong&gt; Depending upon the position of a control statement in a program, looping in C is classified into two types:&lt;br&gt;
2.1 &lt;strong&gt;Entry controlled loop :&lt;/strong&gt; also called as pre-checking loop. A condition is checked before executing the body of a loop. &lt;br&gt;
2.2 &lt;strong&gt;Exit controlled loop :&lt;/strong&gt; also called as post-checking loop. A condition is checked after executing the body of a loop.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--G1FptJiF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9femr1kt3lxqtrfj73i.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G1FptJiF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o9femr1kt3lxqtrfj73i.png" alt="image"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. what is infinite/endless loop?&lt;/strong&gt;&lt;br&gt;
-&amp;gt;The loop that does not stop executing and processes the statements number of times is called as an &lt;strong&gt;"infinite loop"&lt;/strong&gt;. An infinite loop is also called as an &lt;strong&gt;"Endless loop"&lt;/strong&gt;. &lt;br&gt;
-&amp;gt;some characteristics of an infinite loop:&lt;br&gt;
**  No termination condition is specified. **&lt;br&gt;
** The specified conditions never meet. **&lt;br&gt;&lt;br&gt;
-&amp;gt;Thus, to avoid this situation the control conditions must be well defined and specified otherwise the loop will execute an infinite number of times.&lt;br&gt;
-&amp;gt;The for loop is traditionally used for this purpose. Since none of the three expressions that form the 'for' loop is required, you can make an endless loop by leaving the conditional expression empty.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main () 
{
   for( ; ; ) 
   {
      printf("This loop will run forever.\n");
   }

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;4. Types of loop constructs:-&lt;/strong&gt;&lt;br&gt;
4.1 &lt;strong&gt;while:&lt;/strong&gt;&lt;br&gt;
-&amp;gt;It is an entry-controlled loop. In while loop, a condition is evaluated before processing a body of the loop. If a condition is true then and only then the body of a loop is executed. After the body of a loop is executed then control again goes back at the beginning, and the condition is checked if it is true, the same process is executed until the condition becomes false. Once the condition becomes false, the control goes out of the loop.&lt;br&gt;
-&amp;gt;In while loop, if the condition is not true, then the body of a loop will not be executed, not even once.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while (testExpression) 
{
    // the body of the loop 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example: */
#include &amp;lt;stdio.h&amp;gt;
int main()
{
    int i = 1;

    while (i &amp;lt;= 5)
    {
        printf("%d\n", i);
        ++i;
    }

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

&lt;/div&gt;



&lt;p&gt;4.2 &lt;strong&gt;Do while:&lt;/strong&gt;&lt;br&gt;
-&amp;gt;It is more like a while statement, except that it tests the condition at the end of the loop body.&lt;br&gt;
-&amp;gt;it terminates with a semi-colon (;)&lt;br&gt;
-&amp;gt;The body of do...while loop is executed at least once.&lt;br&gt;
-&amp;gt;After the body is executed, then it checks the condition. If the condition is true, then it will again execute the body of a loop otherwise control is transferred out of the loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;do
{
   // the body of the loop
}
while (testExpression);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example: */
#include&amp;lt;stdio.h&amp;gt;
#include&amp;lt;conio.h&amp;gt;
int main()
{
    int num=1;  
    do  
    {
        printf("%d\n",2*num);
        num++;      
    }while(num&amp;lt;=10);
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4.3 &lt;strong&gt;For:&lt;/strong&gt; &lt;br&gt;
-&amp;gt;step1: In this initialization, statement is executed only once. &lt;br&gt;
-&amp;gt;step2: The condition is a Boolean expression that tests and compares the counter to a fixed value after each iteration, stopping the for loop when false is returned.&lt;br&gt;
-&amp;gt;step3: The incrementation/decrementation increases (or decreases) the counter by a set value and again the test expression is evaluated.&lt;br&gt;
-&amp;gt;step4: This process goes on until the test expression is false. When the test expression is false, the loop terminates.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (initial value; condition; incrementation or decrementation ) 
{
  statements;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example:*/
#include&amp;lt;stdio.h&amp;gt;
int main()
{
    int number;
    for(number=1;number&amp;lt;=10;number++)   
    {
        printf("%d\n",number);      
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;5.&lt;strong&gt;For loop in more detail:&lt;/strong&gt;&lt;br&gt;
-&amp;gt;for loop can have multiple expressions separated by commas in each part.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (x = 0, y = num; x &amp;lt; y; i++, y--) { 
  statements; 
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;we can skip the initial value expression, condition and/or increment by adding a semicolon.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int i=0;
int max = 10;
for (; i &amp;lt; max; i++) {
  printf("%d\n", i);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;6.&lt;strong&gt;Nested Loop:-&lt;/strong&gt;using one loop inside another loop.&lt;br&gt;
-&amp;gt;&lt;strong&gt;nested for loop:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for ( init; condition; increment ) {

   for ( init; condition; increment ) {
      statement(s);
   }
   statement(s);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;&lt;strong&gt;nested while loop:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;while(condition) {

   while(condition) {
      statement(s);
   }
   statement(s);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;&lt;strong&gt;nested do while loop:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;do {
   statement(s);

   do {
      statement(s);
   }while( condition );

}while( condition );
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;you can put any type of loop inside any other type of loop. For example, a 'while' loop can be inside a 'for' loop or vice versa.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
int main() {
int i, j;
int table = 2;
int max = 5;
for (i = 1; i &amp;lt;= table; i++) 
{
  for (j = 0; j &amp;lt;= max; j++) 
  { 
    printf("%d x %d = %d\n", i, j, i*j);
  }
  printf("\n");
}
}//main end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE :&lt;/strong&gt; In some versions of 'C,' the nesting is limited up to 15 loops, but some provide more.&lt;/p&gt;

&lt;p&gt;7.&lt;strong&gt;Loop Control Statements :&lt;/strong&gt;change execution from its normal sequence. When execution leaves a scope, all automatic objects that were created in that scope are destroyed.&lt;/p&gt;

&lt;p&gt;8.1 &lt;strong&gt;Break :&lt;/strong&gt;&lt;br&gt;
-&amp;gt;Terminates the loop or switch statement and transfers execution to the statement immediately following the loop or switch.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;break;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;The break statement is almost always used with if...else statement inside the loop.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
int main() 
{
int num = 5;
while (num &amp;gt; 0) 
  {
  if (num == 3)
    break;
  printf("%d\n", num);
  num--;
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;8.2 &lt;strong&gt;Continue :&lt;/strong&gt; The continue statement skips the current iteration of the loop and continues with the next iteration. Its syntax is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;continue;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;The continue statement is almost always used with the if...else statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;
int main() 
{
int nb = 7;
while (nb &amp;gt; 0) 
{
  nb--;
  if (nb == 5)
    continue;
 printf("%d\n", nb);
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;8.3 &lt;strong&gt;Go to:&lt;/strong&gt;&lt;br&gt;
-&amp;gt;Transfers control to the labeled statement.&lt;br&gt;
-&amp;gt;The label is an identifier. When the goto statement is encountered, the control of the program jumps to label: and starts executing the code.&lt;br&gt;
-&amp;gt;Here label can be any plain text except C keyword and it can be set anywhere in the C program above or below to goto statement.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;goto label;
... .. ...
... .. ...
label: 
statement;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example:*/
#include &amp;lt;stdio.h&amp;gt;

int main () {

   int a = 10;
   LOOP:do 
       {
         if( a == 15) 
         {
             a = a + 1;
             goto LOOP;
         }
         printf("value of a: %d\n", a);
         a++;
       }while( a &amp;lt; 20 );
   return 0;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTE :&lt;/strong&gt; Use of the goto statement is highly discouraged in any programming language because it makes it difficult to trace the control flow of a program, making the program hard to understand and hard to modify. Any program that uses a goto can be rewritten to avoid them.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>C : Decision Making</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Mon, 15 Mar 2021 16:22:06 +0000</pubDate>
      <link>https://dev.to/supriya2371997/c-decision-making-5b9i</link>
      <guid>https://dev.to/supriya2371997/c-decision-making-5b9i</guid>
      <description>&lt;ol&gt;
&lt;li&gt;What is decision making?&lt;/li&gt;
&lt;li&gt;Types (if, if else, Nested if....else, else if ladder, switch , Nested switch, ?:, goto)&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;1.&lt;strong&gt;Decision making:&lt;/strong&gt; It is about deciding the order of execution of statements based on certain conditions or repeat a group of statements until certain specified conditions are met.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;if :&lt;/strong&gt; If the expression returns true, then the statement-inside will be executed, otherwise statement-inside is skipped and only the statement-outside is executed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(expression)
{
    statement inside_if;
}
    statement outside_if;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example: */
#include &amp;lt;stdio.h&amp;gt;

void main( )
{
    int x, y;
    x = 15;
    y = 13;
    if (x &amp;gt; y )
    {
        printf("x is greater than y");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;3.&lt;strong&gt;if..else :&lt;/strong&gt; If the expression is true, the statement-block1 is executed, else statement-block1 is skipped and statement-block2 is executed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(expression)
{
    statement block1;
}
else
{
    statement block2;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example: */
#include &amp;lt;stdio.h&amp;gt;

void main( )
{
    int x, y;
    x = 15;
    y = 18;
    if (x &amp;gt; y )
    {
        printf("x is greater than y");
    }
    else
    {
        printf("y is greater than x");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Nested if....else :&lt;/strong&gt; if expression is false then statement-block3 will be executed, otherwise the execution continues and enters inside the first if to perform the check for the next if block, where if expression 1 is true the statement-block1 is executed otherwise statement-block2 is executed.
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if( expression )
{
    if( expression1 )
    {
        statement block1;
    }
    else 
    {
        statement block2;
    }
}
else
{
    statement block3;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example: */
#include &amp;lt;stdio.h&amp;gt;

void main( )
{
    int a, b, c;
    printf("Enter 3 numbers...");
    scanf("%d%d%d",&amp;amp;a, &amp;amp;b, &amp;amp;c);
    if(a &amp;gt; b)
    { 
        if(a &amp;gt; c)
        {
            printf("a is the greatest");
        }
        else 
        {
            printf("c is the greatest");
        }
    }
    else
    {
        if(b &amp;gt; c)
        {
            printf("b is the greatest");
        }
        else
        {
            printf("c is the greatest");
        }
    }
} 

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

&lt;/div&gt;



&lt;p&gt;5.&lt;strong&gt;else if ladder :&lt;/strong&gt; The expression is tested from the top(of the ladder) downwards. As soon as a true condition is found, the statement associated with it is executed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(expression1)
{
    statement block1;
}
else if(expression2) 
{
    statement block2;
}
else if(expression3 ) 
{
    statement block3;
}
else 
    default statement;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example: */
#include &amp;lt;stdio.h&amp;gt;

void main( )
{
    int a;
    printf("Enter a number...");
    scanf("%d", &amp;amp;a);
    if(a%5 == 0 &amp;amp;&amp;amp; a%8 == 0)
    {
        printf("Divisible by both 5 and 8");
    }  
    else if(a%8 == 0)
    {
        printf("Divisible by 8");
    }
    else if(a%5 == 0)
    {
        printf("Divisible by 5");
    }
    else 
    {
        printf("Divisible by none");
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;NOTES TO REMEMBER ABOUT IF ELSE&lt;/strong&gt;: &lt;br&gt;
-&amp;gt;In if statement, a single statement can be included without enclosing it into curly braces { ... }&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int a = 9;
if(a &amp;gt; 3)
    printf("success");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;"==" must be used for comparison in the expression of if condition, if you use = the expression will always return true, because it performs assignment not comparison.&lt;br&gt;
-&amp;gt;Other than 0(zero), all other values are considered as true.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;if(9)
    printf("True");
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;above block will print "True".&lt;/p&gt;

&lt;p&gt;6.&lt;strong&gt;switch :&lt;/strong&gt; A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each switch case.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;switch(expression) {

   case constant-expression  :
      statement(s);
      break; /* optional */

   case constant-expression  :
      statement(s);
      break; /* optional */

   /* you can have any number of case statements */
   default : /* Optional */
   statement(s);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#include &amp;lt;stdio.h&amp;gt;

int main () {

   /* local variable definition */
   char grade = 'B';

   switch(grade) {
      case 'A' :
         printf("Excellent!\n" );
         break;
      case 'B' :
      case 'C' :
         printf("Well done\n" );
         break;
      case 'D' :
         printf("You passed\n" );
         break;
      case 'F' :
         printf("Better try again\n" );
         break;
      default :
         printf("Invalid grade\n" );
   }

   printf("Your grade is  %c\n", grade );

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;RULES TO REMEMBER ABOUT SWITCH&lt;/strong&gt;: &lt;br&gt;
-&amp;gt;The expression (after switch keyword) must yield an integer value i.e the expression should be an integer or a variable or an expression that evaluates to an integer.&lt;br&gt;
-&amp;gt;The case label values must be unique.&lt;br&gt;
-&amp;gt;The case label must end with a colon(:)&lt;br&gt;
-&amp;gt;The next line, after the case statement, can be any valid C statement.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTES TO REMEMBER ABOUT SWITCH&lt;/strong&gt;: &lt;br&gt;
-&amp;gt;break statements are used to exit the switch block. It isn't necessary to use break after each block, but if you do not use it, then all the consecutive blocks of code will get executed after the matching block.&lt;br&gt;
-&amp;gt;default case is executed when none of the mentioned case matches the switch expression. The default case can be placed anywhere in the switch case. Even if we don't include the default case, switch statement works.&lt;br&gt;
-&amp;gt;Nesting of switch statements are allowed, which means you can have switch statements inside another switch block. However, nested switch statements should be avoided as it makes the program more complex and less readable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Difference between switch and if:&lt;/strong&gt;&lt;br&gt;
-&amp;gt;if statements can evaluate float conditions. switch statements cannot evaluate float conditions.&lt;br&gt;
-&amp;gt;if statement can evaluate relational operators. switch statement cannot evaluate relational operators i.e they are not allowed in switch statement.&lt;/p&gt;

&lt;p&gt;7.&lt;strong&gt;Nested switch :&lt;/strong&gt; It is possible to have a switch as a part of the statement sequence of an outer switch. Even if the case constants of the inner and outer switch contain common values, no conflicts will arise.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;switch(ch1) {

   case 'A': 
      printf("outer switch" );

      switch(ch2) {
         case 'A':
            printf("inner switch" );
            break;
         case 'B': /* case code */
      }

      break;
   case 'B': /* case code */
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example: */
#include &amp;lt;stdio.h&amp;gt;

int main () {

   int a = 110;
   int b = 220;

   switch(a) {

      case 110: 
         printf("outer switch\n", a );

         switch(b) {
            case 220:
               printf("inner switch\n", a );
         }
   }

   printf("a is : %d\n", a );
   printf("b is : %d\n", b );

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

&lt;/div&gt;



&lt;p&gt;8.&lt;strong&gt;?::&lt;/strong&gt; can be used to replace if...else statements.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Exp1 ? Exp2 : Exp3;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;-&amp;gt;Exp1 is evaluated. If it is true, then Exp2 is evaluated and becomes the value of the entire ? expression.&lt;/p&gt;

&lt;p&gt;-&amp;gt;If Exp1 is false, then Exp3 is evaluated and its value becomes the value of the expression.&lt;/p&gt;

&lt;p&gt;9.&lt;strong&gt;goto :&lt;/strong&gt; allows us to transfer control of the program to the specified label. label is an identifier. When the goto statement is encountered, the control of the program jumps to label: and starts executing the code.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why to not avoid goto:&lt;/strong&gt;&lt;br&gt;
-&amp;gt;code might get hard to follow.&lt;br&gt;
-&amp;gt;goto allows one to jump out of scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;goto label;
... .. ...
... .. ...
label: 
statement;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*Example: */
#include &amp;lt;stdio.h&amp;gt;

int main() {

   const int maxInput = 100;
   int i;
   double number, average, sum = 0.0;

   for (i = 1; i &amp;lt;= maxInput; ++i) {
      printf("%d. Enter a number: ", i);
      scanf("%lf", &amp;amp;number);

      // go to jump if the user enters a negative number
      if (number &amp;lt; 0.0) {
         goto jump;
      }
      sum += number;
   }

jump:
   average = sum / (i - 1);
   printf("Sum = %.2f\n", sum);
   printf("Average = %.2f", average);

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

&lt;/div&gt;



</description>
      <category>cpp</category>
      <category>programming</category>
    </item>
    <item>
      <title>C : Operators</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Mon, 15 Mar 2021 15:13:42 +0000</pubDate>
      <link>https://dev.to/supriya2371997/c-operators-2in4</link>
      <guid>https://dev.to/supriya2371997/c-operators-2in4</guid>
      <description>&lt;ol&gt;
&lt;li&gt;What are operators and Types?&lt;/li&gt;
&lt;li&gt;Categories with example&lt;/li&gt;
&lt;/ol&gt;




&lt;p&gt;1.&lt;strong&gt;What are operators and Types?&lt;/strong&gt;&lt;br&gt;
 -An operator is a symbol that tells the compiler to perform specific mathematical or logical functions. For example + is an operator to perform addition.&lt;br&gt;
 -Categories of operators depends upon no. of operands.&lt;/p&gt;

&lt;p&gt;2.&lt;strong&gt;Arithmetic Operator:&lt;/strong&gt;performs mathematical operation on numerical values (constants and variables).&lt;br&gt;
&lt;strong&gt;2.1  +    :&lt;/strong&gt; addition or unary plus&lt;br&gt;
&lt;strong&gt;2.2  -    :&lt;/strong&gt; subtraction or unary minus&lt;br&gt;
&lt;strong&gt;2.3  *    :&lt;/strong&gt; multiplication&lt;br&gt;
&lt;strong&gt;2.4  /    :&lt;/strong&gt; division&lt;br&gt;
&lt;strong&gt;2.5  %    :&lt;/strong&gt; remainder after division (modulo division)&lt;br&gt;
&lt;strong&gt;2.6 ++        :&lt;/strong&gt;increment (pre and post increment)&lt;br&gt;
&lt;strong&gt;2.7 --        :&lt;/strong&gt;decrement (pre and post decrement)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/*arithmetic operators*/
#include &amp;lt;stdio.h&amp;gt;
int main()
{
    int a = 5,b = 7, c;

    c = a+b;
    printf("a+b = %d \n",c);
    c = a-b;
    printf("a-b = %d \n",c);
    c = a*b;
    printf("a*b = %d \n",c);
    c = a/b;
    printf("a/b = %d \n",c);
    c = a%b;
    printf("Remainder when a/b = %d \n",c);
    printf("++a = %d \n", ++a);
    printf("--b = %d \n", --b);
    printf("++c = %f \n", ++c);
    printf("--d = %f \n", --d);

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

&lt;/div&gt;



&lt;p&gt;Increment ++ increases the value by 1 whereas decrement -- decreases the value by 1. These two operators are unary operators, meaning they only operate on a single operand.&lt;/p&gt;

&lt;p&gt;3.&lt;strong&gt;Relational Operator:&lt;/strong&gt; checks the relationship between two operands. Returns 1, if the relation is true,else returns value 0. They are used in decision making and loops.&lt;br&gt;
&lt;strong&gt;3.1  ==   :&lt;/strong&gt; Equal to&lt;br&gt;
&lt;strong&gt;3.2  !=   :&lt;/strong&gt; Not Equal to&lt;br&gt;
&lt;strong&gt;3.3  &amp;lt;    :&lt;/strong&gt; Less than&lt;br&gt;
&lt;strong&gt;3.4  &amp;gt;    :&lt;/strong&gt; Greater than&lt;br&gt;
&lt;strong&gt;3.5  &amp;lt;=   :&lt;/strong&gt; Less than or equal to&lt;br&gt;
&lt;strong&gt;3.6  &amp;gt;=   :&lt;/strong&gt; Greater than or equal to&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// relational operators
#include &amp;lt;stdio.h&amp;gt;
int main()
{
    int a = 9, b = 2;

    printf("%d == %d is %d \n", a, b, a == b);
    printf("%d &amp;gt; %d is %d \n", a, b, a &amp;gt; b);
    printf("%d &amp;lt; %d is %d \n", a, b, a &amp;lt; b);
    printf("%d != %d is %d \n", a, b, a != b);
    printf("%d &amp;gt;= %d is %d \n", a, b, a &amp;gt;= b);
    printf("%d &amp;lt;= %d is %d \n", a, b, a &amp;lt;= b);

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

&lt;/div&gt;



&lt;p&gt;4.&lt;strong&gt;Assignment Operator:&lt;/strong&gt; used for assigning a value to a variable.&lt;br&gt;
&lt;strong&gt;4.1  =    :&lt;/strong&gt; similar to a = b&lt;br&gt;
&lt;strong&gt;4.2  +=   :&lt;/strong&gt; similar to a=a+b&lt;br&gt;
&lt;strong&gt;4.3  -=   :&lt;/strong&gt; similar to a=a-b&lt;br&gt;
&lt;strong&gt;4.4  *=   :&lt;/strong&gt; similar to a=a*b&lt;br&gt;
&lt;strong&gt;4.5  /=   :&lt;/strong&gt; similar to a=a/b&lt;br&gt;
&lt;strong&gt;4.6  %=   :&lt;/strong&gt; similar to a=a%b&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// assignment operators
#include &amp;lt;stdio.h&amp;gt;
int main()
{
    int a = 8, c;

    c = a;      // c is 5
    printf("c = %d\n", c);
    c += a;     // c is 10 
    printf("c = %d\n", c);
    c -= a;     // c is 5
    printf("c = %d\n", c);
    c *= a;     // c is 25
    printf("c = %d\n", c);
    c /= a;     // c is 5
    printf("c = %d\n", c);
    c %= a;     // c = 0
    printf("c = %d\n", c);

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

&lt;/div&gt;



&lt;p&gt;5.&lt;strong&gt;Logical Operator:&lt;/strong&gt; expression with logical operator returns either 0 or 1 depending upon whether expression results true or false. Logical operators are commonly used in decision making in C programming.&lt;br&gt;
&lt;strong&gt;5.1  &amp;amp;&amp;amp;   :&lt;/strong&gt; Logical AND. True only if all operands are true &lt;br&gt;
&lt;strong&gt;5.2  ||   :&lt;/strong&gt; Logical OR. True only if either one operand is true &lt;br&gt;
&lt;strong&gt;5.3  !    :&lt;/strong&gt; Logical NOT. True only if the operand is 0&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// logical operators
#include &amp;lt;stdio.h&amp;gt;
int main()
{
    int a = 9, b = 2, c = 16, result;

    result = (a == b) &amp;amp;&amp;amp; (c &amp;gt; b);
    printf("(a == b) &amp;amp;&amp;amp; (c &amp;gt; b) is %d \n", result);

    result = (a == b) &amp;amp;&amp;amp; (c &amp;lt; b);
    printf("(a == b) &amp;amp;&amp;amp; (c &amp;lt; b) is %d \n", result);

    result = (a == b) || (c &amp;lt; b);
    printf("(a == b) || (c &amp;lt; b) is %d \n", result);

    result = (a != b) || (c &amp;lt; b);
    printf("(a != b) || (c &amp;lt; b) is %d \n", result);

    result = !(a != b);
    printf("!(a != b) is %d \n", result);

    result = !(a == b);
    printf("!(a == b) is %d \n", result);

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

&lt;/div&gt;



&lt;p&gt;6.&lt;strong&gt;Bitwise Operator:&lt;/strong&gt; mathematical operations are converted to bit-level during computation which makes processing faster and saves power. They are are used in C programming to perform bit-level operations.&lt;br&gt;
&lt;strong&gt;6.1  &amp;amp;    :&lt;/strong&gt; Bitwise AND&lt;br&gt;
&lt;strong&gt;6.2  |    :&lt;/strong&gt; Bitwise OR&lt;br&gt;
&lt;strong&gt;6.3  ^    :&lt;/strong&gt; Bitwise exclusive OR&lt;br&gt;
&lt;strong&gt;6.4  ~    :&lt;/strong&gt; Bitwise complement&lt;br&gt;
&lt;strong&gt;6.5  &amp;lt;&amp;lt;   :&lt;/strong&gt; Shift left&lt;br&gt;
&lt;strong&gt;6.6  &amp;gt;&amp;gt;   :&lt;/strong&gt; Shift right&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// bitwise operators 
#include &amp;lt;stdio.h&amp;gt; 
int main() 
{ 
    unsigned char a = 5, b = 9; 
    printf("a = %d, b = %d\n", a, b); 
    printf("a&amp;amp;b = %d\n", a &amp;amp; b); 
    printf("a|b = %d\n", a | b); 
    printf("a^b = %d\n", a ^ b); 
    printf("~a = %d\n", a = ~a); 
    printf("b&amp;lt;&amp;lt;1 = %d\n", b &amp;lt;&amp;lt; 1); 
    printf("b&amp;gt;&amp;gt;1 = %d\n", b &amp;gt;&amp;gt; 1); 

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

&lt;/div&gt;



&lt;p&gt;7.&lt;strong&gt;Misc Operator:&lt;/strong&gt; &lt;br&gt;
&lt;strong&gt;7.1  sizeof() :&lt;/strong&gt; Returns the size of a variable. &lt;br&gt;
&lt;strong&gt;7.2  &amp;amp;    :&lt;/strong&gt; Returns the address of a variable.&lt;br&gt;
&lt;strong&gt;7.3  *    :&lt;/strong&gt; Pointer to a variable.&lt;br&gt;
&lt;strong&gt;7.4  ?    :&lt;/strong&gt; Conditional Expression.&lt;/p&gt;

&lt;p&gt;8.&lt;strong&gt;Ternary Operator:&lt;/strong&gt; ternary operator evaluates the test condition and executes a block of code based on the result of the condition.&lt;br&gt;
&lt;strong&gt;condition ? expression1 : expression2;&lt;/strong&gt; &lt;br&gt;
-Here, condition is evaluated and if condition is true, expression1 is executed else if condition is false, expression2 is executed.&lt;br&gt;
-The ternary operator takes 3 operands (condition, expression1 and expression2). Hence, the name ternary operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//without ternary operator
int a = 1, b = 2, ans;
if (a == 1) {
    if (b == 2) {
        ans = 3;
    } else {
        ans = 5;
    }
} else {
    ans = 0;
}
printf ("%d\n", ans);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//with ternary operator i.e. conversion of above code
int a = 1, b = 2, ans;
ans = (a == 1 ? (b == 2 ? 3 : 5) : 0);
printf ("%d\n", ans);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>cpp</category>
      <category>programming</category>
      <category>operations</category>
    </item>
    <item>
      <title>C : Programming Fundamentals</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Sun, 14 Mar 2021 18:40:00 +0000</pubDate>
      <link>https://dev.to/supriya2371997/c-programming-fundamentals-2a7j</link>
      <guid>https://dev.to/supriya2371997/c-programming-fundamentals-2a7j</guid>
      <description>&lt;ol&gt;
&lt;li&gt;Programming language&lt;/li&gt;
&lt;li&gt;Purpose&lt;/li&gt;
&lt;li&gt;What is a program&lt;/li&gt;
&lt;li&gt;EDP (Electronic data processing)&lt;/li&gt;
&lt;li&gt;CPU components&lt;/li&gt;
&lt;li&gt;What is Software?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Programming language:-&lt;/strong&gt;&lt;br&gt;
The computer understands binary/machine/assembly language i.e. in the form of 0's and 1n's.&lt;br&gt;
for example: printf("Hello"); will be 01010111110000100 in binary form&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Purpose / Why use programming language?&lt;/strong&gt;&lt;br&gt;
The purpose of programming is to find a sequence of instructions that will automate the performance of a task (which can be as complex as an operating system) on a computer, often for solving a given problem. Also, The programing language enables us to write efficient programs and develop online solutions such as mobile applications, web applications, and games, etc. Programming is used to automate, maintain, assemble, measure and interpret the processing of the data and information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is a program?&lt;/strong&gt;&lt;br&gt;
A program is a specific set of ordered operations for a computer to perform. Also, a computer program is a collection of instructions that can be executed by a computer to perform a specific task. A computer program is usually written by a computer programmer in a programming language.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;EDP (Electronic data processing):-&lt;/strong&gt;&lt;br&gt;
It is a modern technique to process data. The data is processed through the computer. Data and a set of instructions are given to the computer as input and the computer automatically processes the data according to the given set of instructions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CPU components:-&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--cfgjEVWb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiih16ycmp3qaqa52cz8.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--cfgjEVWb--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qiih16ycmp3qaqa52cz8.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;MU or Memory Unit:-&lt;br&gt;
-this unit can store instructions, data, and intermediate results. This unit supplies information to other units of the computer when needed. It is also known as the &lt;strong&gt;internal storage unit&lt;/strong&gt; or the &lt;strong&gt;main memory&lt;/strong&gt; or the &lt;strong&gt;primary storage&lt;/strong&gt; or &lt;strong&gt;Random Access Memory (RAM)&lt;/strong&gt;.&lt;br&gt;
-speed, power, and capability are affected by its size.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Control Unit:-&lt;br&gt;
-responsible for controlling the transfer of data and instructions among other units of a computer &lt;strong&gt;or&lt;/strong&gt; manages and coordinates all the units of the computer.&lt;br&gt;
-It does not process or store data.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ALU or Arithmetic logic Unit:-&lt;br&gt;
-two parts: 1. Arithmetic Section   2. Logic Section&lt;br&gt;
-Arithmetic Section is responsible for arithmetic operations. &lt;br&gt;
-Logic Section is responsible for logic operations such as comparing, selecting, matching, and merging of data.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;What is Software?&lt;/strong&gt;&lt;br&gt;
   -Software is a collection of instructions and data that tell the computer how to work. This is in contrast to physical hardware, from which the system is built and actually performs the work.&lt;br&gt;
   -For example calculate software holds programs to perform operations such as addition, subtraction and so on.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>computerscience</category>
    </item>
    <item>
      <title>JAVA: OOP (Encapsulation)</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Wed, 16 Dec 2020 07:34:10 +0000</pubDate>
      <link>https://dev.to/supriya2371997/java-oop-encapsulation-3pl8</link>
      <guid>https://dev.to/supriya2371997/java-oop-encapsulation-3pl8</guid>
      <description>&lt;p&gt;Q1: Access Modifiers?&lt;br&gt;
Q2: &lt;a href="https://dev.to/supriya2371997/java-oop-in-brief-4hlf"&gt;OOPS&lt;/a&gt;: Encapsulation?&lt;br&gt;
Q3: How to achieve Encapsulation?&lt;br&gt;
Q4: Advantages?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Access Modifier:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1.1 used to set the access level for classes, attributes, methods and constructors.&lt;br&gt;
1.2 java provides access modifiers such as public, private, default and protected.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Class level access modifiers:-&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;public:&lt;/strong&gt; class is accessible by other classes&lt;br&gt;
&lt;strong&gt;default:&lt;/strong&gt; class can be accessed by the classes from the same package. by default, the access modifier is set to &lt;strong&gt;default&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;em&gt;Method, attributes, constructor level access modifiers:-&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;public:&lt;/strong&gt; code is accessible for all classes&lt;br&gt;
&lt;strong&gt;private:&lt;/strong&gt; code is only accessible within the class&lt;br&gt;
&lt;strong&gt;default:&lt;/strong&gt; code is only accessible in the same package. by default, the access modifier is set to &lt;strong&gt;default&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;protected:&lt;/strong&gt; code is accessible in the same package and outside the package through subclass&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tBtb4V50--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3a2faoqkjzojclo8na0z.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tBtb4V50--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/3a2faoqkjzojclo8na0z.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2. Encapsulation:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;2.1 it is one of the most powerful and fundamental concepts of Object-Oriented Programming&lt;br&gt;
2.2 also called as &lt;strong&gt;data-hiding&lt;/strong&gt; since it hides sensitive data from the user in order to keep it safe from outside interference and misuse&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;wrapping up of data into a single unit in order to prevent access to it from the outside world&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;2.3 for example, a car has many parts such as wheels, engine etc which together form a single object.&lt;/p&gt;

&lt;p&gt;2.4 since there is a prohibition for direct access to the data. Functions are the only ways to access data. It basically creates a shield due to which code or data can't be accessed outside the shield&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;in order to read the data items, you call the member function in the object. It will read the data items from the function and return the value to you. The data can't be accessed directly in order to keep it protected and accidental alteration.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w_qx8aqR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x2fzk64b9r7y4ioashrp.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w_qx8aqR--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/x2fzk64b9r7y4ioashrp.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
2.5 For example, In a large organisation there are many departments like sales, payroll, accounts, etc. And each department had it's own staff to maintain it's data.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Suppose an employee wants to know the data of import and export material, but he won't be allowed to access that data. Rather he will have to issue an order from the authorised person requesting for the required information. Then also the particular employee will not be directly accessing the data, rather the employees of the authorised department will gather the request data and pass it to the desired employee.
&amp;gt;therefore, we can say that here Department is a single unit which is holding data and employees together.&lt;/li&gt;
&lt;/ul&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Achieve Encapsulation:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;step 1: declare class level variables &lt;strong&gt;private&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;so they can't be accessed from outside of the class&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;step 2: provide &lt;strong&gt;setter&lt;/strong&gt; and &lt;strong&gt;getter&lt;/strong&gt; methods that are declared as &lt;strong&gt;public&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;used to view or change the value of the variable&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=""&gt;Github link to below code&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Simple example of encapsulation:-&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Encapsulation
{
  //Declaring variables as private
  private String EmployeeName;
  private String EmployeeJob;
  private int EmployeeAge;

  //'public' Setter and Getter Methods
  public void setName(String EmployeeName)
  {
    this.EmployeeName = EmployeeName;
  }
  public String getName()
  {
    return EmployeeName;
  }

  public void setJob(String EmployeeJob)
  {
    this.EmployeeJob = EmployeeJob;
  }
  public String getJob()
  {
    return EmployeeJob;
  }

  public void setAge(int EmployeeAge)
  {
    this.EmployeeAge = EmployeeAge;
  }
  public int getAge()
  {
    return EmployeeAge;
  }

  public static void main (String[] args)
  {
    //creating object
    Encapsulation e = new Encapsulation();

    // setting values through setter methods
    e.setName("SUPRIYA KOLHE");
    e.setAge(22);
    e.setJob("SOFTWARE DEVELOPER");

    // Displaying values through Getter methods
    System.out.println("Name of the employee: " + e.getName());
    System.out.println("Age of the employee: " + e.getAge());
    System.out.println("Job of the employee: " + e.getJob());
  }//PSVM ends
}//Encapsulation class ends

/*
Name of the employee: SUPRIYA KOLHE
Age of the employee: 22
Job of the employee: SOFTWARE DEVELOPER
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;3.1 as you can see in the above example, here we are setting values using Setter methods and accessing them using Getter method&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;where Setter methods set the value of the variable and Getter methods returns the values&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;4. Advantages:-&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HeeiZiib--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xebqd0m50ldztph1ukve.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HeeiZiib--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/xebqd0m50ldztph1ukve.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Data Hiding:-&lt;/strong&gt; programmer is able to hide inner classes and provide authorization to access them to only desired users.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;limits the accessibility of data&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Easy to Testing:-&lt;/strong&gt; because of sorted structure, it is easy to perform unit testing.&lt;br&gt;
&lt;strong&gt;Flexibility and Maintainability:-&lt;/strong&gt; programmer can make code read-only and write-only according to need.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Getter methods are used to read/fetch the data. Thus using only them will make code read-only.&lt;br&gt;
Setter methods are used to write into the variables. Thus using only them will make code write-only.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Read-only example:&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Employee
{  
    private String Dept="IT";  
    public String getDept()
    {  
         return Dept;   
    }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Write-only example:&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Employee
{  
    private String Salary="80000";  
    public String setSalary()
    {  
         return Salary;   
    }  
}  
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Getter and Setter Methods:-&lt;/strong&gt; able to access private variables outside the class&lt;br&gt;
&lt;strong&gt;Code Reusability:-&lt;/strong&gt; able to use existing code effectively again and again.&lt;br&gt;
&lt;strong&gt;Control &amp;amp; security:-&lt;/strong&gt; a class has control over the variables and fields i.e. what is stored in them.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Please comment if you have any feedback or suggestions&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
    </item>
    <item>
      <title>JAVA: OOP (Abstraction)</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Tue, 15 Dec 2020 15:20:40 +0000</pubDate>
      <link>https://dev.to/supriya2371997/java-oop-abstraction-4ild</link>
      <guid>https://dev.to/supriya2371997/java-oop-abstraction-4ild</guid>
      <description>&lt;p&gt;Q1: &lt;a href="https://dev.to/supriya2371997/java-oop-in-brief-4hlf"&gt;OOPS&lt;/a&gt;: Abstraction?&lt;br&gt;
Q2: interface?&lt;br&gt;
Q3. abstract class?&lt;br&gt;
Q4: Why can’t static methods be abstract in Java?&lt;br&gt;
Q5: Advantages of Abstraction?&lt;br&gt;
Q6: Why can’t we create an object of an Abstract Class?&lt;br&gt;
Q7: Data Encapsulation vs Data Abstraction?&lt;br&gt;
Q8: Abstract Class vs Interface?&lt;br&gt;
Q9: When to use abstract class?&lt;br&gt;
Q10: when to use interface?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Abstraction:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1.1 process of hiding implementation &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;showing essential features and hiding non-essential features from the user.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;1.2 for example, the remote is an interface between user and TV. It can be operated using various buttons, but the user is unaware of the internal part of the remote(i.e. circuits). It is so because the user does not need to know the details except the one that helps him operate the remote.&lt;br&gt;
1.3 another example can be a login or registration form. The user is unaware/does not need to know how things work behind the curtains i.e UI. &lt;br&gt;
1.4 it is a collection of abstract methods&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;ways to achieve abstraction:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;ol&gt;
&lt;li&gt;using the interface&lt;/li&gt;
&lt;li&gt;using abstract class&lt;/li&gt;
&lt;/ol&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;2. Using Interface:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;2.1 Consider an example of the remote. It only works as an interface between the TV and the user. It can't be used to operate any other device/machine. i.t. it contains all the necessary functionalities which the user might require while hiding the implementation details from the user.&lt;br&gt;
2.2 similarly interface contains empty methods and can contain variables also.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;it means that interfaces don't provide any implementation details and it's up to classes/clients to provide the implementation details fro the method/methods when they implement the interface.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;2.3 a class can use &lt;strong&gt;implements&lt;/strong&gt; keyword to implement the interface and provide the implementation of the interface method &lt;br&gt;
2.4 a java class can implement the interface in order to provide the implementation of the methods using &lt;strong&gt;interface&lt;/strong&gt;&lt;br&gt;
2.5 interface provide sets of rules for classes and tell them what to do and not to do.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;in case class does not provide an implementation for all the methods of the interface, then the class must be declared &lt;strong&gt;abstract&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Simple Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface printable
{
    void start();
    void stop();
    int off=0;
    void pressed(int key);
}
class InterfaceExample implements printable
{
    int off=1;
    @Override
    public void start()
    {
        System.out.println("Started");
    }
    @Override
    public void stop()
    {
        System.out.println("\nvariable from interface : "+printable.off+"\nStopped ");
    }
    @Override
    public void pressed(int key)
    {
                //printable.off=1;
        System.out.println("\nvariable from interface : "+off+"\nPressed key number "+key);
    }
    public static void main(String args[])
    {
        InterfaceExample obj = new InterfaceExample();
        obj.start();obj.pressed(23);
        obj.stop();

    }
}
/*Started

variable from interface : 1
Pressed key number 23

variable from interface : 0
Stopped*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;-:here, we have created an interface with methods and variable which we are implementing in class and also trying to see whether a change of value inside the method will affect the interface variable i.e. off variable.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;changing variable value inside the method does not affect interface value&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;-:in the above example if we uncomment the line "printable.off=1;" and then execute the code, it will throw a compile-time error&lt;br&gt;
&lt;/p&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;InterfaceExample.java:24: error: cannot assign a value to final variable off
                printable.off=1;
                         ^
1 error
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;static method inside interface Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface Jump 
{
    static int getHeight() 
    {
        return 1;
    }
}
class Cat implements Jump 
{
    public void jump() 
    {
        System.out.println(“Jumping height “ + getHeight());//COMPILE TIME ERROR
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;-:above code will not compile, since it is calling for the getHeight() which is supposed to be inside Kangaroo.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;in order to execute the code, one change needs to be done i.e.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;System.out.println(“Jumping height “ + Jump.getHeight());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;nested interface Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;interface OuterInterface 
{
    interface InnerInterface 
    {        
    }

}

class ImplementingC implements OuterInterface.InnerInterface 
{
} 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;nested interface Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class OuterC
{
    interface InnerInterface 
    {        
    }
}

class ImplementingC implements OuterClass.InnerInterface 
{    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;interface extending interface Example:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public interface Teacher 
{
   public void Name(String name);
   public void Age(int age);
}

public interface Computer extends Teacher 
{
   public void MonthlyAttendance(int attendance);
   public void Salary(String sal);
   public void City(String city);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;-:here the class that implements Computer interface must provide an implementation for both Computer and Teacher interface as it is extended by the Computer interface.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;class of interface is also created after compiler compiles the code, i.e. printable.class file will be created after the compilation is done&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Facts about interface:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;-:all &lt;strong&gt;members&lt;/strong&gt; i.e. both methods and variables/fields of an interface are public&lt;br&gt;
-:all the &lt;strong&gt;methods&lt;/strong&gt; are &lt;strong&gt;public&lt;/strong&gt;, &lt;strong&gt;abstract&lt;/strong&gt; by &lt;strong&gt;default&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;except &lt;strong&gt;static&lt;/strong&gt; and &lt;strong&gt;default&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;-:all the &lt;strong&gt;fields&lt;/strong&gt; are &lt;strong&gt;public&lt;/strong&gt;, &lt;strong&gt;static&lt;/strong&gt;, final by &lt;strong&gt;default&lt;/strong&gt;&lt;br&gt;
-:an interface can extend another interface using &lt;strong&gt;extend&lt;/strong&gt; keyword.&lt;br&gt;
-:interface can contain static methods&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Interface features:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;-:provide the total abstraction&lt;br&gt;
-:help achieve multiple inheritance as java doesn't support multiple inheritances.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;one class can implement several interfaces which can also be called as multiple interface implementation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;-:help achieve loose coupling in design patterns implementation&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;loose coupling means independent behaviour, for example, class A only knows about class B what class B has exposed through its interface.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. using abstract class:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;3.1 provide total abstraction where all the methods are empty and field variables are public static and final by default&lt;br&gt;
3.2 use keyword &lt;strong&gt;abstract&lt;/strong&gt; before the class declaration and method declaration&lt;br&gt;
3.3 we can't create an object of an abstract class&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;-:but we can define its constructor which can only be invoked in the constructor of its subclass&lt;br&gt;
-:subclass constructor can access a superclass constructor to initialize its variable which might be needed in the subclass&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3.4 they can contain both abstract and non-abstract methods.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;they can't contain the body of the abstract method&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3.5 if the subclass is not implementing the abstract methods then we have to make it &lt;strong&gt;abstract&lt;/strong&gt; explicitly&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;if the class contains an abstract method, then it must be defined as &lt;strong&gt;abstract&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3.6 abstract class is used to provide the most common feature that is specific to various classes.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;subclasses can provide a different implementation of those methods according to their requirement&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Eaxmple:-&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;abstract class Animal
{
    public abstract void Like();
    public void doTheyHaveLegs()
    {
        System.out.println("Yes, animals have legs");
    }
}

class Dog extends Animal
{
    @Override
    public void Like()
    {
        System.out.println("Dog like to cuddle.");
    }
}

class Lion extends Animal
{
    @Override
    public void Like()
    {
        System.out.println("Lion like to Growl");
    }
}



class TestAnimal
{
    public static void main(String[] args)
    {
        Animal Dog = new Dog();
        Dog.Like();

        Animal Lion = new Lion();
        Lion.Like();
        Dog.doTheyHaveLegs();
        Lion.doTheyHaveLegs();
    }
}
/*
Dog like to cuddle.
Lion like to Growl
Yes, animals have legs
Yes, animals have legs
*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;3.7 Here &lt;strong&gt;Animal&lt;/strong&gt; is an abstract class which share a common property of animal with &lt;strong&gt;Dog&lt;/strong&gt; and &lt;strong&gt;Lion&lt;/strong&gt; class, which are implementing &lt;strong&gt;Like()&lt;/strong&gt; of &lt;strong&gt;Animal&lt;/strong&gt; abstract class&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Animal&lt;/strong&gt; class has both abstract and non-abstract methods in it.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;4. Why can’t static methods be abstract in Java:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;4.1 there are two points to remembers&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;static keyword stated that static method can't be overridden.&lt;br&gt;
abstract stated that the implementation of the method must be provided by the subclass&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;4.2 here as you can see, both the points contradict with each other, thus resulting it is not possible to make an abstract method static&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;although, abstract class may contain static methods&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Sxyv8EHg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o4g1dfk2qyeym4644j6w.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Sxyv8EHg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/o4g1dfk2qyeym4644j6w.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;6. Why can’t we create an object of an Abstract Class:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;6.1 it is not very useful to do so because there would not be any actual implementation of the called method.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;7. Data Encapsulation vs Data Abstraction:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Data Encapsulation is hiding data or information&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Abstraction is hiding the implementation details&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Encapsulation binds the data members and methods together&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;data abstraction deals with showing the external details of an entity to the user and hiding the details of its implementation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Encapsulation hides the data&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;abstraction provides access to a specific part of data&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;8. Abstract Class vs Interface:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"abstract" keyword is used&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"interface" keyword is used&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We can extend an abstract class using the extends keyword&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We can implement an interface using the implements keyword&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;can have both final, non-final, static and non-static variables&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;can only have final and static variables that are declared by default&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;speed is fast as compared to the interface&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;speed is slow as compared to abstract class&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;may or may not have variables declared as final &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;variables are by default declared as final&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;can have all access modifiers&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;only public access modifier is allowed&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;can have both abstract and non-abstract or concrete methods&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;can only have abstract methods,&lt;strong&gt;but, from version 8 of Java, the interface supports static and non-static methods too.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;can have constructors&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;can not have constructors&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Abstract classes do not support Multiple Inheritance, &lt;strong&gt;but, a class can extend only a single abstract class but can implement multiple Java interfaces&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Interface support Multiple Inheritance&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;abstract class is used to avoid independence&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;interface is used when Future enhancement is needed&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;9. When to use abstract class:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;9.1 when some related classes that need to share the same lines of code&lt;br&gt;
9.2 is there is a requirement of using access modifiers other than public&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;10. When to use interface:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;10.1 to achieve 100% abstraction&lt;br&gt;
10.2 to achieve multiple inheritance&lt;br&gt;
10.3 to specify the behaviour of a particular data type, irrespective of who implements its behaviour&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Please comment if you have any feedback or suggestions&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
    </item>
    <item>
      <title>JAVA: OOP (Polymorphism)</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Tue, 15 Dec 2020 05:14:12 +0000</pubDate>
      <link>https://dev.to/supriya2371997/java-oop-polymorphism-4jc0</link>
      <guid>https://dev.to/supriya2371997/java-oop-polymorphism-4jc0</guid>
      <description>&lt;p&gt;Q1: &lt;a href="https://dev.to/supriya2371997/java-oop-in-brief-4hlf"&gt;OOPS&lt;/a&gt;: Polymorphism?&lt;br&gt;
Q2: Compile-time polymorphism?&lt;br&gt;
Q3: Run-time polymorphism?&lt;br&gt;
Q4: Facts about Polymorphism?&lt;br&gt;
Q5: Advantages?&lt;br&gt;
Q6: Disadvantages?&lt;br&gt;
Q7: Method Overloading?&lt;br&gt;
Q8: Method Overloading?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Polymorphism:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1.1 having the ability for a message or data to be processed in more than one form &lt;br&gt;
1.2 It is derived from two Greek words, that is, poly and morphs. “poly” means many and “morphs” means forms. Henceforth, polymorphism implies many forms.&lt;br&gt;
1.3 for e.g. a function to read secured classes - class_category() can take up different types of arguments like - class_category(FirstClass), class_category(SecondClass), class_category(Distinction), etc.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TheZCBR3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lq38vtxcpteyiiz80wnv.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TheZCBR3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/lq38vtxcpteyiiz80wnv.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Compile-time polymorphism:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;2.1 performed by method overloading&lt;br&gt;
2.2 also called as &lt;strong&gt;Static binding/Early binding&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Run-time polymorphism:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;3.1 performed  by method overriding&lt;br&gt;
3.2 also called &lt;strong&gt;Dynamic binding/Dynamic Method Dispatch/Late binding&lt;/strong&gt;, where &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;a call to an overridden method is resolved at runtime rather than compile-time OR&lt;br&gt;
implemented dynamically when a program is being executed is called run-time polymorphism.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;3.3 Here the overridden method is called through a reference variable of a parent class&lt;br&gt;
3.4 Runtime polymorphism can't be achieved by data members&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;4. Facts about Polymorphism:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;4.1 all the working code in various classes does not require to know about the class being used by it, since their way of usage is the same.&lt;br&gt;
4.2 For example, suppose there is a button and we know that pressing it will do something, but unaware of the output or the reference of its use. So the conclusion is, either way, it will not affect the way it is used.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;5. Advantages:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;5.1 helps programmer to reuse the code and also the classes that once written to be tested and implemented&lt;br&gt;
5.2 one variable name can contain values of multiple data types such as int, float etc.&lt;br&gt;
5.3  improved readability of the program&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;6. Disadvantages:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;6.1 developers may find it difficult to implement polymorphism in codes&lt;br&gt;
6.2 may affect performance &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;if the machine needs to decide which method or variable to invoke. and as these decisions are taken at run time.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;6.3 reduces the readability of the program.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;7. Method overloading:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;7.1 same method name &amp;amp; different parameters&lt;br&gt;
 7.2 it is performed within class&lt;br&gt;
7.3 the main advantage of it is increased readability &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;when we must perform only one operation, having the same name of the methods.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;ways to overload the method:&lt;br&gt;
option 1: changing the number of arguments&lt;br&gt;
option 2: changing the data type&lt;br&gt;
option 3: changing both the number of arguments and data type&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;option 1: changing the number of arguments:-&lt;/strong&gt;&lt;br&gt;
-suppose you have to perform a multiplication operation of the given number but there can be n number of arguments, then if you create a method such as mult1(int, int) for two parameters and mult2(int, int, int) for three parameters then it may be difficult for the programmer to understand the behaviour of the block i.e. method because of the different name. In such situations, option 1 can be used.&lt;br&gt;
-&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/MethodOverloadingDifferentNumberOfArguments.java"&gt;Github Link to code&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MethodOverloading
{
    static int mult (int a,int b)
    {
        return a*b;
    }
    static int mult(int a,int b,int c)
    {
        return a*b*c;
    }
}
class MethodOverloadingDifferentNumberOfArguments
{
    public static void main(String[] args)
    {
        System.out.println(MethodOverloading.mult(13,13));
        System.out.println(MethodOverloading.mult(9,9,9));
    }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we are creating static methods so that there is no need to create an instance for calling methods.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;option 2: changing the data type:-&lt;/strong&gt;&lt;br&gt;
-suppose you have to perform a multiplication operation of the given number where given numbers can be of any data types. Then we can create methods such as mult(int, int), mult(float, float) and so on.&lt;br&gt;
-&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/MethodOverloadingChangingDataType.java"&gt;Github Link to code&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MethodOverloading
{
    static int mult (int a,int b)
    {
        return a*b;
    }
    static double mult(double a,double b,double c)
    {
        return a*b*c;
    }
}
class MethodOverloadingChangingDataType
{
    public static void main(String[] args)
    {
        System.out.println(MethodOverloading);
        System.out.println(MethodOverloading);
    }
}
/*15
35.721*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;option3: changing both the number of arguments and data type:-&lt;/strong&gt;&lt;br&gt;
-sometimes we may need to use the method which is having both different numbers of arguments and data types. These methods are called or invoked with the value of the same data type and number of parameters used.&lt;br&gt;
-&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/MethodOverloadingBoth.java"&gt;Github Link to code&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MethodOverloading
{
    static int one (int a)
    {
        return a*a;
    }//return square
    static int two(int a,int b)
    {
        return a*b;
    }//return multiplication
    static int three(int a,int b,int c)
    {
        return a+b+c;
    }//return addition
}
class MethodOverloadingBoth
{
    public static void main(String[] args)
    {
        System.out.println(MethodOverloading.one(5));
        System.out.println(MethodOverloading.two(2,3));
        System.out.println(MethodOverloading.three(2,3,4));
    }
}
/*25
6
9*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;8. Method overriding:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;-used to achieve the runtime polymorphism or dynamic binding.&lt;br&gt;
how to achieve method overriding:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;a. the method name must be same as in the parent class&lt;br&gt;
b. the parameters must be same as in the parent class&lt;br&gt;
c. there must be an inheritance i.e. IS-A relationship&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;-&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/MethodOverriding.java"&gt;Github Link to code&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class MethodOverridingParent
{
    int a=10;
    public void run()
    {
        System.out.println("MethodOverridingParent class's method");
    }
}
class MethodOverridingChild1 extends MethodOverridingParent
{
    int a=9;
    public void run()
    {
        System.out.println("MethodOverridingChild1 class's method "+a);
    }
}
class MethodOverridingChild2 extends MethodOverridingParent
{
    public void run()
    {
        System.out.println("MethodOverridingChild2 class's method "+a );
    }
}
class MethodOverriding
{
    public static void main(String[] args)
    {
        MethodOverridingParent m1=new MethodOverridingChild1();
        m1.run();
        MethodOverridingParent m2=new MethodOverridingChild2();
        m2.run();
    }
}
/*MethodOverridingChild1 class's method 9
MethodOverridingChild2 class's method 10*/
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here, child classes will override the default behaviour provided by superclass and some of its own specific behaviour. As you can see MethodOverridingChild1  is giving the priority to it's own variable a first in order to perform the operation. and since MethodOverridingChild2 does not have any of it's own variable a, it is accessing the values of it's parent class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Please comment if you have any feedback or suggestions&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
    </item>
    <item>
      <title>JAVA: OOP (Inheritance)</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Sat, 12 Dec 2020 09:56:03 +0000</pubDate>
      <link>https://dev.to/supriya2371997/java-oop-inheritance-178l</link>
      <guid>https://dev.to/supriya2371997/java-oop-inheritance-178l</guid>
      <description>&lt;p&gt;Q1: &lt;a href="https://dev.to/supriya2371997/java-oop-in-brief-4hlf"&gt;OOPS&lt;/a&gt;: Inheritance?&lt;br&gt;
Q2: When to use?&lt;br&gt;
Q3: Advantages?&lt;br&gt;
Q4: Disadvantages?&lt;br&gt;
Q5: Explain types with example?&lt;br&gt;
Q6: Facts about inheritance?&lt;br&gt;
Q7: Why java does not support multiple inheritances?&lt;br&gt;
Q8: How to access private members of the superclass?&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;1. Inheritance:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1.1 it is a mechanism of acquiring certain properties and behaviour of one class and another class i.e. parent class to child class.&lt;br&gt;
1.2 the purpose of inheritance is to be able to create new classes that are built upon existing classes such as new child class on the existing parent class.&lt;br&gt;
1.3 inheritance represents an IS-A-relationship i.e. parent-child relationship.&lt;br&gt;
1.4 access modifiers play a major role in inheritance. Only public and protected members can be accessed by child class and not the private members. Although we can indirectly use private members using public or protected functions.&lt;br&gt;
&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/Getter_Setter.java"&gt;Click here to view the code for 1.4 point&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Syntax and terms used&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;class Subclass-name extends Superclass-name {  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;//methods and fields&lt;br&gt;&lt;br&gt;
}  &lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;-: class - it is a group of objects with common properties. it is a template or blueprint from which object can be created.&lt;br&gt;
-: subclass - class that inherits another class. It is also called a derived class, extended class, or child class.&lt;br&gt;
-: superclass - class from where a subclass inherits the features. It is also called as a base class or a parent class.&lt;br&gt;
-: extends - indicates the new class is inheriting from the existing class.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example&lt;/strong&gt; &lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/Single_inheritance.java"&gt;Below source code&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--LxblYIJZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7jhb1ygbi7z1y0ukzhu4.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--LxblYIJZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/7jhb1ygbi7z1y0ukzhu4.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. When to use:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;2.1 Method Overriding to achieve runtime polymorphism&lt;br&gt;
2.2 Code reusability&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Advantages:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;3.1 reusability &lt;br&gt;
3.2 readability&lt;br&gt;
3.3 reliability i.e. the base class code will be already tested and debugged&lt;br&gt;
3.4 less costly because of reusability&lt;br&gt;
3.5 supports code extensibility&lt;br&gt;
3.6 improper use or less knowledge may lead to wrong solutions&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;4. Disadvantages:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;4.1 less use of data members present in the base class may lead to memory wastage.&lt;br&gt;
4.2 dependability may cause unintended damage i.e. inheritance causes the coupling between classes, thus a change in the base class will affect all the child processes.&lt;br&gt;
4.3 can't inherit from final class i.e. below program will an error.&lt;br&gt;
final class Class1 { &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;...&lt;br&gt;
  }&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;class Class2 extends Class1{&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;...&lt;br&gt;
}&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;5 Types:-&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---A4zOQNs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jzkfz1waqgi2jn2oq34k.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---A4zOQNs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/jzkfz1waqgi2jn2oq34k.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Single Inheritance&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1.1 subclass extends or inherits the features of one superclass. eg. daughter class is inheriting father class&lt;br&gt;
1.2 Basically, java only uses a single inheritance as a subclass cannot extend more superclass.&lt;br&gt;
&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/SingleInherit.java"&gt;CLICK HERE FOR SIMPLE PROGRAM&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--9fpWMUU_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w9epjr4vg0hr66zplewe.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--9fpWMUU_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/w9epjr4vg0hr66zplewe.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Multilevel Inheritance&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;2.1 a class will be inheriting a base class and as well as the derived class also act as the base class to other class. eg. daughter inherit form father, and father inherit from grandfather&lt;br&gt;
&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/MultilevelInherit.java"&gt;CLICK HERE FOR SIMPLE PROGRAM&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FP4sKN4i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t6vcgjsiovh46z525b6o.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FP4sKN4i--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/t6vcgjsiovh46z525b6o.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Hierarchical Inheritance &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;3.1 one class serves as a superclass for more than one subclass. eg. one teacher serves multiple students&lt;br&gt;
&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/HierarchicalInherit.java"&gt;CLICK HERE FOR SIMPLE PROGRAM&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GCx3ZOLM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/23zssbgiz66307j40wxi.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GCx3ZOLM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/23zssbgiz66307j40wxi.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Multiple Inheritance (can't be implemented using class in java)&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;4.1 one class can have more than one superclass&lt;br&gt;
4.2 java does not support multiple inheritances with classes, but it can only be achieved through interfaces&lt;br&gt;
&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/MultipleInherit.java"&gt;CLICK HERE FOR SIMPLE PROGRAM&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--sL-R2xN2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h54tpudck2uj1twnt1d8.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--sL-R2xN2--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/h54tpudck2uj1twnt1d8.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Hybrid Inheritance&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;5.1 combinations of two or more types of inheritance.&lt;br&gt;
5.2 since multiple inheritances can't be achieved in java with classes, hybrid inheritance also can't be achieved in java with classes. But using inheritance only it can be implemented.&lt;br&gt;
&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/HybridInherit.java"&gt;CLICK HERE FOR SIMPLE PROGRAM&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;6. Facts about inheritance:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;6.1 only one superclass: The superclass can only be one, that is because java does not support multiple inheritance with classes.&lt;br&gt;
6.2 inherit constructor: derived class can inherit methods, variables and nested classes from its superclass but constructors, that is because constructors are not members. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;However, constructors of the superclass can be invoked from its derived class&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;6.3 inheritance does not allow derived class to inherit private members of its superclass. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;However, it can be accessed using getters and setters in order to access them.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;7. Why java does not support multiple inheritances:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;7.1 To prevent ambiguity: consider a situation where both BaseClass1 and BaseClass2 has calculate() with different working or behaviour, then there will be ambiguity if ChildClass which inherits both the base classes will try to call calculate()&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;because java compiler can't decide which calculate() it should inherit.&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;8. How to access private members of the superclass?&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We can use getter and setter methods that &lt;br&gt;
&lt;a href="https://github.com/supriya2371997/Java/blob/master/DEV%20COMMUNITY%20PROGRAMS/Getter_Setter.java"&gt;Click here for the code&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;option 1. return private member&lt;br&gt;
option 2. return public member that store private member's values&lt;/p&gt;
&lt;/blockquote&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Please comment if you have any feedback or suggestions&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
    </item>
    <item>
      <title>JAVA: OOP in brief</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Fri, 11 Dec 2020 10:14:02 +0000</pubDate>
      <link>https://dev.to/supriya2371997/java-oop-in-brief-4hlf</link>
      <guid>https://dev.to/supriya2371997/java-oop-in-brief-4hlf</guid>
      <description>&lt;p&gt;Q1: what do you mean by OOP concept?&lt;br&gt;
Q2: List of OOP Features?&lt;br&gt;
Q3: Why use OOP concepts or advantages of OOP?&lt;br&gt;
Q4: Disadvantages of OOP?&lt;br&gt;
Q5: Difference between Procedural and OOP programming?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt;: For detailed information on OOP feature click on one you wish to explore&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;1. what do you mean by OOP concept:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;1.1 stands for Object-Oriented Programming.&lt;br&gt;
1.2 OOP is a methodology or paradigm to design a program using classes and objects.&lt;br&gt;
1.3 OOP simplifies software development and maintenance by providing a few concepts such as:&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frewxsx85fqmolo6r49p9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Frewxsx85fqmolo6r49p9.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. List of OOP Features:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;2.1 class: a collection of object &amp;amp; logical entity, eg. bike&lt;br&gt;
2.2 object: a real-life entity that has state &amp;amp; behaviour of its own, eg. colour&lt;br&gt;
2.3 &lt;a href="https://dev.to/supriya2371997/java-oop-inheritance-178l"&gt;Inheritance&lt;/a&gt;: acquiring properties and behaviour from another class, eg. father and son&lt;br&gt;
2.4 Polymorphism: one task in different ways, speak can be as meow and for the dog, it can be woof.&lt;br&gt;
2.5 Abstraction: hiding internal details and showing functionality, eg. ATM machine&lt;br&gt;
2.6 Encapsulation: binding/ wrapping code &amp;amp; data together into a single unit, eg. capsule containing different medicines&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;3. Why use OOP concepts or advantages of OOP:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;3.1 faster&lt;br&gt;
3.2 Simple and provide a clear understanding and structure of code&lt;br&gt;
3.3 reusability - able to reuse content and behaviour of the existing class in a new class.&lt;br&gt;
3.4 code optimisation&lt;br&gt;
3.5 Modifiability i.e. easy to update&lt;br&gt;
3.6 Secure because of data hiding concept&lt;br&gt;
3.7 easy to upgrade from small to large system&lt;br&gt;
3.8 we cn eliminate redundant code and extend the use of existing classes&lt;br&gt;
3.9 possible to have multiple objects&lt;br&gt;
3.10 easy to partition the work in a project based on objects&lt;br&gt;
3.11 provide message passing technique for communication between objects&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;4. Disadvantages of OOP:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;4.1 require more memory to increase speed&lt;br&gt;
4.2 larger program size&lt;br&gt;
4.3 not suitable for all type of programs&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;5. Difference between OOP programming &amp;amp; Procedural oriented language:-&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;OOPs makes development and maintenance easier i.e. if code grows it's easy to manage it&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;POL is not easy to manage &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;OOP provide data hiding&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;in procedure-oriented programming global data can be accessed from anywhere&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdliqxhamrky8rak7bz1j.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fdliqxhamrky8rak7bz1j.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;OOP follows the bottom-up approach&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;POL follows the top-down approach&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;OOP have many access specifiers such as public, private, protected etc&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;POL does not have any&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;updation in OOP based program is easy&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;updation in POL based program is difficult&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;because of data hiding, OOP is secure&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;POL doesn't have any proper way of data hiding, thus it is less secure&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;in OOP data is more important&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;in POL functions are more important&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;OOP is mainly used to solve real-world problems&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;POL is mainly used for unreal issues&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpdokcalwp2nycijouyok.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fi%2Fpdokcalwp2nycijouyok.jpg" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;


&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Please comment if you have any feedback or suggestions&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>java</category>
      <category>oop</category>
    </item>
    <item>
      <title>JAVA: Increment, Decrement operator</title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Wed, 09 Dec 2020 13:42:06 +0000</pubDate>
      <link>https://dev.to/supriya2371997/java-increment-decrement-operator-4084</link>
      <guid>https://dev.to/supriya2371997/java-increment-decrement-operator-4084</guid>
      <description>&lt;p&gt;Please go through &lt;a href="https://dev.to/supriya2371997/java-theory-of-operators-precedence-associativity-11an"&gt;Java: theory of Operators, Precedence &amp;amp; Associativity&lt;br&gt;
&lt;/a&gt; for other operators and basics of below-mentioned operators&lt;/p&gt;

&lt;p&gt;Q1: Increment operator?&lt;br&gt;
Q2: Decrement operator?&lt;br&gt;
Q3: Facts?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Increment operator:-&lt;/strong&gt;&lt;br&gt;
-: used to increment a value by 1.&lt;br&gt;
-: 2 varieties are available that are pre-increment and post-increment.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Pre-Increment: value is first used for calculating the result and then incremented&lt;br&gt;
For example X=42&lt;br&gt;
        y=++X&lt;br&gt;
  step1: x=x+1 (x=42+1=43)&lt;br&gt;
  step2: y=x (y=43)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Post-Increment: value is incremented and then calculated the result&lt;br&gt;
For example X=42&lt;br&gt;
        y=X++&lt;br&gt;
  step1: y=x (y=42)&lt;br&gt;
  step2: x=x+1 (x=42+1=43)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Decrement operator:-&lt;/strong&gt;&lt;br&gt;
-: used to decrement a value by 1.&lt;br&gt;
-: 2 varieties available that are pre-decrement and post-decrement&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Pre-Decrement: value is first used for calculating the result and then decremented&lt;br&gt;
For example X=42&lt;br&gt;
        y=--X&lt;br&gt;
  step1: x=x-1 (x=42-1=41)&lt;br&gt;
  step2: y=x (y=41)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Post-Decrement: value is decremented and then calculated the result&lt;br&gt;
For example X=42&lt;br&gt;
        y=X--&lt;br&gt;
  step1: y=x (y=42)&lt;br&gt;
  step2: x=x-1 (x=42-1=41)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CZcsc8sO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9cpgk0taomao0mpevlg3.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CZcsc8sO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/9cpgk0taomao0mpevlg3.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Facts:-&lt;/strong&gt;&lt;br&gt;
F1. Nesting like ++(++a) is not allowed&lt;br&gt;
   error: unexpected type&lt;/p&gt;

&lt;p&gt;F2. Can be only used with variables.&lt;br&gt;
   program.java:9: error: unexpected type&lt;br&gt;
       a = 34++;&lt;br&gt;
            ^&lt;br&gt;
   required: variable&lt;/p&gt;

&lt;p&gt;F3. Can't be used on final variables&lt;br&gt;
   error: cannot assign a value to final variable a&lt;/p&gt;

&lt;p&gt;F4. Can be only applied only on all primitive data types&lt;br&gt;
   error: bad operand type boolean for unary operator '++'&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Please comment if you have any feedback or suggestions&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>java</category>
    </item>
    <item>
      <title>JAVA: theory of Operators, Precedence &amp; Associativity </title>
      <dc:creator>Supriya Kolhe</dc:creator>
      <pubDate>Wed, 09 Dec 2020 11:46:21 +0000</pubDate>
      <link>https://dev.to/supriya2371997/java-theory-of-operators-precedence-associativity-11an</link>
      <guid>https://dev.to/supriya2371997/java-theory-of-operators-precedence-associativity-11an</guid>
      <description>&lt;p&gt;Q1:  What are the operators?&lt;br&gt;
Q2:  Types?&lt;br&gt;
Q3:  Arithmetic operators?&lt;br&gt;
Q4:  Assignment Operators?&lt;br&gt;
Q5:  Relational Operators?&lt;br&gt;
Q6:  Logical Operators?&lt;br&gt;
Q7:  Unary Operators?&lt;br&gt;
Q8:  Bitwise Operators?&lt;br&gt;
Q9:  instanceof Operator?&lt;br&gt;
Q10: Ternary Operator?&lt;br&gt;
Q11: Precedence and Associativity of Operators&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. What are the operators:-&lt;/strong&gt;&lt;br&gt;
-symbols that perform operations on variables and values. For example, + is used to perform an addition operation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Types:-&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Arithmetic Operators&lt;/li&gt;
&lt;li&gt;Assignment Operators&lt;/li&gt;
&lt;li&gt;Relational Operators&lt;/li&gt;
&lt;li&gt;Logical Operators&lt;/li&gt;
&lt;li&gt;Unary Operators&lt;/li&gt;
&lt;li&gt;Bitwise Operators&lt;/li&gt;
&lt;li&gt;instanceof  Operator&lt;/li&gt;
&lt;li&gt;Ternary Operator&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;3. Arithmetic Operators:-&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;these operators are used to perform basic mathematical operations on variables or data. For example, a+b or so&lt;/li&gt;
&lt;li&gt;Addition :  a+b, here, a is added with b variable&lt;/li&gt;
&lt;li&gt;Subtraction :  a-b, here, b is subtracted from b variable&lt;/li&gt;
&lt;li&gt;Multiplication :  a*b, here, a is multiplied wth b variable&lt;/li&gt;
&lt;li&gt;Division :  a/b, here, b is divided by a&lt;/li&gt;
&lt;li&gt;Modulus :  a%b, here, remainder after division of b by a is passes&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;4. Assignment Operators:-&lt;/strong&gt;&lt;br&gt;
-used to store the value in variable right after performing basic mathematical operations&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;= :  Assignment, used to assign values to variables. a=6 will store 6 value in a variable. It assigns the value on it's the right side to it's left.&lt;/li&gt;
&lt;li&gt;+= :  Addition Assignment, a += b will work as a = a + b;&lt;/li&gt;
&lt;li&gt;-= : Subtraction Assignment, a -= b; will work as a = a - b;&lt;/li&gt;
&lt;li&gt;*= :  Multiplication Assignment, a *= b; will work as a = a * b;&lt;/li&gt;
&lt;li&gt;/= : Division Assignment, a /= b; will work as a = a / b;&lt;/li&gt;
&lt;li&gt;%= : Modulus Assignment, a %= b; will work as a = a % b;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;5. Relational Operators:-&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;== :  Is Equal To, 3 == 9 returns false&lt;/li&gt;
&lt;li&gt;!= :  Not Equal To, 8 != 5 returns true&lt;/li&gt;
&lt;li&gt;&amp;gt; :  Greater Than, 1 &amp;gt; 5 returns false&lt;/li&gt;
&lt;li&gt;&amp;lt; :  Less Than, 1 &amp;lt; 5 returns true&lt;/li&gt;
&lt;li&gt;&amp;gt;= :  Greater Than or Equal To, 1 &amp;gt;= 5 returns false&lt;/li&gt;
&lt;li&gt;&amp;lt;= :  Less Than or Equal To, 1 &amp;lt;= 5 returns false&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;6. Logical Operators:-&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&amp;amp;&amp;amp; :  logical AND, expression1 &amp;amp;&amp;amp; expression2, return true only if both expressions are true&lt;/li&gt;
&lt;li&gt;|| :  logical OR, expression1 || expression2, return true if at least one expression is true&lt;/li&gt;
&lt;li&gt;! :  logical NOT, !expression, return true if expression is not true or false&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;7. Unary Operators:-&lt;/strong&gt;&lt;br&gt;
-these operators are used only with one operand.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;+ : Unary plus, stores value as positive, but there is no need to use it since without any operator the value is taken as positive &lt;/li&gt;
&lt;li&gt;- : Unart minus, convert a negative value to a positive one, a = -10&lt;/li&gt;
&lt;li&gt;! : Logical complement operator, inverts the value of a boolean, &lt;/li&gt;
&lt;li&gt;++ : Increment operator, increments value by 1&lt;/li&gt;
&lt;li&gt;-- : Decrement operator, decrements value by 1&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;NOTE:&lt;/strong&gt; please check &lt;a href="https://dev.to/supriya2371997/java-increment-decrement-operator-4084"&gt;Java: Increment, Decrement operator&lt;/a&gt; for detailed ++ and --.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;8. Bitwise Operators:-&lt;/strong&gt;&lt;br&gt;
-used to perform operations on individual bits&lt;br&gt;
-can be used with any of the integer types&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;~ : Bitwise Complement, return 1n's complement&lt;/li&gt;
&lt;li&gt;&amp;amp; : Bitwise AND. returns bit by bit AND of input values&lt;/li&gt;
&lt;li&gt;| : Bitwise OR, returns bit by bit OR of input values&lt;/li&gt;
&lt;li&gt;^ : Bitwise XOR, returns bit by bit XOR of input values&lt;/li&gt;
&lt;li&gt;&amp;lt;&amp;lt; :  Left Shift Operator, shifts all bits towards the left by a certain number of specified bits.
For example, number&amp;lt;&amp;lt;2 where 2 means 2-bit operation&lt;/li&gt;
&lt;li&gt;&amp;lt;&amp;lt;&amp;lt; : Unsigned Left shift operator, since "&amp;lt;&amp;lt;&amp;lt;" and "&amp;lt;&amp;lt;" are similar, there is no "&amp;lt;&amp;lt;&amp;lt;" operator in java.&lt;/li&gt;
&lt;li&gt;&amp;gt;&amp;gt; : Signed Right Shift Operator, shifts all bits towards the right by a certain number of specified bits, 
For example, number&amp;gt;&amp;gt;2 where 2 means 2-bit operation&lt;/li&gt;
&lt;li&gt;&amp;gt;&amp;gt;&amp;gt; : Unsigned Right Shift Operator&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;9. instanceof:-&lt;/strong&gt;&lt;br&gt;
-checks whether an object is an instanceof a particular class&lt;br&gt;
-For example, output = str instanceof String;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;10. Ternary Operator:-&lt;/strong&gt;&lt;br&gt;
-short trick for "if-then-else" statement&lt;br&gt;
-Syntax: variable = expression ? expression1 : expression2&lt;br&gt;
OR you can also say,&lt;br&gt;
variable = condition ? if_execution_block: else_execution_block&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;11. Precedence and Associativity of Operators:-&lt;/strong&gt;&lt;br&gt;
-higher it appears in the table, the higher its precedence&lt;br&gt;
-If an expression has more than one operators with similar precedence, the expression is evaluated according to its associativity i.e. left to right or right to left. For example, x=y=z=a, here allocation will be followed from right to left.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--994qsFME--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0gye260bdb10ksdh848o.JPG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--994qsFME--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/0gye260bdb10ksdh848o.JPG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;-General doubts on Precedence and Associativity:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;using + in System.out.println(): in order to perform addition operation in System.out.println(), one should make sure to add them in parenthesis. Now the question arises why? Well, associativity of addition is left to right and hence integers are added to a string first and so forth.&lt;/li&gt;
&lt;li&gt;is something like a=n+++o right? the answer is yes because it is understood by the compiler as a, =, n, ++, +, 0.
But something like a=b+++++c will not work since there is no operand after the second unary operator.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Please comment if you have any feedback or suggestions&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>java</category>
    </item>
  </channel>
</rss>
