<?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: Saraswathi P</title>
    <description>The latest articles on DEV Community by Saraswathi P (@saraswathi_p_d12f8b88b244).</description>
    <link>https://dev.to/saraswathi_p_d12f8b88b244</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%2F3355744%2Fa710fb8f-201e-4174-bf38-d5967a416bd5.png</url>
      <title>DEV Community: Saraswathi P</title>
      <link>https://dev.to/saraswathi_p_d12f8b88b244</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/saraswathi_p_d12f8b88b244"/>
    <language>en</language>
    <item>
      <title>Format Specifier in java</title>
      <dc:creator>Saraswathi P</dc:creator>
      <pubDate>Tue, 28 Oct 2025 18:48:28 +0000</pubDate>
      <link>https://dev.to/saraswathi_p_d12f8b88b244/format-specifier-in-java-4c56</link>
      <guid>https://dev.to/saraswathi_p_d12f8b88b244/format-specifier-in-java-4c56</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is a Format Specifier?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A format specifier is a special symbol used inside System.out.printf() or String.format() to control how values are printed.&lt;/p&gt;

&lt;p&gt;It starts with a % sign, followed by a character or number that tells Java what type of value to print and how to format it.&lt;/p&gt;

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

&lt;p&gt;&lt;code&gt;System.out.printf("My age is %d and my name is %s", 20, "Saraswathi");&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
&lt;strong&gt;output&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;My age is 20 and my name is Saraswathi&lt;br&gt;
&lt;/code&gt;&lt;br&gt;
Here:&lt;br&gt;
 %d → integer (age)&lt;br&gt;
 %s → string (name)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Common Format Specifiers&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;%d&lt;/code&gt; → for all integer types (&lt;code&gt;byte&lt;/code&gt;, &lt;code&gt;short&lt;/code&gt;, &lt;code&gt;int&lt;/code&gt;, &lt;code&gt;long&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;%f&lt;/code&gt; → for floating-point numbers (&lt;code&gt;float&lt;/code&gt;, &lt;code&gt;double&lt;/code&gt;)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;%c&lt;/code&gt;→ for characters&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;%b&lt;/code&gt; → for booleans&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;%s&lt;/code&gt; → for strings&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Special Characters (Escape Sequences)&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;\n&lt;/code&gt; -&amp;gt; moves to next line&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;\t&lt;/code&gt; -&amp;gt; adds horizontal space&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;%n&lt;/code&gt; -&amp;gt; newline&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Formatting Options&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You can control width, alignment, and precision:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;%5d&lt;/code&gt;     Print integer in a field of width 5 (right-aligned)  &lt;code&gt;'   25'&lt;/code&gt;&lt;br&gt;&lt;br&gt;
 &lt;code&gt;%-5d&lt;/code&gt;    Print integer in width 5 (left-aligned)              &lt;code&gt;'25   '&lt;/code&gt;&lt;br&gt;&lt;br&gt;
 &lt;code&gt;%05d&lt;/code&gt;    Print integer padded with zeros                      &lt;code&gt;'00025'&lt;/code&gt;&lt;br&gt;&lt;br&gt;
 &lt;code&gt;%.2f&lt;/code&gt;    Print float with 2 digits after decimal              &lt;code&gt;3.14&lt;/code&gt;&lt;br&gt;&lt;br&gt;
 &lt;code&gt;%10.2f&lt;/code&gt;  Total width = 10, 2 digits after decimal             &lt;code&gt;'      3.14'&lt;/code&gt; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;example&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 FormatDemo {
    public static void main(String[] args) {
        int age = 22;
        float mark = 95.678f;
        char grade = 'A';
        String name = "Saraswathi";
        boolean pass = true;

        System.out.printf("Name: %-10s Age: %2d  Marks: %.2f  Grade: %c  Pass: %b%n",
                          name, age, mark, grade, pass);
    }
}

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;output&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;Name: Saraswathi Age: 22  Marks: 95.68  Grade: A  Pass: true&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>java Arrays</title>
      <dc:creator>Saraswathi P</dc:creator>
      <pubDate>Tue, 28 Oct 2025 17:53:11 +0000</pubDate>
      <link>https://dev.to/saraswathi_p_d12f8b88b244/java-arrays-3p3b</link>
      <guid>https://dev.to/saraswathi_p_d12f8b88b244/java-arrays-3p3b</guid>
      <description>&lt;p&gt;Arrays are used to store multiple values in a single variable, instead of declaring separate variables for each value.&lt;/p&gt;

&lt;p&gt;To declare an array, define the variable type with square brackets [ ] :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] names;

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

&lt;/div&gt;



&lt;p&gt;We have now declared a variable that holds an array of strings. To insert values to it, you can place the values in a comma-separated list, inside 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;String[] names = {"Saras","Krithi","Brindha","Magi"};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To create an array of integers, you could write:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;int[] numbers = {10, 20, 30, 40};

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Access the Elements of an Array
&lt;/h2&gt;

&lt;p&gt;You can access an array element by referring to the index number.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] names = {"Saras","Krithi","Brindha","Magi"};
System.out.println(names[0]);
//output:Saras


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

&lt;/div&gt;



&lt;p&gt;This statement accesses the value of the first element in names: Array indexes start with 0: [0] is the first element. [1] is the second element, etc.&lt;/p&gt;

&lt;h2&gt;
  
  
  Change an Array Element
&lt;/h2&gt;

&lt;p&gt;To change the value of a specific element, refer to the index number:&lt;br&gt;
&lt;code&gt;names[0] = "Sri"&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] names = {"Saras","Krithi","Brindha","Magi"};
names[0] = "Sri";
System.out.println(names[0]);
//Now outputs Sri instead of Saras
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Array Length
&lt;/h2&gt;

&lt;p&gt;To find out how many elements an array has, use the length property:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] names = {"Saras","Krithi","Brindha","Magi"};
System.out.println(names.length);
// Outputs 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;strong&gt;new&lt;/strong&gt; Keyword&lt;br&gt;
You can also create an array by specifying its size with new. &lt;br&gt;
This makes an empty array with space for a fixed number of elements, which you can fill later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;String[] names = new String[4]; // size is 4
names[0] = "Saras";
names[1] = "Krithi";
names[2] = "Brindha"
names[3] = "Brindha"

System.out.println(names[0]); // Output:Saras
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, if you already know the values, you don't need to write new. Both of these create the same array:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//with **new**
String[] names = new String[] {"Saras","Krithi","Brindha","Magi"};
// Shortcut (most common)
String[] names = {"Saras","Krithi","Brindha","Magi"};

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

&lt;/div&gt;



&lt;p&gt;You cannot write new String[4] {"Volvo", "BMW", "Ford", "Mazda"}.&lt;/p&gt;

&lt;p&gt;In Java, when using new, you either:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use new String[4] to create an empty array with 4 slots, and then fill them later &lt;/li&gt;
&lt;li&gt;Or use new String[]  {"Saras","Krithi","Brindha","Magi"}; (without specifying the number of elements) to create the array and assign values at the same time
The shortcut syntax is most often used when the values are known at the start. Use new with a size when you want to create an empty array and fill it later.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Java Arrays Loop
&lt;/h2&gt;

&lt;p&gt;You can loop through the array elements with the for loop, and use the length property to specify how many times the loop should run.&lt;/p&gt;

&lt;p&gt;This example creates an array of strings and then uses a for loop to print each element, one by one:&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 Main {
  public static void main(String[] args) {
    String[] cars = {"Saras", "Krithi", "Brindha", "Magi"};
    for (int i = 0; i &amp;lt; cars.length; i++) {
      System.out.println(cars[i]);
    }
  }
}
//output
Saras
Krithi
Brindha
Magi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a similar example with numbers. We create an array of integers and use a for loop to print each value:&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 Main {
  public static void main(String[] args) {
    int[] numbers = {10, 20, 30, 40};

    for (int i = 0; i &amp;lt; numbers.length; i++) {
      System.out.println(numbers[i]);
    }
  }
}
//output
10
20
30
40
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Calculate the Sum of Elements
&lt;/h2&gt;

&lt;p&gt;Now that you know how to work with arrays and loops, let's use them together to calculate the sum of all elements in an array:&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 Main {
  public static void main(String[] args) {
    int[] numbers = {1, 5, 10, 25};
    int sum = 0;

    // Loop through the array and add each element to sum
    for (int i = 0; i &amp;lt; numbers.length; i++) {
      sum += numbers[i];
    }

    System.out.println("The sum is: " + sum);
  }
}
//output
The sum is: 41 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  what is += in java?
&lt;/h2&gt;

&lt;p&gt;In Java, += is an addition assignment operator. It is a shorthand way to add a value to a variable and then assign the result back to that same variable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Functionality:&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Examples:&lt;br&gt;
Numeric Addition.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    int x = 5;
    x += 3; // This is equivalent to x = x + 3; so x becomes 8
    System.out.println(x); // Output: 8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;String Concatenation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    String message = "Hello";
    message += " World"; // This is equivalent to message = message + " World";
    System.out.println(message); // Output: Hello World
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It is a compound assignment operator, combining an arithmetic operation (addition) with an assignment operation.&lt;br&gt;
It works for both numeric types (integers, floats, doubles) and String types (for concatenation).&lt;/p&gt;
&lt;h2&gt;
  
  
  Loop Through an Array with For-Each
&lt;/h2&gt;

&lt;p&gt;The "for-each" loop in Java, also known as the enhanced for loop, is a control flow statement introduced in Java 5 to simplify iteration over arrays and collections.&lt;br&gt;
 It provides a more concise and readable way to process each element in a collection without explicitly managing an index or iterator. &lt;/p&gt;
&lt;h2&gt;
  
  
  Syntax:
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (DataType variable : collection) {
    // Loop body: statements to be executed for each element
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Explanation:
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;DataType&lt;/code&gt;: This specifies the data type of the elements within the collection.&lt;br&gt;
&lt;code&gt;variable&lt;/code&gt;: This is a new variable declared within the loop, and in each iteration, it takes on the value of the current element from the collection.&lt;br&gt;
&lt;code&gt;collection&lt;/code&gt;: This refers to the array or an object that implements the Iterable interface (e.g., ArrayList, HashSet, LinkedList). &lt;/p&gt;
&lt;h2&gt;
  
  
  How it works:
&lt;/h2&gt;

&lt;p&gt;The for-each loop iterates through each element of the &lt;code&gt;collection&lt;/code&gt;from beginning to end. In each iteration, the&lt;code&gt;variable&lt;/code&gt; is automatically assigned the value of the current element, and the code within the loop body is executed.&lt;/p&gt;
&lt;h2&gt;
  
  
  Example:
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Main {
  public static void main(String[] args) {
    String[] cars = {"Volvo", "BMW", "Ford", "Mazda"};

    for (String car : cars) {
      System.out.println(car);
    }    
  }
}
//output:
Volvo
BMW
Ford
Mazda 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Limitations:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;No Index Access&lt;/code&gt;:You cannot directly access the index of the current element within a for-each loop. If index access is required, a traditional for loop is necessary.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;No Element Modification&lt;/code&gt;:You cannot modify the elements of the underlying collection directly within a for-each loop. If modification is needed, a traditional for loop or an iterator (for collections) should be used.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;Forward Iteration Only&lt;/code&gt;:It only supports forward iteration through the collection; reverse or selective iteration is not possible.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;you can create any empty array that value is 0 in default.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
public class Student{
    public static void main(String args[]){
        int[] roll_no=new int[6];
        roll_no[0]=1;
        roll_no[1]=2;
        System.out.println(roll_no[0]);
        System.out.println(roll_no[4]);
        System.out.println(roll_no[1]);

    }
}
output
1
0
2

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

&lt;/div&gt;


&lt;p&gt;in the above program roll_no[4] can't be initialized but i got the output was 0. that means all int data type array have a default value 0&lt;/p&gt;
&lt;h2&gt;
  
  
  1D Array
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;public class Student{
    public static void main(String args[]){
        int[] roll_no=new int[10];
        roll_no[0]=1;
        roll_no[1]=2;
        for(int i=0; i&amp;lt;10; i++){ //i=0 means index start from 0
        System.out.println(roll_no[i]);


        }

    }
}
output
1
2
0
0
0
0
0
0
0
0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;2D Array&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 Student{
    public static void main(String args[]){
        int[][] roll_no=new int[4][3];
        roll_no[0][0]=1;
        roll_no[0][1]=2;
        roll_no[0][2]=3;
        roll_no[1][0]=4;
        roll_no[1][1]=5;
        roll_no[1][2]=6;
        roll_no[2][0]=7;
        roll_no[2][1]=8;
        roll_no[2][2]=9;
        roll_no[3][0]=10;
        roll_no[3][1]=11;
        roll_no[3][2]=12;


        for(int i=0; i&amp;lt;4; i++){
            for(int j=0; j&amp;lt;3; j++) {
        System.out.print(roll_no[i] [j]+"\t");
            }
            System.out.println();


        }

    }
}
ouput
1  2  3
4  5  6
7  8  9
10 11 12 

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

&lt;/div&gt;



&lt;p&gt;Reducing array initialization&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 Student{
    public static void main(String args[]){
        int[][] roll_no=new int[4][3];
        int num=1;

        for(int i=0; i&amp;lt;4; i++){
            for(int j=0; j&amp;lt;3; j++) {
            num=roll_no[i][j];
            num++;
            System.out.print(num +"\t");


            }
            System.out.println( );



        }

    }
}
output
1  1  1
1  1  1
1  1  1 

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

&lt;/div&gt;



&lt;p&gt;Here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;I created a 2D array&lt;code&gt;roll_no[4][3]&lt;/code&gt;, but i never store any numbers inside it — all elements start as 0 (the default for &lt;code&gt;int&lt;/code&gt;).&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then i do &lt;code&gt;num = roll_no[i][j]&lt;/code&gt;; → so &lt;code&gt;num&lt;/code&gt; becomes &lt;code&gt;0&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Then &lt;code&gt;num++&lt;/code&gt; → becomes &lt;code&gt;1&lt;/code&gt; every time.&lt;br&gt;
So my output will be all 1’s:&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Corrected program&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 Student {
    public static void main(String[] args) {
        int[][] roll_no = new int[4][3];
        int num = 1;

        // Fill and print the array
        for (int i = 0; i &amp;lt; 4; i++) {
            for (int j = 0; j &amp;lt; 3; j++) {
                roll_no[i][j] = num;         // store number in array
                System.out.print(roll_no[i][j] + "\t");
                num++;                        // increase for next value
            }
            System.out.println();
        }
    }
}
output
1   2  3
4   5  6
7   8  9
10  11  12

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;What changed:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;roll_no[i][j] = num&lt;/code&gt;; → actually stores the number inside the array.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;num++&lt;/code&gt; → moves to the next number for each element.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;🧠 Default values by data type&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Data Type&lt;/th&gt;
&lt;th&gt;Example Array&lt;/th&gt;
&lt;th&gt;Default Value&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;byte&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;new byte[5]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;short&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;new short[5]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;int&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;new int[5]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;long&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;new long[5]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0L&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;float&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;new float[5]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0.0f&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;double&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;new double[5]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;0.0&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;char&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;new char[5]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;
&lt;code&gt;'\u0000'&lt;/code&gt; (blank character)&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;code&gt;boolean&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;new boolean[5]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;false&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;String&lt;/code&gt; (or any object)&lt;/td&gt;
&lt;td&gt;&lt;code&gt;new String[5]&lt;/code&gt;&lt;/td&gt;
&lt;td&gt;&lt;code&gt;null&lt;/code&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

</description>
    </item>
    <item>
      <title>#java</title>
      <dc:creator>Saraswathi P</dc:creator>
      <pubDate>Mon, 27 Oct 2025 09:07:32 +0000</pubDate>
      <link>https://dev.to/saraswathi_p_d12f8b88b244/java-3pop</link>
      <guid>https://dev.to/saraswathi_p_d12f8b88b244/java-3pop</guid>
      <description>&lt;h2&gt;
  
  
  What is java?
&lt;/h2&gt;

&lt;p&gt;Java is a high-level, object-oriented programming language developed by Sun Microsystems in 1995. It is mostly used for building desktop applications, web applications, Android apps, and enterprise systems.&lt;/p&gt;

&lt;h2&gt;
  
  
  why use java?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; Java works on different platforms (Windows, Mac, Linux, Raspberry Pi, etc.)&lt;/li&gt;
&lt;li&gt; It is one of the most popular programming languages in the world&lt;/li&gt;
&lt;li&gt;It has a large demand in the current job market&lt;/li&gt;
&lt;li&gt;It is easy to learn and simple to use&lt;/li&gt;
&lt;li&gt;It is open-source and free&lt;/li&gt;
&lt;li&gt;It is secure, fast and powerful&lt;/li&gt;
&lt;li&gt; It has huge community support (tens of millions of developers)&lt;/li&gt;
&lt;li&gt;Java is an object oriented language which gives a clear structure to programs and allows code to be reused, lowering development costs&lt;/li&gt;
&lt;li&gt; As Java is close to C++ and C#, it makes it easy for programmers to switch to Java or vice versa&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnf8ryd3hmos2fivqvsbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnf8ryd3hmos2fivqvsbn.png" alt=" " width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Object-Oriented Programming (OOP):&lt;/strong&gt; Java supports OOP concepts to create modular and reusable code.&lt;br&gt;
    &lt;strong&gt;Platform Independence:&lt;/strong&gt; Java programs can run on any operating system with a JVM.&lt;br&gt;
    &lt;strong&gt;Robust and Secure:&lt;/strong&gt; Java ensures reliability and security through strong memory management and exception handling.&lt;br&gt;
    &lt;strong&gt;Multithreading and Concurrency:&lt;/strong&gt; Java allows concurrent execution of multiple tasks for efficiency.&lt;br&gt;
   &lt;strong&gt;Rich API and Standard Libraries:&lt;/strong&gt; Java provides extensive built-in libraries for various programming needs.&lt;br&gt;
    &lt;strong&gt;Frameworks for Enterprise and Web Development:&lt;/strong&gt; Java supports frameworks that simplify enterprise and web application development.&lt;br&gt;
    &lt;strong&gt;Open-Source Libraries:&lt;/strong&gt; Java has a wide range of libraries to extend functionality and speed up development.&lt;br&gt;
   &lt;strong&gt;Maintainability and Scalability:&lt;/strong&gt; Java’s structured design allows easy maintenance and growth of applications.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding the Hello World Program in Java&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;// A Java program to print Hello World!
public class HelloWorld {
    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

Output:
Hello World!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt; // Starts a single-line comment. The comment is not executed by Java.&lt;/li&gt;
&lt;li&gt;public class HelloWorld defines a class named HelloWorld. In Java, every program must be inside a class.&lt;/li&gt;
&lt;li&gt;public static void main(String[] args) is the entry point of any Java application. It tells the JVM where to start executing the program.&lt;/li&gt;
&lt;li&gt;System.out.println("Hello, World!"); prints the message to the console.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;In Java, every application begins with a class name, and that class must match the filename.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to run the above code?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Write code in a file like HelloWorld.java.&lt;/li&gt;
&lt;li&gt;The Java Compiler "javac" compiles it into bytecode "HelloWorld.class".&lt;/li&gt;
&lt;li&gt;The JVM (Java Virtual Machine) reads the .class file and interprets the bytecode.&lt;/li&gt;
&lt;li&gt;JVM converts bytecode to machine readable code i.e. "binary" (001001010) and then execute the program.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faot85067npxio6uqrfea.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Faot85067npxio6uqrfea.webp" alt=" " width="800" height="401"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Comments in Java&lt;/strong&gt;&lt;br&gt;
The &lt;a href="https://www.geeksforgeeks.org/java/comments-in-java/" rel="noopener noreferrer"&gt;comments&lt;/a&gt; are the notes written inside the code to explain what we are doing. The comment lines are not executed while we run the program.&lt;/p&gt;

&lt;p&gt;Single-line comment&lt;br&gt;
&lt;code&gt;// This is a comment&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Multi-line comment&lt;br&gt;
&lt;code&gt;/*&lt;br&gt;
This is a multi-line comment.&lt;br&gt;
This is useful for explaining larger sections of code.&lt;br&gt;
*/&lt;/code&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>java</category>
      <category>programming</category>
    </item>
    <item>
      <title>JAVASCRIPT</title>
      <dc:creator>Saraswathi P</dc:creator>
      <pubDate>Mon, 04 Aug 2025 18:21:17 +0000</pubDate>
      <link>https://dev.to/saraswathi_p_d12f8b88b244/javascript-5ap6</link>
      <guid>https://dev.to/saraswathi_p_d12f8b88b244/javascript-5ap6</guid>
      <description>&lt;p&gt;&lt;strong&gt;What is javascript?&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;javascript is the world most papular programing language and it is easy to learn.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;javascript is used to create interactive and dynamic web pages.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;it is responsible for adding functionality to a website and allows for user interaction with the website's content.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  VARIABLES:-
&lt;/h2&gt;

&lt;p&gt;variales are containers for stroing information or data.&lt;br&gt;
&lt;strong&gt;example&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;var a=10
var b=20
console.log(a+b)

output:20
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;in the above program a and b are variables,10 and 20 are integers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;console.log -&lt;/strong&gt; it is the function in javascript used to print messages or values to the browser's console mainly for debugging purpose.&lt;/p&gt;

&lt;h2&gt;
  
  
  VARIABLE DECLARATION:-
&lt;/h2&gt;

&lt;p&gt;in javascript variable can be declared in 3 ways.&lt;br&gt;
1.&lt;strong&gt;var&lt;/strong&gt;&lt;br&gt;
2.&lt;strong&gt;let&lt;/strong&gt;&lt;br&gt;
3.&lt;strong&gt;const&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;using var keyword-&lt;/strong&gt; function scope or global scope.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var x=10
{
var y=20
}
console.log(y)

output:20 //accessible inside the block.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;using let ketword-&lt;/strong&gt; block scope.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;the let keyword introduced in 2015.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;the keyword must be declared before use.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;let keyword can not be redeclared.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;let keyword have block scope.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
let a=10
}
console.log(a)

output
Error: a is not defined // a can't be used here becauce a is the block scope.
{
let a=10
console.log(a)
}

ouput:20 // a can be used hear.

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

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;using const keyword-&lt;/strong&gt; block scope.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;in javascript the const keyword is used to declare a constant variable.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;a constant variable once assinged value cannot be reassinged or redeclared.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;it provide a way to create variable that are meant to be immutable.&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const a=10
a=20
console.log(a)

output
Error:assingnment to constant variable. //const cannot be reassinged 

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

&lt;/div&gt;



</description>
    </item>
  </channel>
</rss>
