Tag Archives: fresher interview

Can some one give real life example to understand access specifiers in JAVA?

Hello Guys,

Today morning I came across very good information about Object Oriented Programming (OOP) on Quora. I am very excited to share this with you all. As this is not my article, I would like to many thanks to author Pritam Kumar. To read the original post, Can someone give real life example to understand access specifiers in JAVA?

When you update your Facebook Status, it gives you 4 options

1. If you make this status visible for Public, anyone can see this status on Internet (Anyone On or Off Facebook). [Public Access Specifiers]

2. If you make this status visible “only for me”. No one can see this status except you. [Private Access Specifiers]

3. If you make this status visible for Friends or Friends of friends, then your status will be only visible for your friends and your friends friends. Not everyone presents on Facebook or Internet. [Protected Access Specifiers]

4. If you make this status visible for “Friends”, then your status will be only visible for your Friends. Not your friends of friends or everyone presents on Facebook. [Default  Access Specifiers]

In Programming Terms:

There are four Access Specifiers in Java.

1. Public
2. Private
3. Default.
4. Protected

Hope this little information will help you. Feel free to add your valuable comments.
Happy Coding! Stay tuned…

Swapnil Sonar

Interview Questions for IT Fresher| Tech Code Geek

Hello Guys,

Most of the times freshers are confusing while interview, they actually not aware of what type of questions will asked in interview.
I like to share some of Interview Questions which were asked to me during my interview.
Hope it will helpful to you…

What is a CAPTCHA and when do you use it?
CAPTCHA is the short form of Completely Automated Public Turing Test. It’s a step taken to ensure that a feature is not abused in a way it’s not meant to be used. We use CAPTCHAS for general form submissions, registrations, user generated content and so on to prevent spam bots from clogging up the system or spamming.

What is the current version of PHP and MYSQL?
Their current versions are
PHP is 5.4.1 (As of this writing. Make sure you know the current version when you go in for your interview)
MySQL- 5.5.23

Can you tell me the difference between include and require functions?
Both these functions differ in how they handle failures that occur.
Suppose a file is not found by the include() function, then it will simply give a warning and script execution will not be interrupted.
However, if a file is not found using a require() function, it will throw up a fatal warning and stop the script execution.

What the difference is between get and post method in HTTP?
GET Method:
•    All the name value pairs are submitted as a query string in URL. It’s not secured as it is visible in plain text format in the Location bar of the web browser.
•    As the data transfers through address bar (URL) there are some restrictions in using space, some characters like ampersand (&) etc. in the GET method of posting data. We have to take special care for encoding data if such special characters are present.
•    Length of the string is restricted.
•    If method is not mentioned in the Form tag, this is the default method used.
•    If get method is used and if the page is refreshed it would not prompt before the request is submitted again.
•    One can store the name value pairs as bookmark and directly be used while sharing with others – example search results.
•    Data is always submitted in the form of text
•    If the response of the page is always same for the posted query then use GET example database searches

POST Method:
•    All the name value pairs are submitted in the Message Body of the request.
•    Length of the string (amount of data submitted) is not restricted.
•    Post Method is secured because Name-Value pairs cannot be seen in location bar of the web browser.
•    If post method is used and if the page is refreshed it would prompt before the request is resubmitted.
•    If the service associated with the processing of a form has side effects (for example, modification of a database or subscription to a service), the method should be POST.
•    Data is submitted in the form as specified in enctype attribute of form tag and thus files can be used in FileUpload input box.

Is it possible to create a database using PHP and MySQL?
Yes. We can create a database using the function mysql_create_db(??).

Is it possible to know details about the browser being used to view a PHP website?
Yes. We can use the get_browser() function to get the details of the browser a user is using. This information is usually found inside the browscap.ini file.

String Concatenation –
There are two different ways to combine variables in PHP. Let’s take an example.
$var1 = “Hello”;
$var2 = “World”;
We can combine it using the two codes below
$var3 = $var1.$var2; and
$var3 = “$var1$var2″;

Method Definitions:-
The set of common methods for HTTP/1.1 is defined below. Although this set can be expanded, additional methods cannot be assumed to share the same semantics for separately extended clients and servers.
Safe and Idempotent Methods
•        OPTIONS
•        GET
•        HEAD
•        POST
•        PUT
•        DELETE
•        TRACE
•        CONNECT

What does setAutoCommit(false) do?
A JDBC connection is created in auto-commit mode by default. This means that each individual SQL statement is treated as a transaction and will be automatically committed as soon as it is executed. If you require two or more statements to be grouped into a transaction then you need to disable auto-commit mode using below command
con.setAutoCommit(false);

Once auto-commit mode is disabled, no SQL statements will be committed until you explicitly call the commit method. A Simple transaction with use of autocommit flag is demonstrated below.

con.setAutoCommit(false);
PreparedStatement updateStmt =
con.prepareStatement( "UPDATE EMPLOYEE SET SALARY = ? WHERE EMP_NAME LIKE?");

updateStmt.setInt(1, 5000); updateSales.setString(2, "Jack");
updateStmt.executeUpdate();

updateStmt.setInt(1, 6000); updateSales.setString(2, "Tom");
updateStmt.executeUpdate();
con.commit();
con.setAutoCommit(true);

What is Connection pooling? What are the advantages of using a connection pool?
Connection Pooling is a technique used for sharing the server resources among requested clients. It was pioneered by database vendors to allow multiple clients to share a cached set of connection objects that provides access to a database.
Getting connection and disconnecting are costly operation, which affects the application performance, so we should avoid creating multiple connections during multiple database interactions.
A pool contains set of Database connections which are already connected, and any client who wants to use it can take it from pool and when done with using it can be returned back to the pool.
Apart from performance this also saves you resources as there may be limited database connections available for your application.

What is a stored procedure? How to call stored procedure using JDBC API?
Stored procedure is a group of SQL statements that forms a logical unit and performs a particular task.
Stored Procedures are used to encapsulate a set of operations or queries to execute on database. Stored procedures can be compiled and executed with different parameters and results and may have any combination of input/output parameters. Stored procedures can be called using CallableStatement class in JDBC API.
Below code snippet shows how this can be achieved.

CallableStatement cs = con.prepareCall("{call MY_STORED_PROC_NAME}");
ResultSet rs = cs.executeQuery();

What are the types of statements in JDBC?
The JDBC API has 3 Interfaces,
1.    Statement
2.    PreparedStatement,
3.    CallableStatement

The key features of these are as follows:

Statement
This interface is used for executing a static SQL statement and returning the results it produces.
The object of Statement class can be created using Connection.createStatement() method.

PreparedStatement
A SQL statement is pre-compiled and stored in a PreparedStatement object.
This object can then be used to efficiently execute this statement multiple times.
The object of PreparedStatement class can be created using Connection.prepareStatement() method. This extends Statement interface.

CallableStatement
This interface is used to execute SQL stored procedures.
This extends PreparedStatement interface.
The object of CallableStatement class can be created using Connection.prepareCall() method.

What does Class.forName() method do?
Method forName() is a static method of java.lang.Class. This can be used to dynamically load a class at run-time. Class.forName() loads the class if it’s not already loaded. It also executes the static block of loaded class. Then this method returns an instance of the loaded class. So a call to Class.forName(‘MyClass’) is going to do following

– Load the class MyClass.
– Execute any static block code of MyClass.
– Return an instance of MyClass.

JDBC Driver loading using Class.forName is a good example of best use of this method. The driver loading is done like this

Class.forName("org.mysql.Driver");

All JDBC Drivers have a static block that registers itself with DriverManager and DriverManager has static initializer method registerDriver() which can be called in a static blocks of Driver class. A MySQL JDBC Driver has a static initializer which looks like this:

static {
try {
java.sql.DriverManager.registerDriver(new Driver());
} catch (SQLException E) {
throw new RuntimeException("Can't register driver!");
}
}

Class.forName() loads driver class and executes the static block and the Driver registers itself with the DriverManager.

Good Luck.. 🙂
Swapnil Sonar