Monday, February 7, 2011

Some Switch loop concepts

Note 1 : In the Switch Expression only the variables it can be implicitly cast to 'Int'
can only be allowed. (or) the Java 5 feature  enum's are allowed.


Note 2 : Even it does not support the other numeric types like long,float,double.


Note 3: So, it supports only char, byte, int, short.

Tuesday, January 25, 2011

Java JDBC Questions

Question : What is JDBC ?
Ans : Java Database Connectivity , Provide a java interface to Relational database.

Flow Pattern : 
                         Application ----- > JDBC --------> Driver ------------>Database..


Question: How to get the Instance of Driver ?
Ans : Class Class.forName("name of the JDBC Driver");


Steps in Creating a Database Connection in JAva/
Step 1 : load the Driver.   
          --> through Class.forName("Name of the Driver");


This helps you to establish a connection between front end back-end of Application.
Step 2 : Creating a oracle JDBC Connection ?
   DriverManger.getConnection();
Helps you to get the Connection Object,helps you to build connection between
URL and Database.


Step3 : Create JDBC statement Object.


Step4 : Execute SQL statements?


Question : What is DriverManager Class?
Ans: Which creates objects which can connect Java applications to database.
  It manages the Drivers that are installed on the System.
getConnection() ,method uses to establish connection to the Database.


Syntax of getConnection(dbURL,userName,Password);
dbUrl  == java:subProtocol:subName.
Each Driver has it's own subProtocol Syntax : 
Example : for JDBC-ODBC Driver -> sun.jdbc.odbc.JdbcOdbcDriver
for MYSQL : mysql
Question : what is JDBC connection :
Ans: A jdbc connection is session/connection, within context of connection SQL statements
get Executed and results are returned.
A Connection Object provides MetaData, information about the database, fields,tables etc..
A Connection interface defines methods to interact with database.
Question : what is statement Object ?
Ans : A Statement Object is used to send and execute statements to Database.


Question : What are the different types of statements?
Ans :  Statement              : A simple Sql query Statement.
         Prepared Statement : Pre-Compiled Sql Queries 
         Callable Statement   : A call to Database Stored Procedure.


what is the Difference between DML , DDL , DCL commands /
Ans : DDL ---  use to define the Structure/scheme of a Database. 
Example : Alter, Create, Drop, truncate,Rename.
DML -- Use to manage the data within the scheme Objects
Example : UPDATE,SELECT , INSET, DELETE,MERGE, CALL
DCL :  GRANT, REVOKE.


TCL[ Transaction Control ] : used to manage the changes made by the DML commands
example : COMMIT, SAVEPOINT,ROllback.SetRollback.


Question : What is the Difference between EXECUTE(), ExecuteQuery(), ExecuteUpdate()?
Ans :
   boolean Execute() . == Will do both the Operations of ExecuteQuery and ExecuteUpdate.
  ResultSet ExecuteQuery();
 int ExecuteUpdate(); Insert,Update,Delete. or an SQL query which returns nothing.


What are the different Database Drivers available ?
Ans :
        1) JDBC-ODBC Drivers.
        2) Native - API partly Java Driver.
        3) Net Protocol Java Driver.
        4) Native Protocol Java Driver.
What are the Difference between these drivers?
Ans :  Type 1 : Converts all JDBC calls into ODBC calls.
         Type 4 : No Conversion requires purely java Driver.
         Type 1 : Need to install third Party[ ODBC Drivers ] Drivers.
         Type 4 : No Need.


Type 1 and 3 are Database independent .
Type 2 and 4 are database Dependent.


http://www.bestjavainterviewquestions.com/java-jdbc-questions/




Question : How to Debug problems related to JDBC ?
Ans : DriverManager.setLogWriter(PrintWriter out);
Question : What Causes the "no Suitable driver" error?
Ans : Specifying invalid URL in DriverManager.getConnection(); - Where the driver is 
unable to recognize that URL.


Question : How to get the Number of rows in a ResultSet ?
Ans : 
1. Invoke ResultSet.last() on the ResultSet.
2. Invoke ResultSet.getRow() to get the current row number (which is also the number of rows in the ResultSet)
3. Invoke ResultSet.beforeFirst() on the ResultSet.
4. Process as normal.
Question : 

Wednesday, December 29, 2010

Java Memory Management

Where local variables in Java Store?
Ans: Local variables store inside the Stack of JVM
All class instances and Arrays are allocates in Heap Memory.
Question : What is output of the below program?
Ans :

     String s1 = "MY Name is Chakra";
     String s2 = "MY Name is Chakra";
     if(s2  == "MY Name is Chakra"){
System.out.println(" s1 == s2 ");
     }else{
System.out.println(" s1 != s2 ");
     }
     if(s1.equals(s2)){
System.out.println(" s1 equals s2 ");
     }else{
System.out.println(" s1 not equals s2");
     }
o/p : s1 == s2 
      s1 equals s2 
Question 2 :

     String s1 = "MY Name";
     s1 = s1 + " is Chakra";
     String s2 = "MY Name is Chakra";
     if(s1  == "MY Name is Chakra"){
System.out.println(" s1 == s2 ");
     }else{
System.out.println(" s1 != s2 ");
     }
o/p : 
 s1 != s2 

       s1 equals s2 
Question 3 : 
     String s1 = new String("MY Name is Chakra"); 
     if(s1  == "MY Name is Chakra"){
System.out.println(" s1 == s2 ");
     }else{
System.out.println(" s1 != s2 ");
     }

o/p: s1 != s2 
     s1 equals s2 
Question : What are the interfaces a string class implements?
Ans: Serializable , Comparable, charSequence.


Question : If your class overrides the hashCode method , how will you get the 
int value of default hashCode() .
Ans : Use System.identityHashCode(obj1);


Question: how can you make your class immutable ?
Ans: Declare all variables as private, and  do not provide setters and getters.

Thursday, December 16, 2010

MYSQL Interview Questions

What is the difference between RDBMS and DBMS?
Ans : 1)DBMS does not support a tabular structure and does not enforce relationship
betweeb tables.
         2) DBMS does not enforce security on data manipulation Operations.
             it does not ensure the ACID property.
Where as RDMS ensures all the above property.


Question : What is ACID Property in RDBMS?
Answer : from wikipedia :
Atomicity requires that database modifications must follow an "all or nothing" rule. 


consistency property ensures that any transaction the database performs will
take it from one consistent state to another.


Isolation refers to the requirement that other operations cannot access data that 
has been modified during a transaction that has not yet completed.


Durability is the ability of the DBMS to recover the committed transaction updates 
against any kind of system failure (hardware or software). 


This is Very Good Website for MYSQL Interview Questions :
http://dba.fyicenter.com/Interview-Questions/MySQL/


What is TableSpace ?
Ans :  1) It is a logical unit storage in Oracle Database.
           2) consists of one or more data files.
           3) can be taken into offline or online.
           4) can make read Only.
           

Tuesday, November 30, 2010

DownCasting vs UpCasting

Take one Super class and one sub Class.

public class ClassA {

public void callMe(){
System.out.println(" I am in Class A");
}
}


Sub Class : 
public class ClassB extends ClassA {

public void callMe(){
System.out.println(" I am in Class B");
}
}




What is Upcasting in Java?

System.out.println(" -------------------UpCasting Example --------------------- ");
ClassB childClassObject  = new ClassB();
ClassA parentClassObject = new ClassA();

ClassA classAObject = childClassObject;
classAObject.callMe();

System.out.println("--------------------------------------------------------------");



What is DownCasting in Java?

System.out.println("-----------Down Casting Example-------------------------------");
ClassB classBObject = (ClassB) parentClassObject;
classBObject.callMe();
System.out.println("---------------------------------------------------------------");


Does Java Supports the DownCasting ?
Strictly Speaking No.

This is the Wonderful Link:

NOTES:
If an Class Object is upcasted to It's super class, then we cant allow you to use the properties
in that Class. It allows use only the Properties in the super class.
Example : Once an Object of Class Cat is upcasted to Animal Class. So Now onwards the object
of Cat behaves like an Object of Animal Class. So it is not allowed to use the Properties of
Cat Class.
Example :



http://javaforyou.wordpress.com/2008/06/22/casting-reference-variables-downcasting-upcasting/

Sunday, November 28, 2010

Servlets

Question : What is Servlet?
Definition 1: A small Java program that runs within a web server.servlets
 receive and response to the request from the Web Clients usually across HTTP.
              2) It runs completely inside the JVM.
Definition 2: A servlet is a java class therefore needs to be executed inside
 the JVM, by a service we called Servlet engine.


Question: What is JSDK?
Answer: All servlets API classes and Simple servlet enables web server are 
combined into Java Servlet Development Kit(JSDK).

Question :What are life cycle methods of the servlet interface?
Ans: The interface servlet defines the methods for the servlet life cycle. those are
         1) init Method() :  servlet constructed and initialized
         2) service method() : calls from clients are handled here.
         3) destroy method() :  servlet is taken out of service and destroyed.

Question : Who calls the service() method ?
Ans: called by the servlet container to allow the servlet to handle the request.

Explain the Hierarchal of the servlets ?
Answer :   Servlet [ interface
            |   implements
GenericServlet [ abstract Class ]
           | extends
 HttpServlet   [ Abstract Class ]
          |
          ---------> implements [ serializable ]
          ---------> implements [ servlet ]
         ----------> implements [ ServletConfig ]
Question : What is servlet Config?
Ans : It is an interface, used by the servlet container used to pass information to 
servlet during initialization.

Question : What is servletContext ?
Ans : It is an Interface, used by the servlet to communicate with the servlet container
to get the information such as MIME type of a file , write to a log file.

Note: ServletContext is the object contained within the servletConfig object, where this
 object is passed to the servlet by the servlet container during servlet initialization.


Note: There is only one context with the one web application or with one JVM.


Question : advantages of servlets over the CGI?
Answer : Platform Independent : because servlets written in java language.
              Performance: CGI creates a new process to handle a new request,Servlet creates a new thread.

AWS certification question

AWS AWS Hi! this is for questions related to AWS questions. EC2 instances EC2 storage types cold HDD : 1. Defines performance in terms...