Showing posts with label JAVA. Show all posts
Showing posts with label JAVA. Show all posts

October 19, 2013

What is Session

What is Session ?

Web is stateless, which means a new instance of a web page class is re-created each time the page is posted to the server. As we all know, HTTP is a stateless protocol, it can't hold client information on a page. If the user inserts some information and move to the next page, that data will be lost and the user would not be able to retrieve that information. What do we need here? We need to store information. Session provides a facility to store information on server memory. It can support any type of object to store along with our own custom objects. For every client, session data is stored separately, which means session data is stored on a per client basis. Have a look at the following diagram:



Fig: For every client, session data is stored separately
State management using session is one of the best ASP.NET features, because it is secure, transparent from users, and we can store any kind of object in it. Along with these advantages, some times session can cause performance issues in high traffic sites because it is stored in server memory and clients read data from the server

October 15, 2013

Differences Between Java and C++

All Differences Between Java and C++ 

Pointers
Java does not have an explicit pointer type. Instead of pointers, all references to objects—
including variable assignments, arguments passed into methods, and array elements—are
accomplished by using implicit references. References and pointers are essentially the same thing
except that you can’t do pointer arithmetic on references (nor do you need to).
Reference semantics also enable structures such as linked lists to be created easily in Java without
explicit pointers; merely create a linked list node with variables that point to the next and the
previous node. Then, to insert items in the list, assign those variables to other node objects.


Arrays
Arrays in Java are first class objects, and references to arrays and their contents are accomplished
through explicit references rather than via point arithmetic. Array boundaries are strictly
enforced; attempting to read past the ends of an array is a compile or run-time error. As with
other objects, passing an array to a method passes a reference to the original array, so changing
the contents of that array reference changes the original array object.
Arrays of objects are arrays of references that are not automatically initialized to contain actual
objects. Using the following Java code produces an array of type MyObject with ten elements, but
that array initially contains only nulls:
MyObject arrayofobjs[] = new MyObject[10];
You must now add actual MyObject objects to that array:
for (int i; i< arrayofobjs.length. i++) {
arrayofobjs[i] = new MyObject();
Java does not support multidimensional arrays as in C and C++. In Java, you must create arrays
that contain other arrays.
 

Strings
Strings in C and C++ are arrays of characters, terminated by a null character (\0). To operate
on and manage strings, you treat them as you would any other array, with all the inherent
difficulties of keeping track of pointer arithmetic and being careful not to stray off the end of
the array.

Strings in Java are objects, and all methods that operate on strings can treat the string as a
complete entity. Strings are not terminated by a null, nor can you accidentally overstep the end
of a string (like arrays, string boundaries are strictly enforced).


Memory Management
All memory management in Java is automatic; memory is allocated automatically when an
object is created, and a run-time garbage collector (the “GC”) frees that memory when the object
is no longer in use. C’s malloc and free functions do not exist in Java.
To “force” an object to be freed, remove all references to that object (assign variables holding
it to null, remove it from arrays, and so on). The next time the Java GC runs, that object is
reclaimed.


Data Types
As mentioned in the early part of this book, all Java primitive data types (char, int, long, and
so on) have consistent sizes and behavior across platforms and operating systems. There are no
unsigned data types as in C and C++ (except for char, which is a 16-bit unsigned integer).
The boolean primitive data type can have two values: true or false. Boolean is not an integer,
nor can it be treated as one, although you cannot cast 0 or 1 (integers) to boolean types in Java.
Composite data types are accomplished in Java exclusively through the use of class definitions.
The struct, union, and typedef keywords have all been removed in favor of classes.
Casting between data types is much more controlled in Java; automatic casting occurs only when
there will be no loss of information. All other casts must be explicit. The primitive data types
(int, float, long, char, boolean, and so on) cannot be cast to objects or vice versa; there are
methods and special “wrapper” classes to convert values between objects and primitive types.


Operators
Operator precedence and association behaves as it does in C. Note, however, that the new
keyword (for creating a new object) binds tighter than dot notation (.), which is different
behavior from C++. In particular, note the following expression:
new foo().bar;
This expression operates as if it were written like this:
(new foo()).bar;
Operator overloading, as in C++, cannot be accomplished in Java. The , operator of C has been
deleted.
The >>> operator produces an unsigned logical right shift (remember, there are no unsigned data
types).
The + operator can be used to concatenate strings.


Control Flow
Although the if, while, for, and do statements in Java are syntactically the same as they are in
C and C++, there is one significant difference. The test expression for each control flow construct
must return an actual boolean value (true or false). In C and C++, the expression can return
an integer.


Arguments
Java does not support mechanisms for optional arguments or for variable-length argument lists
to functions as in C and C++. All method definitions must have a specific number of arguments.
Command-line arguments in Java behave differently from those in C and C++. The first element
in the argument vector (argv[0]) in C and C++ is the name of the program itself; in Java, that
first argument is the first of the additional arguments. In other words, in Java, argv[0] is argv[1]
in C and C++; there is no way to get hold of the actual name of the Java program.


The following other minor differences from C and C++ exist in Java: 
  •  Java does not have a preprocessor, and as such, does not have #defines or macros. Constants can be created by using the final modifier when declaring class and instance variables.
  •  Java does not have template classes as in C++.
  •  Java does not include C’s const keyword or the ability to pass by const reference explicitly.
  •  Java classes are singly inherited, with some multiple-inheritance features provided through interfaces.
  •  All functions are implemented as methods. There are no functions that are not tied to classes.
  •  The goto keyword does not exist in Java (it’s a reserved word, but currently unimplemented). You can, however, use labeled breaks and continues to break out of and continue executing complex switch or loop constructs.

October 09, 2013

Java Important Topics



Question 01: Give a few reasons for using Java?
Answer 01: Java is a fun language. Let’s look at some of the reasons:
  •  Built-in support for multi-threading, socket communication, and memory management (automatic garbage collection).
  •  Object Oriented (OO).
  •  Better portability than other languages across operating systems.
  •  Supports Web based applications (Applet, Servlet, and JSP), distributed applications (sockets, RMI. EJB etc) and network protocols (HTTP, JRMP etc) with the help of extensive standardised APIs (Application Program Interfaces).

Question 02: What is the difference between C++ and Java? LF
Answer 02: Both C++ and Java use similar syntax and are Object Oriented, but:

  •  Java does not support pointers. Pointers are inherently tricky to use and troublesome.
  •  Java does not support multiple inheritances because it causes more problems than it solves. Instead Java supports multiple interface inheritance, which allows an object to inherit many method signatures from different interfaces with the condition that the inheriting object must implement those inherited methods. The multiple interface inheritance also allows an object to behave polymorphically on those methods.
  •  Java does not support destructors but rather adds a finalize() method. Finalize methods are invoked by the garbage collector prior to reclaiming the memory occupied by the object, which has the finalize() method. This means you do not know when the objects are going to be finalized. Avoid using finalize() method to release non-memory resources like file handles, sockets, database connections etc because Java has only a finite number of these resources and you do not know when the garbage collection is going to kick in to release these resources through the finalize() method.
  •  Java does not include structures or unions because the traditional data structures are implemented as an object oriented framework
  • All the code in Java program is encapsulated within classes therefore Java does not have global variables or functions.
  •  C++ requires explicit memory management, while Java includes automatic garbage collection.

Core Java Interview Questions And Answers



Question- Can there be an abstract class with no abstract methods
in it?
Answer- Yes


Question-
Can an Interface be final?
Answer- No

Question- Can an Interface have an inner class?
Answer- Yes.
public interface abc {
static int i=0;
void dd();
class a1 {
a1() {
int j;
System.out.println("in interfia");
};
public static void main(String a1[]) {
System.out.println("in interfia"); } } }


Question- Can we define private and protected modifiers for
variables in interfaces? (Core Java)
Answer- No

Question- What is Externalizable?
Answer- Externalizable is an Interface that extends Serializable Interface. And sends data into Streams in Compressed Format. It has two methods, writeExternal(ObjectOuput out) and readExternal(ObjectInput in)

Question- What modifiers are allowed for methods in an Interface?
Answer-
Only public and abstract modifiers are allowed for methods in interfaces.

April 30, 2013

Core Java Interview Questions And Answers

Question: Why do u use Session Tracking in HttpServlet?
Answer: In HttpServlet you can use Session Tracking to track the user state. Session is required if you are developing shopping cart application or in any e-commerce application.


Question: What are the advantage of Cookies over URL rewriting?
Answer: Sessions tracking using Cookies are more secure and fast. Session tracking
using Cookies can also be used with other mechanism of Session Tracking like url rewriting.
Cookies are stored at client side so some clients may disable cookies so we may not sure that the cookies may work or not.

In url  rewriting requites large data transfer from and to the server. So, it leads to network traffic and access may be become slow.


Question: What is session hijacking?
Answer: If you application is not very secure then it is possible to get the access of system after acquiring or generating the authentication information. Session hijacking refers to the act of taking control of a user session after successfully obtaining or generating an authentication session ID. It involves an attacker using captured, brute forced or reverse-engineered session IDs to get a control of a legitimate user's Web application session while that session is still in progress.


Question: What is Session Migration?
Answer: Session Migration is a mechanism of moving the session from one server to another in case of server failure. Session Migration can be implemented by:
a) Persisting the session into database
b) Storing the session in-memory on multiple servers.


Question: How to track a user session in Servlets?
Answer: The interface HttpSession can be used to track the session in the Servlet. Following code can be used to create session object in the Servlet: HttpSession session = req.getSession(true);


Question: How you can destroy the session in Servlet?
Answer: You can call invalidate () method on the session object to destroy the session. e.g. session.invalidate();

Core Java Interview Questions And Answers


Question: What is a Session?
Answer: A Session refers to all the request that a single client makes to a server. A session is specific to the user and for each user a new session is created to track all the request from that user. Every user has a separate session and separate session variable is associated with that session. In case of web applications the default time-out value for session variable is 20 minutes, which can be changed as per the requirement.


Question: What is Session ID?
Answer: A session ID is an unique identification string usually a long, random and alpha-numeric string, that is transmitted between the client and the server. Session IDs are usually stored in the cookies, URLs (in case url rewriting) and hidden fields of Web pages. 


Question: What is Session Tracking?
Answer: HTTP is stateless protocol and it does not maintain the client state. But there exist a mechanism called "Session Tracking" which helps the servers to maintain the state to track the series of requests from the same user across some period of time. 


 Question: What  are different types of Session Tracking? 
 Answer: Mechanism for Session Tracking are:
               a) Cookies
               b) URL rewriting
               c) Hidden form fields
               d) SSL Sessions


 Question: What is HTTPSession Class? 
 Answer: HTTPSession Class provides a way to identify a user across across multiple request. The servlet container uses HttpSession interface to create a session between an HTTP client and an HTTP server. The session lives only for a specified time period, across more than one connection or page request from the user.
  • Blogger news

    This Blog Contains All Topics Related To Internet, Website Help, Interview Questions, News, Results From Various Resources, Visit Daily For More Interesting And Famous Topics.
  • Random Post

  • About

    We Provide All Information Which you Needed. We Maintain This Blog Very Carefully, If You Find Any Mistake or Any Suggestions Then Please Let Us Know, You Can Contact Us By Comments, On FB Page Or On Google+ Page. ~ Thank You