Tuesday, 28 January 2014

String Reverse Program

 public class ReverseProgram{
    public static void main(String[] args) {
        String a="Siva";
        for(int i = a.length() - 1; i >= 0; --i)
    {
        System.out.print(a.charAt(i));
    }

}
}
                                  (or)

public class String_reverse
{
public static void main(String[] args)
{
Scanner sc=new Scanner(System.in);
System.out.println("Enter String :");
String n=sc.nextLine();
String rev="";
int len=n.length();
for(int i=len-1;i>=0;i--)
{
rev=rev+n.charAt(i);
}
System.out.println("Reverse of Given String is :");
System.out.println(""+rev);
}
}

Monday, 27 January 2014

Factorial Program

public class Factorial {
   
    int fact(int number)
    {
        int f=1;
        for(int i=1;i<=number;i++)
        {
            f = f*i;
        }
        return f;
    }
    public static void main(String[] args) {
        Factorial fa = new Factorial();
        int ab=fa.fact(4);
        System.out.println(ab);
       
    }
}

Fibonacci Series

public class Fibonacci
{
    public static void main(String[] args)
    {
        int f = 0;
        int g = 1;

        for(int i = 1; i <= 10; i++)
        {
            f = f + g;
            g = f - g;
            System.out.print(f + " ");
        }

        System.out.println();
    }
}

Saturday, 25 January 2014

Tavant interview questions

1. Sort integer array ?
  
               public class SortedArray
{
    public static void main(String[] args) {

        int a[]={30,7,9,20};
        Arrays.sort(a);
        System.out.println(Arrays.toString(a));
}
}

2. Sort integer array without using Array.sort by ascending

  public class ArraySort {
public static void main(String[] args) {
int a[] = {6,500,700,200,1000,1};   
int temp=0;
/*** Ascending Order ***/
for(int i=0;i<a.length;i++)
{   
for(int j=a.length-1;j>i;j--)
{   
if(a[i]>a[j]){
temp = a[i];
a[i] = a[j];
a[j] = temp;   
}
}
}
for(int i=0;i<a.length;i++)
System.out.println("a["+i+"] = "+a[i]);
}
}

                  
3. Sort integer array without using Array.sort by decending

            public class Test {
    public static void main(String[] args)
    {
        int a[] = {6,500,700,200,1000,1};   
        int temp=0;
        /*** Descending Order***/
        for(int i=0;i<a.length;i++)
        {   
        for(int j=0;j<a.length;j++)
        {   
        if(a[i]>a[j]){
        temp = a[i];
        a[i] = a[j];
        a[j] = temp;   
        }
        }
        }
        for(int i=0;i<a.length;i++)
            System.out.println("a["+i+"] = "+a[i]);
    }
    }

4. why need to use overriding ?

             Consider Manager is a super class and Employee is a child class.
             Both class has work() .
             But in Manager,he only manage and in Employee, he will do coding. But basically Manager and Employee are worker.
            Their work is different based on class.

5. What is Generic ?
             A class or interface that operates on parameterized type is called Generic.
             Generic also provide type safety.
             we cannot use other class object .

6.How to sort employee details using comparable ?

                 class Student implements Comparable<Student> {
    int rollno;
    String name;
    int age;
    public int getRollno() {
        return rollno;
    }
    public void setRollno(int rollno) {
        this.rollno = rollno;
    }
    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public int getAge() {
        return age;
    }
    public void setAge(int age) {
        this.age = age;
    }
        public int compareTo(Student obj)
    {
        return this.rollno - obj.rollno;
    }
}

public class Simple {
   
    public static void main(String[] args) {
        ArrayList al = new ArrayList();
        Student a = new Student();
        a.setAge(2);
        a.setName("bala");
        a.setRollno(5);
        Student b = new Student();
        b.setAge(1);
        b.setName("sures");
        b.setRollno(67);
        Student c = new Student();
        c.setAge(8);
        c.setName("ramesh");
        c.setRollno(43);
        al.add(a);
        al.add(b);
        al.add(c);
        Collections.sort(al);
        Iterator itr = al.iterator();
        while(itr.hasNext())
        {
            Student st=(Student)itr.next();
            System.out.println(st.age+" "+st.name+" "+st.rollno);
        }
       
    }

}

7. Reverse the string ?

            public class StringReverseExample{
       public static void main(String[] args){
          String string="How to name it";
          String reverse = new StringBuffer(string).
          reverse().toString();
          System.out.println("\nString before reverse:" +string);
          System.out.println("String after reverse:"+reverse);
       }
    }
                     

8.Difference between executeUpdate and executeQuery ?

  1. int executeUpdate(String SQL) : Returns the numbers of rows affected by the execution of the SQL statement. Use this method to execute SQL statements for which you expect to get a number of rows affected - for example, an INSERT, UPDATE, or DELETE statement.
  2. ResultSet executeQuery(String SQL) : Returns a ResultSet object. Use this method when you expect to get a result set, as you would with a SELECT statement.

Saturday, 4 January 2014

1. What is log4j
    This is a Open Source tool given by Apache, for only java projects, to record or write the status of an application at various places
  • Working with log4j is nothing but working with classes & interfaces given in org.apache.log4j.*
  • Log4j is a common tool, used for small to large scale Java/J2EE projects
  • In Log4j we use log statements rather SOPL statements in the code to know the status of a project while it is executing
  • In real time, after a project is released and it is installed in a client location then we call the location as on-site right, when executing the program at on-site location, if we got any problems occurred then these problems must report to the off showered engineers,  in this time we used to mail these Log files only so that they can check the problems easily

2. What is web application
       A Web application (Web app) is an application program that is stored on a remote server and delivered over the Internet through a browser interface.

3.postgresql vs MySQL
          --  PostgreSQL is more reliable because it is ACID (Atomicity, Consistency, Isolation, and Durability) compliant which means queries will maintain data integrity, and return the same output without error.
         -- MySQL is less reliable and not ACID compliant: The way it handles foreign key references, auditing and transactions make it less reliable. MySQL is good if you are thinking you may use code from other open source projects. Since it is widely used in smaller websites,

       

4. what is SNMP

5.what is SNMP Manager

6.what is snmp agent

7.explain SNMP simulator

8.SNMP Ports are

9. IP in which OSI layer

10.What is Managed Device

11.what is network manager

12.what is MIB

13.what is OID

14.MIB order names



15.What is Socket
                    

Definition: A socket is one end-point of a two-way communication link between two programs running on the network.                - -  When a computer program needs to connect to a local or wide area network such as the Internet, it uses a software component called a socket. The socket opens the network connection for the program, allowing data to be read and written over the network. It is important to note that these sockets are software, not hardware, like a wall socket. So, yes, you have a much greater chance of being shocked by a wall socket than by a networking socket.

16.What is SSL
                 
              - -SSL (Secure Sockets Layer) is a standard security technology for establishing an encrypted link between a server and a client—typically a web server (website) and a browser; or a mail server and a mail client (e.g., Outlook).

SSL allows sensitive information such as credit card numbers, social security numbers, and login credentials to be transmitted securely. Normally, data sent between browsers and web servers is sent in plain text—leaving you vulnerable to eavesdropping. If an attacker is able to intercept all data being sent between a browser and a web server they can see and use that information.
More specifically, SSL is a security protocol. Protocols describe how algorithms should be used; in this case, the SSL protocol determines variables of the encryption for both the link and the data being transmitted.

Short for Secure Sockets Layer, a protocol developed by Netscape for transmitting private documents via the Internet. SSL uses a cryptographic system that uses two keys to encrypt data − a public key known to everyone and a private or secret key known only to the recipient of the message.

https://www.globalsign.eu/ssl-information-center/what-is-ssl.html


17. Object-relational mapping (ORM, O/RM, and O/R mapping)
                              In computer software is a programming technique for converting data between incompatible type systems in object-oriented programming languages.

18.What is hashcode in java?
                             1) when an object is created by JVM, it returns the memory address of the object as a hexadecimal number, which is called object reference or hashcode. When a new object is created, a new reference number is allocated to it.It means every object will have a unique reference.

  --If we want to see the object's hashcode, by using hashCode() method we can see hashcode of object. hashCode() method presents in Object class which is super class for every predefined class and user defined class.

  --For every object JVM will assign a unique value which is nothing but hash code



EX:

class One
{
public static void main(String args[])
{
One o=new One();
System.out.println(o.hashCode());
}
}

Output: 4072869

19. What is Hashing?
            -- Hashing is the transformation of a string of characters into a usually shorter fixed-length value or key that represents the original string.