Udemy coupon 100 off 2017 ::Udemy coupon code free :: Get 100+ Free Udemy coupons Here

Java Interview Programs pdf

Java Interview Programs pdf

Top Development Courses- Programming Java for Beginners

Comming Soon

Find out Factorial of a Given Number - with and with out Recursion

Find out Factorial of a Given Number - with and with out Recursion

Here is output :



With Out Recursion
Out Put is as following :




import java.io.*;
class FactorialWithoutRecursion
{
public static void main(String args[]) throws IOException
{
int i, product=1;

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter the Number : ");
  int n=Integer.parseInt(br.readLine());

System.out.print("Factorial of " + n + " is..  ");
for(i=n;i>=1;i--)
{
if(i!=1)
{
System.out.print(i + " * ");
}
else
{
System.out.print(i );
}
product=product*i;
}
System.out.println(" = "  + product);
}
}
  • Save the file with name FactorialWithoutRecursion.java 
  • Compile with: javac FactorialWithoutRecursion.java
  • Run with: java FactorialWithoutRecursion




With use of Recursion:


Out Put is as following :



import java.io.*;
class Factorial 
{
// this is a recursive function
int fact(int n) 
{
int result;
if(n!=1)
{
System.out.print(n+" * ");
}
else
{
System.out.print( n );
}
if(n==1) return 1;

result = fact(n-1) * n;
return result;
}
}
class FactWithRecursion 
{
public static void main(String args[]) throws IOException
{
int r;
Factorial f = new Factorial();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter the Number : ");
  int n=Integer.parseInt(br.readLine());
System.out.print("Factorial of "+ n +" is " );
r=f.fact(n);
System.out.print(" = "+r);
}
}
  • Save the file with name FactWithRecursion.java 
  • Compile with: javac FactWithRecursion.java
  • Run with: java FactWithRecursion

String given as command line argument is Palindrome or not



Check String given as command line argument is Palindrome or not?


Out Put is as following :


import java.util.*;

class Palindrome
{
   public static void main(String args[])
   {
      String originalString, reverseString="";

      originalString = args[0];

      int length = originalString.length();

      for ( int i = length - 1 ; i >= 0 ; i-- )
         reverseString = reverseString + originalString.charAt(i);

      if (originalString.equals(reverseString))
         System.out.println("Entered string is a palindrome.");
      else
         System.out.println("Entered string is not a palindrome.");

   }
}
  • Save the file with name Palindrome.java 
  • Compile with: javac Palindrome.java
  • Run with: java Palindrome malayalam
  • Run with: java Palindrome madam
  • Run with: java Palindrome Java
  • Run with: java Palindrome good

Fibonacci Series using Java.

Fibonacci Series using Java.


Out Put is as following :

class FibonacciSeries
{
public static void main(String args[])
{
int PrevNum, NextNum, Sum, i;
PrevNum=NextNum=1;
System.out.println();
for(i=1;i<=10;i++)
{
System.out.print(PrevNum+"       ");
Sum=PrevNum+NextNum;
PrevNum=NextNum;
NextNum=Sum;
}
}
}




  • Save the file with name FibonacciSeries.java 
  • Compile with: javac FibonacciSeries.java
  • Run with: java FibonacciSeries


Animation Demo JavaFX

Animation Demo JavaFX

We have come up with New and Better avatar!

Now enjoy our improved version!


This post has been moved to :


http://www.puretechy.com/blog/javafx-animation

Image Editor Using JavaFx


Image Editor Using JavaFX

We have come up with New and Better avatar!

Now enjoy our improved version!

This post has been moved to :

http://www.puretechy.com/blog/javafx-application-image-editor


Sine Wave Using JavaFX

Sine Wave Using JavaFX

We have come up with New and Better avatar!

Now enjoy our improved version!


This post has been moved to :


http://www.puretechy.com/blog/javafx-example-javafx-sine-wave

Animation Example Using JavaFX.

Animation Demo JavaFX

We have come up with New and Better avatar!

Now enjoy our improved version!


This post has been moved to :


http://www.puretechy.com/blog/javafx-animation

JPA with JavaFX - Student Management System

JPA with JavaFX - Student Management System

We have come up with New and Better avatar!

Now enjoy our improved version!


This post has been moved to :


http://www.puretechy.com/blog/jpa-with-javafx-example

Find out Reverse Number of a given Number.

Find out Reverse Number of a given Number.

Out Put is as following :


Source code: 

import java.io.*;
class ReverseOfNum 
{
public static void main(String args[]) throws IOException
{
int num, temp,reverse=0;
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter the Number You Want to Reverse : ");
num=Integer.parseInt(br.readLine());

while(num>0)
{
temp=num%10;
reverse=reverse*10+temp;
num=num/10;

}
System.out.println("Result is  : " + reverse);
}
}

  • Save the file with name ReverseOfNum .java 
  • Complie with: javac ReverseOfNum .java
  • Run with: java ReverseOfNum 


Split the numbers list based on odd & even and list of Strings based Starting character

Split the numbers list based on odd & even

Here is output :





Source code: 

import java.io.*;
class SplitListForNumbers
{
   public static void main(String args[]) throws IOException
{

int i;
int [] array_values=new int[50];
  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter the Total Number Of  Elements You Want to Enter : ");
  int n=Integer.parseInt(br.readLine());

   System.out.println("Now enter the values  : ");
  for(i=0;i<n;i++)
{
         array_values[i]=Integer.parseInt(br.readLine());
     }

    System.out.println("Even List is:  ");
   for(i=0;i<n;i++)
{
        if(array_values[i]%2==0)
{
                  System.out.println(array_values[i]);
             }
}

System.out.println("Odd List is :  ");
                 for(i=0;i<n;i++)
{
            if(array_values[i]%2!=0)
{
         System.out.println(array_values[i]);
}
}
}
}

  • Save the file with name SplitListForNumbers.java 
  • Complie with: javac SplitListForNumbers.java
  • Run with: java SplitListForNumbers


Split the list of Strings based Starting character.

Out Put is as following :


Source code: 

import java.io.*;
class SplitListForString
{
   public static void main(String args[]) throws IOException
{
int i;
boolean t=false;
char comp[]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
String [] array_values=new String[50];
  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter the Total Number Of  Elements You Want to Enter : ");
  int n=Integer.parseInt(br.readLine());

   System.out.println("Now enter the values  : ");
  for(i=0;i<n;i++)
{
         array_values[i]=br.readLine();
     }

for(i=0;i<26;i++)
{
t=false;
System.out.println(" \n \n----------------------------"+"List with char  " + comp[i] + "-------------------------");
for(int j=0;j<n;j++)
{
if(comp[i]==array_values[j].charAt(0))
{
System.out.println(    array_values[j]);
t=true;
}
}
if(!t)
{
System.out.println(    "No Entries Found !");
}
     }
}
}

  • Save the file with name SplitListForString.java 
  • Complie with: javac SplitListForString.java
  • Run with: java SplitListForString

Bubble Sort in ascending and descending order

Bubble Sort in ascending order

Out Put is as following :



Source code: 

import java.io.*;
public class BubbleSort
{
public static void main(String[] args) throws IOException
{
int i,j,t;
int [] array_values=new int[50];
  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter the Total Number Of  Elements You Want to Enter : ");
  int n=Integer.parseInt(br.readLine());

   System.out.println("Now enter the values to Short  : ");
  for(i=0;i<n;i++)
{
         array_values[i]=Integer.parseInt(br.readLine());
     }

  for(i = 0; i < n; i++)
{
  for(j = 1; j < (n-i); j++)
{
 if(array_values[j-1] > array_values[j])
{
   t = array_values[j-1];
   array_values[j-1]=array_values[j];
  array_values[j]=t;
   }
  }
 }
System.out.println("\n\nShorted Values are : ");
  for(i = 0; i < n; i++)
{
System.out.println(array_values[i]);
}
}
}

  • Save the file with name BubbleSort.java 
  • Complie with: javac BubbleSort.java
  • Run with: java BubbleSort


Bubble Sort in descending order

Out Put is as following :

Source code: 

import java.io.*;
public class BubbleSortDesc
{
public static void main(String[] args) throws IOException
{
int i,j,t;
int [] array_values=new int[50];
  
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
   System.out.println("Enter the Total Number Of  Elements You Want to Enter : ");
  int n=Integer.parseInt(br.readLine());

   System.out.println("Now enter the values to Short  : ");
  for(i=0;i<n;i++)
{
         array_values[i]=Integer.parseInt(br.readLine());
     }

  for(i = 0; i < n; i++)
{
  for(j = 1; j < (n-i); j++)
{
 if(array_values[j-1] < array_values[j])
{
   t = array_values[j-1];
   array_values[j-1]=array_values[j];
  array_values[j]=t;
   }
  }
 }
System.out.println("\n\nShorted Values are : ");
  for(i = 0; i < n; i++)
{
System.out.println(array_values[i]);
}
}
}

  • Save the file with name BubbleSortDesc.java 
  • Complie with: javac BubbleSortDesc.java
  • Run with: java BubbleSortDesc