Java Programmers

Java Programmers

This page is for the persons who have interest in java programming....Please like this page....
Here you will learn anything new everyday....

This page is all about java programming...Java is not an one time learn coding...if you want to be an long lasting programmer...you need to keep your knowledge upto date..Here we will help you to remind you the skills you studied in java..And we will support beginners to be an Professional..Thank You...

19/06/2014

How To Accept Input From KeyBoard ?
=> A stream represent flow of data from one
place to another place like a water pipe
carries water. A stream carries a data there
are 2 type of stream
1)Input Stream :- They read or accept a data.
2)Output Stream :- They send or write a data
to another place.
All Stream are represented as a classes in
"java.io" Packages
"KeyBoard" => "InputStreamReader" =>
"BufferedReader"
Accepting Input From KeyBoard :-
1)Connect InputStreamReader to the
KeyBoard
InputStreamReader obj = new
InputStreamReader(System.in);
2)connect InputStreamReader to
bufferedReader :-
BufferedReader br = new BufferedReader(
obj);
3)Read data at br using "read()" or
"readLine" methods.
Example:- Accept a single character from a
keyboard
*/
import java.io.*;
class AcceptSingleCharacter
{
public static void main(String args[])throws
Exception
{
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in));
System.out.println("\nEnter a Character : ");
//try{
char ch = (char) br.read();
System.out.println("You Entered "+ch+"\n
\n");
//}
//catch(Exception e){}
}//main method
}//class AcceptSingleCharacter

09/06/2014

Program to check whether the given
String is Palindrome Or not:

import java.util.Scanner;
class PalindromeString
{
public static void main(String args[])
{
String original, reverse = "";
Scanner input = new Scanner(System.in);
System.out.println("Enter a string to reverse:
");
original = input.nextLine();
int length = original.length();
for ( int i = length - 1 ; i >= 0 ; i-- )
reverse = reverse + original.charAt(i);System.out.println("Reverse of the string is:
" +reverse);
if (original.equals(reverse))
System.out.println("Entered string is a
palindrome.");
else
System.out.println("Entered string is not a
palindrome.");
}
}
Output:
Enter a string to reverse:
Iam an Java Programmer
Reverse of the string is: remmargorp avaj na mai

Entered string is not a palindrome.

25/05/2014

Needed two likes to 100 :-(

25/05/2014

What are the differences between HttpServlet and
Generic Servlets ?
A- GenericServlet defines a generic, protocol-independent servlet whereas HttpServlet Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site that uses the Http Protocol.

25/05/2014

What are the types of Servlet?

A-There are two types of servlets, GenericServlet and HttpServlet. GenericServlet defines the generic or protocol independent servlet. HttpServlet is subclass of GenericServlet and provides http protocl specific functionality.

25/05/2014

What is a Servlet?

A-Java Servlets are server side components that provides a powerful mechanism for developing server side of web application. Earlier CGI was used to provide server side capabilities for web applications. Although CGI played a major role in the explosion of the Internet, its performance, scalability and reusability issues made it less and less desirable among people who wanted enterprise class scalable applications. Java Servlets was the solution to all of CGIs problems. Built from ground up using Sun's java technology, servlets provide excellent framework for server side processing. They are an integral part of almost all J2EE applications.

25/05/2014

What is JSP?

A-JavaServer Pages (JSP) technology is the Java platform technology for delivering dynamic content to web applications in a portable, secure and well-defined way. The JSP Technology allows us to use HTML, Java, JavaScript and XML in a single file to create high quality and fully functionaly User Interface components for Web Applications.

Timeline photos 25/05/2014

Funny Thing...lol

Timeline photos 19/05/2014

Only Programmers can know it !!!!

Timeline photos 16/05/2014

Funnyyyy

12/05/2014

Top 10 Servlet Interview Question
Answers - J2EE
This time its servlet interview questions, I was thinking
what to pick for my interview series and than I thought
about J2EE and Servlet is my favorite on that space.
Servlet is an important part of any J2EE development
and serves as Controller on many web MVC frameworks
and that’s why it’s quite popular on J2EE interviews.
These Servlet questions are based on my experience as
well as collected by friends and colleague and they are
not only good for interview practice but also shows a
new direction of learning for any one who is not very
familiar with servlet technology.
As said earlier this interview question article
is part of my earlier series java interview questions ,
UNIX command interview questions and Java threading
interview questions.
You can find answers of all these questions on google
but I have also listed my answers fo r quick reference.
Question 1: In web.xml file 1 is defined between tag
what does it means.
Ans : whenever we request for any servlet the servlet
container will initialize the servlet and load it which is
defined in our config file called web.xml by default it
will not initialize when our context is loaded .defining
like this 1 is also
known as pre initialization of servlet means now the
servlet for which we have define this tag has been
initialized in starting when context is loaded before
getting any request.When this servlet question was
asked to me in an interview few years back , I was not
even aware of this element but this questions pointed
me to look DTD of web.xml and understand other
elements as well. .
Question 2: How can we create deadlock condition on
our servlet?
Ans: one simple way to call doPost() method inside
doGet() and doGet()method inside doPost() it will create
deadlock situation for a servlet. This is rather simple
servlet interview questions but yet tricky if you don’t
think of it J
Question 3: For initializing a servlet can we use
constructor in place of init ().
Ans: No, we can not use constructor for initializing a
servlet because for initialization we need an object of
servletConfig using this object we get all the parameter
which are defined in deployment descriptor for
initializing a servlet and in servlet class we have only
default constructor according to older version of java so
if we want to pass a
Config object we don’t have parametrized constructor
and apart from this servlet is loaded and initialized by
container so ots a job of container to call the method
according to servlet specification they have lifecycle
method so init() method is called firstly.
More important Java doesn't allow interfaces to declare
constructors. These kinds of servlet interview questions
are quite popular on service based companies who just
want to dig one level more.
Question 4: Why super.init (config) wiil be the first
statement inside init(config) method .
Ans: This will be the first statement if we are overriding
the init(config ) method by this way we will store the
config object for future reference and we can use by
getServletConfig () to get information about config
object if will not do this config object will be lost and
we have only one way to get config object because
servlet pass config object only in init method . Without
doing this if we call the servletConfig method will get
NullPointerException.
Question5: Can we call destroy() method inside the init
() method is yes what will happen?
Ans:Yes we can call like this but if we have not
override this method container will call the default
method and nothing will happen.after calling this if any
we have override the method then the code written
inside is executed.
Question 6: How can we refresh servlet on client and
server side automatically?
Ans: On client side we can use Meta http refresh and
server side we can use server push.
Question 7: How can you get the information about one
servlet context in another servlet ?
Ans: In context object we can set the attribute which we
want on another servlet and we can get that attribute
using their name on another servlet.
Context.setAttribute (“name”,” value”)
Context.getAttribute (“name”)
Question 8: Why we need to implement Single Thread
model in case of Servlet.
Ans: In J2EE we can implement our servlet on two
different ways either by using:
1. Single Thread Model
2. Multithread Model
Depending upon our scenario, if we have implemented
single thread means only one instance is going handle
one request at a time no two thread will concurrently
execute service method of servlet.
Example in banking account where sensitive data is
handle mostly this scenario was used this interface is
deprecated in Servlet API version 2.4.
As the name signifies multi thread means a servlet is
capable to handle multiple requests at same time. This
servlet interview question was quite popular few years
back on entry level but now its loosing its shine.
Question 9: what is servlet collaboration?
Ans communication between two servlet is called
servlet collaboration which is achieved by 3 ways.
1. RequestDispatchers include () and forward() method .
2. Using sendRedirect() method of Response object.
3. Using servlet Context methods
Question 10: What is the difference between
ServletConfig and ServletContext?
Ans: ServletConfig as the name implies provide the
information about configuration of a servlet which is
defined inside the web.xml file or we can say
deployment descriptor.its a specific object for each
servlet.
ServletContext is application specific object which is
shared by all the servlet belongs to one application in
one JVM .this is single object which represent our
application and all the servlet access application
specific data using this object.servlet also use their
method to communicate with container.
These Servlet interview questions are good for quick
recap of important concept before appearing on any
J2EE interview.

Please share if you have come across
any other interesting interview question on Servlets.

Timeline photos 09/05/2014

Collections interface.....

07/05/2014

java Language Interview Question and Answers

1. What is Java?

A high-level programming language developed by Sun
Microsystems. Java was originally called OAK, and was designed for handheld devices and set-top boxes. Oak was unsuccessful so in 1995 Sun changed the name to Java and modified the language to take advantage of the burgeoning World Wide Web.

2. what are the main features of java?
The main features of java are Compiled and Interpreted Object oriented
Robust and secure Type safe
High Performance.

3. What are pass by reference and passby value?

Pass By Reference means the passing the address itself rather than passing the value. Passby Value means passing a copy of the value to be passed.

4. What is the Java API?
The Java API is a large collection of ready-made
software components that provide many useful
capabilities, such as graphical user interface (GUI)widgets.

5. What is the Java Virtual Machine (JVM)?
The Java Virtual Machine is software that can be ported
onto various hardware-based platforms.

6. What is variables and then types?
Variables is an identifier that denotes a storage
location used to store a data values.unlike constants
that remain unchanged during the ex*****on of a
program, a variable may takes different values at
different times during the ex*****on of the program.
Instance variables
Class variables
Local variable
Parameters

7. what is dot operator?
The dot operator(.) is used to access the instance
variables and methods of class objects.It is also used
to access classes and sub-packages from a package.
Examples :
Person1.age ---------> Reference to the variable age
8. Define strings?
Strings represent a sequence of characters.The easiest
way to represent a sequence of characters in java is by
using a character array.
9. What is serialization?
Serialization is the process of converting a objects into
a stream of bytes.
10. What are different types of access modifiers?
Access specifiers are keywords that determine the type
of access to the member a class.
Public
Protected
Private
Default
11. What is an abstract class?
Abstract class is a class which contain one or more
abstract methods, which has to be implemented by sub
classes. An abstract class can contain no abstract
methods also i.e. abstract class may contain concrete
methods.
12. what are class variables
Class variables are global to a class and belong to the
entire set of objects that class creates. Only one
memory location is created for each variable.
13. What is the Collection interface?
The Collection interface provides support for the
implementation of a mathematical bag - an unordered
collection of objects that may contain duplicates.
14. What must a class do to implement an interface?
The class must provide all of the methods in the
interface and identify the interface in its implements
clause.
15. What is the Collections API?
The Collections API is a set of classes and interfaces
that support operations on collections of objects.
16. What is an array?
Array is a group of related data items that share a
common name.For instance, we can define an array
name salary to represent a set of salaries of a group of
employees.
Examples : salary[10]
17. What is a list iterator?
The List and Set collections provide iterators, which
are objects that allow going over all the elements of a
collection in sequence. The java.util.Iterator interface
provides for one-way traversal and java.util.ListIterator
is an iterator for lists that allows the programmer to
traverse the list in either direction (i.e. forward and or
backward) and modify the list during iteration.
18 What is the main difference between a String and a
StringBuffer class?
String is immutable : you can’t modify a string object
but can replace it by creating a new instance. Creating
a new instance is rather expensive.
StringBuffer is mutable : use StringBuffer or
StringBuilder when you want to modify the contents.
StringBuilder was added in Java 5 and it is identical in
all respects to StringBuffer except that it is not
synchronized,which makes it slightly faster at the cost
of not being thread-safe.
19. When to use serialization?
A common use of serialization is to use it to send an
object over the network or if the state of an object
needs to be persisted to a flat file or a database.
20. What is the main difference between shallow
cloning and deep cloning of objects?
Java supports shallow cloning of objects by default
when a class implements the java.lang.Cloneable
interface.
Deep cloning through serialization is faster to develop
and easier to maintain but carries a performance
overhead.
21. What are wrapper classes?
primitive data types may be converted into object types
by using the wrapper classes contained in the java.lang
package.
Exampes : int, float, long, char, double
22. What is the difference between an instance variable
and a static variable?
Class variables are called static variables. There is only
one occurrence of a class variable per JVM per class
loader.When a class is loaded the class variables are
initialized.
Instance variables are non-static and there is one
occurrence of an instance variable in each class
instance.Also known as a member variable or a field.
23 Where and how can you use a private constructor?
Private constructor is used if you do not want other
classes to instantiate the object and to prevent
subclassing.The instantiation is done by a public static
method (i.e. a static factory method) within the same
class.
24. What is type casting?
Type casting means treating a variable of one type as
though it is another type.
Examples :
int m = 5;
byte n =i;
25. What is a user defined exception?
User defined exceptions may be implemented by
defining a new exception class by extending the
Exception class.
26. What is an instanceof operator?
Instanceof is an object reference operator and returns
true if the object on the left-hand side is an instance of
the glass given to the right hand side.This operator
allows to determine whether the object belongs to a
particular class or not.
27. What are runtime exceptions?
Runtime exceptions are those exceptions that are
thrown at runtime because of either wrong input data
or because of wrong business logic etc. These are not
checked by the compiler at compile time.
28 What is the difference between an interface and an
abstract class?
An abstract class may contain code in method bodies,
which is not allowed in an interface. With abstract
classes, you have to inherit your class from it and Java
does not allow multiple inheritance. On the other hand,
you can implement multiple interfaces in your class.
29. what is a package?
A package is a namespace that organizes a set of
related classes and interfaces.The classes contained in
the packages of other programs can be easily
reused.Packages, classes can be unique compared with
classes in other packages.That is, two classes in two
different packages can have the same name.
30. Why do threads block on I/O?
Threads block on i/o (that is enters the waiting state)
so that other threads may execute while the i/o
Operation is performed.
26. What is an instanceof operator?
Instanceof is an object reference operator and returns
true if the object on the left-hand side is an instance of
the glass given to the right hand side.This operator
allows to determine whether the object belongs to a
particular class or not.
27. What are runtime exceptions?
Runtime exceptions are those exceptions that are
thrown at runtime because of either wrong input data
or because of wrong business logic etc. These are not
checked by the compiler at compile time.
28 What is the difference between an interface and an
abstract class?
An abstract class may contain code in method bodies,
which is not allowed in an interface. With abstract
classes, you have to inherit your class from it and Java
does not allow multiple inheritance. On the other hand,
you can implement multiple interfaces in your class.
29. what is a package?
A package is a namespace that organizes a set of
related classes and interfaces.The classes contained in
the packages of other programs can be easily
reused.Packages, classes can be unique compared with
classes in other packages.That is, two classes in two
different packages can have the same name.
30. Why do threads block on I/O?
Threads block on i/o (that is enters the waiting state)
so that other threads may execute while the i/o
Operation is performed.
31. What is the List interface?
The List interface provides support for ordered
collections of objects.
32. What is the Vector class?
The Vector class provides the capability to implement a
growable array of objects.
33 What is the base class of all classes?
java.lang.Object
34 What is the importance of static variable?
static variables are class level variables where all
objects of the class refer to the same variable. If one
object changes the value then the change gets
reflected in all the objects.
35. What is the difference between a while statement
and a do while statement?
A while statement checks at the beginning of a loop to
see whether the next loop iteration should occur. A do
while statement checks at the end of a loop to see
whether the next iteration of a loop should occur. The
do whilestatement will always execute the body of a
loop at least once.
36. Describe life cycle of thread?
A thread is similiar to a program that has a single flow
of control.A thread is a ex*****on in a program. The life
cycle of threads are
Newborn state
Runnable state
Running state
Blocked state
Dead state
37. What is an Applets?
Applets are small java programs that are primarily used
in Internet computing. They can be transported over the
internet from one computer to another and run using
the Applet Viewer or any web browser that supports
java.
38 What are wrapped classes?
Wrapped classes are classes that allow primitive types
to be accessed as objects.
39. What is the difference between an if statement and
a switch statement?
The if statement is used to select among two
alternatives. It uses a boolean expression to decide
which alternative should be executed. The switch
statement is used to select among multiple
alternatives. It uses an int expression to determine
which alternative should be executed.s
40. What modifiers are allowed for methods in an
Interface?
Only public and abstract modifiers are allowed for
methods in interfaces.
41. What is the difference between method overriding
and overloading?
Overriding is a method with the same name and
arguments as in a parent, whereas overloading is the
same method name but different arguments.
42. What do you mean by polymorphism?
Polymorphism means the ability to take more than one
form. fro example, an operation may exhibit behaviour
in different instances. The behaviour depends upon the
types of data used in the operatiom.
43 What is the difference between an abstract class and
an interface?
Abstract class Interface - Have executable methods and
abstract methods.Can only subclass one abstract class
Interface - Have no implementation code. All methods
are abstract.A class can implement any number of
interfaces.
44. What is the purpose of finalization?
The purpose of finalization is to give an unreachable
object the opportunity to perform any cleanup
processing before the object is garbage collected.
45. What is the difference between a break statement
and a continue statement?
Break statement results in the termination of the
statement to which it applies (switch, for, do, or while).
A Continue statement is used to end the current loop
iteration and return control to the loop statement.
46. When is a method said to be overloaded and when
is a method said to be overridden?
Overloading deals with multiple methods in the same
class with the same name but different method
signatures.
Overridingdeals with two methods, one in the parent
class and the other one in the child class and has the
same name and signatures.
47. How is final different from finally and finalize()?
Final - constant declaration.
The finally block always executes when the try block
exits, except System.exit(0) call.
finalize() is a method of Object class which will be
executed by the JVM just before garbage collecting
object to give a final chance for resource releasing
activity.
48. What is Byte Code?
All Java programs are compiled into class files that
contain bytecodes. These byte codes can be run in any
platform and hence java is said to be platform
independent.
49. What is the difference between error and an
exception?
Exception means When a method encounters an
abnormal condition (an exception condition) that it
can’t handle itself, it may throw an exception.
ssError mens system doesn’t handle.For
example:Overflow,Out of memory.
50. What if the main method is declared as private?
When a method is declared as private, the program
compiles properly but it will give runtime error Main
method not “public„.
51. What type of parameter passing does Java support?
In Java the arguments are always passed by value.
52. What is singleton?
It is one of the design pattern. This falls in the
creational pattern of the design pattern. There will be
only one instance for that entire JVM. You can achieve
this by having the private constructor in the class.
53. What is Locale?
A Locale object represents a specific geographical,
political, or cultural region.
54. What is the difference between constructors and
normal methods?
Constructors must have the same name as the class
and can not return a value. They are only called once
while regular methods could be called many times and
it can return a value or can be void.
55. What is the difference between static and non-
static variables?
A static variable is associated with the class as a
whole rather than with specific instances of a class.
Non-static variables take on unique values with each
object instance.
56. What is the difference between java and c++?
Java is a true object - oriented language while c++ is
basically c with object-oriented extension.
C++ supports multiple inheritence but Java provides
interfaces in case of multiple inheritence.
Java does not support operator overloading.
Java does not have template classes as in c++.
java does not use pointers.

07/05/2014

Cricket fever :-)

A Java programmer doing cricket commentary-

Four or six- OutOfBound Exception(out of boundary).

Somebody Missed a catch- Batsman have 'thrown' the ball but 'catch' block missed
catch.

Change in regular fielding setup- Dhoni expected, Kohli found.

Any dispute among the players- Players not compatible with each other.

06/05/2014

Life Cycle of an Applet:

Four methods in the Applet class give you the framework on which you build any serious applet:


init() :

This method is intended for whatever initialization is needed for your applet. It is called after the param tags inside the applet tag have been processed.


start() : This method is automatically called
after the browser calls the init method. It is also called whenever the user returns to the page containing the applet after having gone
off to other pages.


stop() : This method is automatically called when the user moves off the page on which the applet sits. It can, therefore, be called
repeatedly in the same applet.


destroy() : This method is only called when the
browser shuts down normally. Because
applets are meant to live on an HTML page,you should not normally leave resources
behind after a user leaves the page that contains the applet.


paint() : Invoked immediately after the start()
method, and also any time the applet needs to repaint itself in the browser. The paint() method is actually inherited from the
java.awt.


If you want to clear something like this,pls let me know...i will try to help you....if you think this page is useful,pls like,comment or share...Thank you...

http://java.awt/

06/05/2014

Features of Applet Class :

Every applet is an extension of the java.applet.Applet class.

The base Applet
class provides methods that a derived Applet class may call to obtain information and services from the browser context.

These include methods that do the following:

Get applet parameters

Get the network location of the HTML file
that contains the applet

Get the network location of the applet class
directory

Print a status message in the browser

Fetch an image

Fetch an audio clip

Play an audio clip

Resize the applet

if you want to clear about anything like this....pls let me know,i will try to help you....Thank you...

05/05/2014

Semi-colon plays an important part.

Can you tell which are correct-

a. if(i

02/05/2014

Good Morning Programmers !!!!!

Want your school to be the top-listed School/college?

Website