Results for Java Tutorials

Multiplication Table using Java program

January 04, 2020


Java Code to print Multiplication Table

                    Hello, In this blog we see the java code to print multiplication table. In this program user give the input and depends on that integer number the multiplication table will displayed.

Program:
import java.util.Scanner;
public class MultiTable1
{
    public static void main(String[] args)
    {
        Scanner s = new Scanner(System.in);
 System.out.print("Enter number:");       
 int n=s.nextInt();
        for(int i=1; i <= 10; i++)
        {
            System.out.println(n+" * "+i+" = "+n*i);
        }
    }
}

                  In the above code we use variable 's' to store the input value. And by using for loop the actual multiplication table is displayed.

Output:






Multiplication Table using Java program Multiplication Table using Java program Reviewed by Amit Waghmare on January 04, 2020 Rating: 5

Fibonacci series using Java program

January 02, 2020


                     Hello friends, In this blog we see the how to generate Fibonacci series using java. In C, CPP and Python programs we see what is Fibonacci series. So Without giving the definition of Fibonacci series we see the program.

Program:
1. (Using for loop)
public class Fibonacci
{
    public static void main(String[] args)
{
        int a = 0, b = 1;
        System.out.println("First 10 terms: ");
        for (int i = 1; i <= 10; ++i)
        {
            System.out.println(a + "  ");
            int sum = a + b;
            a = b;
            b = sum;
        }
    }
}


           In  the above program we use two variables that is a and b and assign the value 0 and 1 respectively. For loop is used to initialize the value of 'i' variable and increment it by 1. And we put the condition that is the 'i' must be less than or equal to 10. So we see the output of 10 numbers only.


2. Using while loop

public class Fibonacci
{
    public static void main(String[] args)
{
        int i = 1, a = 0, b = 1;
        System.out.println("First 10 terms: ");
        while(i<=10)
        {
            System.out.println(a + "  ");
            int sum = a + b;
            a = b;
            b = sum;
            i++;
        }
    }
}

In the above code instead of for loop we use the while loop and incremented I variable in the middle loop. The output of both code is exactly same.
   
Output:





Fibonacci series using Java program Fibonacci series using Java program Reviewed by Amit Waghmare on January 02, 2020 Rating: 5

Reverse String

December 26, 2019



                           Java Program to print the Reverse String

In this blog we the java program to reverse the given string. To reverse the given string we use two variables i.e. original, reverse and reverse a string is initialized as null. Then by using a scanner, we scan the input string. This input string is stored in the original variable. Then by using length function and for loop program will reverse the string and finally stored in the reverse string. The actual code is as follows.
Code:
import java.util.*;
class ReverseString
{
public static void main(String args[])
 {
 String original,reverse="";
 Scanner in=new Scanner(System.in);
 System.out.print("Enter a string to be reverse:");
 original=in.nextLine();
 int length=original.length();
 for(int i=length-1;i>=0;i--)
  {
  reverse=reverse+original.charAt(i);
  }
 System.out.println("Reverse of entered string:"+reverse);
 }
}
Output:
C:\jp> javac ReverseString.java
C:\jp> java ReverseString
Enter a string to be reverse:TutorialLands
Reverse of entered string:sdnaLlairotuT
C:\jp>




Reverse String Reverse String Reviewed by Amit Waghmare on December 26, 2019 Rating: 5

Java Half Pyramid Pattern

December 09, 2019



Java Program to Print half inverted Pyramid

       Hello friends, In this post, we see the simple java code to print the above pattern. To print the pattern we use 2 for loop, first for rows and second for columns. 
       We initialize two variables i.e. i and j as an integer, i for Row and j for column. The difference between the keyword print and println is, print is use to print the data/statement, as well as the second data/statement is print in front of first line. For example,
Code:
class print_printlnDemo
{
public static void main(String args[])
{
System.out.print("Java ");
System.out.print("Programming ");
System.out.print("Softwere");
}
}
Output:
 
       Println is use to print the data/statement, as well as the second data/statement is print at next line. For example,  
Code:
class print_printlnDemo
{
public static void main(String args[])
{
System.out.print("Java ");
System.out.println("Programming ");
System.out.println("Softwere");
}
}
Output:

Java Program to Print half inverted Pyramid
Program:
class DisplayPattern
{
public static void main(String args[])
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=i;j<=5;j++)
{
System.out.print("*");
}
System.out.println("");
}
}
}

Output:


Java Half Pyramid Pattern Java Half Pyramid Pattern Reviewed by Amit Waghmare on December 09, 2019 Rating: 5

Simple Java Program

December 06, 2019

Java Programming

                      Hello friends, In this blog, we see how to run the Java program. It is very simple to run the java program. To run the java code your machine must have a JDK (Java Development KIT) file. When you install it on your pc one folder named as Java is created in c drive. So, first of all, we see the simple java program to display "Hello I am Java Programmer". I will explain every stapes of the program.

Program:
class intro
{
public static void main(String args[])
{
System.out.println("Hello I am Java Programmer");
}
}
            To run the program there are two stapes in that First is Compilation and second is Interpretation.

Compilation: A compilation is one type of application softwere that translates or converts the code from human-readable code to machine-readable code i.e. in the form of 0 and 1. To make this conversion successful we must write a code on the notepad and save this code with extension .java. When we compile this code on command prompt, one same name file is created with extension .class and this file is in machine-readable form.
            To compile the java code the class name and file name must same. And to compile the code on command prompt type javac intro.java

Interpretation: Interpretation means the actual execution of the program, Once we successfully compile the program we can execute it easily. To run the java program on command prompt type java class_name i.e. java intro


Stapes to run the java program:
 Step 1: Go to that folder where your java code to be saved using the command prompt.
Step 2: Set the JDK path as shown below,



Step 3: Compile the java program using syntax javac class_name.java
      (For example, javac intro.java)


Step 4: Finally to run or execute the code type java class_name


Note: In syntax, I wrote class_name which is the same as the file name.

Output:


Simple Java Program Simple Java Program Reviewed by Amit Waghmare on December 06, 2019 Rating: 5

Introduction to Java

November 24, 2019

               What is Java?                     
,

                         Java is the most broadly utilized programming language. It creates a secured, reliable and platform independent programming language. Which should be imperative and reflective.



Highlights of java


1              1.  Simple, Small and Familiar:

Java is simple because most of the features are derived from c and cpp. Java removes complexity because it does not uses the pointers.

Java is definitely not small but it is small in terms of coding and programming statements.


2             2.  Object Oriented Language:       

A programing language which supports the features like polymorphism, inheritance, Data hiding, Data abstraction, Encapsulation is called as an object oriented language.

3             3.  High performance:

Java programs are compiles to a portable intermediate code through a user defined class known as byte code. Because of this Java’s reusability is maximum and its execution speed is comparable with its native c and cpp. Java compiler convert the java code in o byte code and these byte code is executed by JVM (Java Virtual Machine) hence java programs and applications provide high performance on every platform.


4             4.  Platform Independent:

Java program written on one platform and can run on any other platform without need to recompile or any modifications.
  

5            5.  Multi-Threaded:

Multithreading means threading multiple threads at a time. Threads are used in network based applications.


6            6.  Interpreted and Compiled:

Java programs are compiles to a portable intermediate code through a user defined class known as byte code. Because of this Java’s reusability is maximum and its execution speed is comparable with its native c and cpp. Java compiler convert the java code in o byte code and these byte code is executed by JVM (Java Virtual Machine) hence java programs and applications provide high performance on every platform.


7            7.  Robust and secure (Easily executable):

Java is widely used in web servers and web pages. The ability to create the robust programs was gives a high priority during design a java. It performs compile time as well as runtime checking for datatype. Java is design with built-in tools called garbage collector, which reduces all the memory management problems for the programmers.


8             8.  Portability:

Java perform the portability because of its architecture neutrality. Source code may run on different hardware platforms to platform. This consistencies make the java platform portable on different platforms such as Windows, Unix, etc.        

                             So in next blog We see the exact coding of Java Programming.






Introduction to Java Introduction to Java Reviewed by Amit Waghmare on November 24, 2019 Rating: 5