Tuesday, 16 December 2014

Class Key Words And Identifiers In Java


public class Display{

public is a keyword which means means what we are named can use by other classes
class is a keyword which indicates a class is being named
Display is an identifier gives the name of the class

{   Opening braces delimiter  indicates description of class members 

Wednesday, 8 October 2014

Write a program to reverse a string

import java.util.*;
 class ReverseAString           //class name
{
   public static void main(String args[])  //main function
   {
      String original, reverse = "";    //string declaration
      Scanner in = new Scanner(System.in);                //to get input from- //-user

      System.out.println("Enter a string to reverse"); //Ask //string to reverse from user
original = in.nextLine();                            //getting input from user //using ‘in’ object

      int length = original.length();            //finding length of the //inputted string

      for ( int i = length - 1 ; i >= 0 ; i-- )  //using for loop //getting each character by using charAt(i) method
         reverse = reverse + original.charAt(i);  //reversed string is //stored in reverse string

      System.out.println("Reverse of entered string is: "+reverse);
//reversed sting is outputted to user
   }
}

Java Interview questions

·        Collections in java
·        Interfaces in java
·        Why static is used in public static void main()
Question
·        Difference between jre and jdk
Answer
·        JRE: Java Runtime Environment.
JRE basically the Java Virtual Machine where Java programs run on and  also includes browser plugins for Applet execution.
·        JDK: Java Development Kit

It is a Software Development Kit for Java, including JRE, and compilers and tools (eg. JavaDoc,, Java Debugger) to create and compile programs.

Sunday, 28 September 2014

Final Variable With Example


There is a final variable a, we are going to change the value of this variable, but It can't be changed because final variable once assigned a value can never be changed.

Example Program

class Super
{
                       final int a=100;
                       void show()
                       {
                        //a=200;error , can't be changed because final variable once assigned a value can never be changed.

                        System.out.println("Welcome to the final Keyword                       "+a);
                       }
}

class Demofinal
{
                       public static void main(String args[])
                       {
                        Super obj=new Super();
                        obj.show();
                       }
}


Output

D:\>javac Demofinal

D:\>java Demofinal

Welcome to the final Keyword    100

Wednesday, 24 September 2014

Constructor Overloading with Example

Constructor Overloading

Constructor overloading in java allows to have more than one constructor inside one Class. 

Example Program

class Demo
{
                       Demo()
                       {
                        System.out.println("Constructor without parameter");
                       }
                       Demo(int a)
                       {
                        System.out.println("Constructor with integer parameter "+a);
                       }
                       Demo(float b)
                       {
                        System.out.println("Constructor with float parameter "+b);
                       }
}
public class Democonover {
                       public static void main(String args[])
                       {
                        Demo obj1=new Demo();
                        Demo obj2=new Demo(4);
                        Demo obj3=new Demo(5.9f);
                       }
}


Output

D:\> javac Democonover.java
D:\>java Democonover
Constructor without parameter
Constructor with integer parameter 4
Constructor with float parameter 5.9


Explanation



Tuesday, 23 September 2014

Constructor program with parameter passing

 Constructor program with parameter passing

 Program

class Parmpass
{
          int i;
          Parmpass(int a)
          {
                   i=a;
                   System.out.println("Constructor with parameter "+i);
          }
}
class ParmpassMain
{
          public static void main(String args[])
          {
                   int b=10;
                   Parmpass obj= new Parmpass(b);
          }
}

Output   

D:\>java ParmpassMain
Constructor with parameter 10


Explanation