Tuesday, 27 June 2017

👉Program-To Print Floyd Triangle  



  1.  import java.util.Scanner;
  2. public class FloydTriangle{
  3. public static void main(String[] args){
  4. Scanner in = new Scanner(System.in);
  5. System.out.println("Enter the number of rows which you want in your Floyd Triangle: ");
  6. int r = in.nextInt();
  7. int n=0;
  8. for(int i=0; i<r; i++){
  9. for(int j=0; j<=i; j++){
  10. System.out.print(++n+" ");
  11. }
  12. System.out.println();
  13. }
  14. }
  15. }

Friday, 23 June 2017

Interview Questions

👉  Basic Questions 


Ques->What is the most important feature of Java?
Ans->The most important feature of Java is that Java is a platform independent language.


Ques->What do you mean by platform independent?
Ans-> Platform independent means that we can write and compile the java code in one platform (example windows) and can execute the class in any other supported platform example (Linux ,Solaris ,etc).


Ques->what is a JVM?
Ans->JVM is Java Virtual Machine which is a run time environment for the compiled java class files.


Ques->Are JVM's platform independent?
Ans->JVM's are not platform independent. JVM's are platform specific run time implementation provided by the vendor.


Ques->What is the operation of JVM?
Ans->JVM mainly performs following operations-

  • Allocating sufficient memory space for the class properties.
  • Provides runtime environment in which java bytecode can be executed.
  • Converting byte code instructions into machine level instructions.


Ques->What is the base class of all classes?
Ans-> The base class of all classes is  java.lang.Object  .


Ques->What is the difference between Path and Classpath?
Ans->Path and Classpath are operating system level environment variables. Path is used  define where the system can find the executables(.exe) files and classpath is used to specify the location .class files.


Ques->What is API?
Ans->An API(Application Programming Interface)  is a collection of packages, classes, interfaces and sub-packages . And subpackage is also a collection of classes interfaces and sub-packages etc.


Ques->Why Java take 2 bytes of memory for store character?
Ans-> Java support more  than 18 international languages so java take 2 bytes for characters, because 18 international language 1 byte of memory is not  sufficient for storing all characters and sysmbols present in 18 languages. Java supports unicode but C support ASCII code. In ASCII code only english language are present , so  for storing all english latter and symbols 1 byte is sufficient.









Tuesday, 20 June 2017

Java


What is Java? 




Java is a high-level programming language originally developed by Sun Microsystems and released in 1995. Java runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.


Java is a programming language and a platform.

* Platform :  Any hardware or software environment in which a program runs, is known as a platform . Since Java has its own runtime environment (JRE) and  API, it is called platform.


The Java programming language is a high - level language that can be characterized by all  of the following buzzwords :


->OBJECT ORIENTED:


        In  java , everything is an object. Java can be easily extended since it is based on the object model.


->PLATFORM INDEPENDENT:

      when java is compiled , it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by virtual machine (JVM) on whichever platform it is being run.


->SIMPLE:

    Java is designed to be easy to learn.


->SECURE:

   With Java's secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.


->ARCHITECTURAL -NEUTRAL:


   Java compiler generates an architectural - neutral object file format which makes the compiled code to be executable on many processors, with the presence of java runtime system.


->PORTABLE:


   Being architectural - neutral and having no implementation dependent aspects of the specification makes java portable.


->ROBUST:


    Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.


->MULTI THREADED:


   With this feature it is possible to write programs that can do many tasks simultaneously.This design feature allows developers to construct smoothly running interactive application.


->HIGH PERFORMANCE:


  With the use of Just-In-Time compiler, java enables high performance.


->INTERPRETED:


  Java byte codes are translated on the fly to native machine instructions(interpreted) and not    stored anywhere. And since linking is a more incremental and lightweight process, the development process can be much more rapid and exploratory.


->DISTRIBUTED:


  Java is designed for the distributed environment of the internet.





*  Sun released the first public implementation as java 1.0 in 1995. I t promised write once, run anywhere (WORA) , providing no cost run-times on popular platforms.






Tuesday, 24 January 2017

Program-To find find all pairs of  elements from an array whose sum is equal to given number  


  1. class SumIsEqualTo
  2. {
  3. public static void main(String args[])
  4. {
  5. int array[]={18,4,6,12,20,16};

  6. sumEquals(array,22);
  7. }
  8. public static  void sumEquals(int arr[],int X)
  9. {
  10. if(arr.length<2)
  11.     return;

  12.    System.out.println("the set or pairs of number whose sum is equals to 22 are :");

  13. for(int i=0;i<arr.length;i++)
  14. {
  15. for(int j=1+i;j<arr.length;j++)
  16. {
  17. int temp=arr[i] + arr[j];
  18. if(temp==X)
  19. {
  20. System.out.println(arr[i] +","+arr[j]);
  21. }
  22. }
  23. }
  24. }
  25. }    

     For example:

                                            Given a  array,we need to find all pairs whose sum is equal to number X (In           above program X=22)                         
  1. array[]={18,4,6,12,20,16};
  2. Pair of elements whose sum is equal to 22 :  18, 4 and 6,16.
     

Program-To find largest number in an  array 



  1. class LargestNumber
  2. {
  3. public static void main(String args[])
  4. {
  5. int arr[]={1,5,7,9,54,8};
  6. System.out.println("Largest number in array is:"+findingNumber (arr));
  7. }
  8. public static int findingNumber(int arr[])
  9. {
  10. int largeno=arr[0];
  11. for(int i=0;i<arr.length;i++)
  12. {
  13. if(arr[i]>largeno)
  14. {
  15. largeno=arr[i];
  16. }
  17. }
  18. return largeno;
  19. }
  20. }

Wednesday, 11 January 2017

Program-To find missing number in array 



  1. class MissingNumber
  2. {
  3. public static void main(String args[])
  4. {
  5. int []arr={1,2,3,5,6,7};
  6. System.out.println("missing number from this array is :"+missingElement(arr));
  7. }
  8. public static int missingElement(int arr[])
  9. {
  10.     int n=arr.length+1;
  11. int es=n*(n+1)/2;
  12. int ac=0;
  13. for(int i=0;i< arr.length;i++)
  14. {
  15. ac=ac+arr[i];
  16. }
  17. return es-ac;
  18. }
  19. }

Program-To reverse a number using function  



  1. import java.util.*;
  2.  class ReverseNumber{
  3. public static int r=0,l;
  4. public static void Reverse(int n){
  5.  
  6.  while(n>0)
  7.  {
  8.    l=n%10;
  9.            r=(r*10)+l;
  10.            n=n/10;   
  11.  }
  12.  System.out.println(r);
  13.  }
  14.  public static void main(String args[])
  15.  {       
  16.      int n;
  17.  Scanner ov=new Scanner(System.in);
  18.  System.out.println("Enter the number");
  19.  n=ov.nextInt();
  20.  System.out.println("Reverse of the number is:");
  21.  Reverse(n);
  22.  }
  23.  }

Program-To reverse a number using recursion 


  1. import java.util.*;
  2.  class ReverseNumber{
  3.  public static void Reverse(int n)
  4.  {
  5.  int l;
  6.  if(n<10)
  7.  {
  8. System.out.print(n);
  9.  }
  10.  else
  11.  {
  12.  l=n%10;
  13.  n=n/10;
  14.  System.out.print(l);
  15.  Reverse(n);
  16.  }
  17.  
  18.  }
  19.  public static void main(String args[])
  20.  {
  21.  int n;
  22.  Scanner ob=new Scanner(System.in);
  23.  System.out.println("Enter the number");
  24.   n=ob.nextInt();
  25.  System.out.println("Reverse of the number is");
  26.  Reverse(n);
  27.  
  28.  
  29.  }
  30.  }

Program -To reverse a number



  1.  import java.util.*;
  2. class ReverseNumber
  3. {
  4. public static void main(String args[])
  5. {
  6. int reverse=0,number,lastdigit;
  7. Scanner ob=new Scanner(System.in);
  8. System.out.println("Enter the number");
  9. number=ob.nextInt();
  10. while(number>0)
  11. {
  12. lastdigit=number%10;
  13. reverse=(reverse*10)+lastdigit;
  14. number=number/10;
  15. }
  16. System.out.println("Reverse of the number is :"+reverse);
  17. }
  18. }