All java c# asp.net .net servlet jdbc c sqlserver android ado.net javascript php wcf clearcase angularjs 2

What is Java Virtual Machine and how it is considered in context of Java’s platform independent feature?

When Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by Java Virtual Machine (JVM) on whichever platform it is being run.

Platform independency is one of the key aspect that Java provides and the question you have asked is a very common and basic one. I'm trying to explain it below. Hope it will help.

Explanation :

The java compiler compiles a java program and converts it into bytecode because of which a java program can run on wide variety of platforms.

Java Virtual Machine(JVM) is a Java run time system. It is platform dependent i.e its implementation differs from platform to platform. It provides the runtime environment in which java bytecode can be executed.

In order to run a java program on different platforms, only we need to implement platform specific JVMs and these all will execute the same byte code.This is the feature due to which java is considered as platform independent.

Explanation :

The java compiler compiles a java program and converts it into bytecode because of which a java program can run on wide variety of platforms. 

Java Virtual Machine(JVM) is a Java run time systemIt is platform dependent i.e its implementation differs from platform to platform. It provides the runtime environment in which java bytecode can be executed.

In order to run a java program on different platforms, only we need to implement platform specific JVMs and these all will execute the same byte code.This is the feature due to which java is considered as platform independent.

Multithreading in java

Java is a multi-threaded programming language which means we can develop multi-threaded program using Java. A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.

https://www.tutorialspoint.com/java/java_multithreading.htm

Multithreading in java is a process of executing multiple threads simultaneously.

Thread is basically a lightweight sub-process, a smallest unit of processing. Multiprocessing and multithreading, both are used to achieve multitasking.

But we use multithreading than multiprocessing because threads share a common memory area. They don't allocate separate memory area so saves memory, and context-switching between the threads takes less time than process.

Java Multithreading is mostly used in games, animation etc.

ADVANTAGES OF MULTI THREADING:

1) It doesn't block the user because threads are independent and you can perform multiple operations at same time.

2) You can perform many operations together so it saves time.

3) Threads are independent so it doesn't affect other threads if exception occur in a single thread.

In this process we execute multiple threads simultaneously.Because thread is basically a lightweight sub-process, a smallest unit of processing.As we know Multiprocessing and multithreading, both are used to achieve multitasking purposes only.But we use multithreading than multiprocessing because threads share a common memory area. They don't allocate separate memory area so saves memory, and context-switching between the threads takes less time than process.And we use multithreading for animation,gaming etc.its major advantage is Threads are independent so it doesn't affect other threads if exception occur in a single thread and it can perform multiple operations at a time and saves our time to.

Explain servlet life cycle.

A servlet life cycle can be defined as the entire process from its creation till the destruction. The following are the paths followed by a servlet.

  • The servlet is initialized by calling the init () method.
  • The servlet calls service() method to process a client's request.
  • The servlet is terminated by calling the destroy() method.
  • Finally, servlet is garbage collected by the garbage collector of the JVM.
The web container maintains the life cycle of a servlet instance. Let's see the life cycle of the servlet:
  1. Servlet class is loaded.
  2. Servlet instance is created.
  3. init method is invoked.
  4. service method is invoked.
  5. destroy method is invoked
there are three states of a servlet: new, ready and end. The servlet is in new state if servlet instance is created. After invoking the init() method, Servlet comes in the ready state. In the ready state, servlet performs all the tasks. When the web container invokes the destroy() method, it shifts to the end state.

1) Servlet class is loaded

The classloader is responsible to load the servlet class. The servlet class is loaded when the first request for the servlet is received by the web container.

2) Servlet instance is created

The web container creates the instance of a servlet after loading the servlet class. The servlet instance is created only once in the servlet life cycle.

3) init method is invoked
The web container calls the init method only once after creating the servlet instance. The init method is used to initialize the servlet. It is the life cycle method of the javax.servlet.Servlet interface. Syntax of the init method is given below:
  1. public void init(ServletConfig config) throws ServletException  
 

4) service method is invoked

The web container calls the service method each time when request for the servlet is received. If servlet is not initialized, it follows the first three steps as described above then calls the service method. If servlet is initialized, it calls the service method. Notice that servlet is initialized only once. The syntax of the service method of the Servlet interface is given below:
  1. public void service(ServletRequest request, ServletResponse response)   
  2.   throws ServletException, IOException  
 

5) destroy method is invoked

The web container calls the destroy method before removing the servlet instance from the service. It gives the servlet an opportunity to clean up any resource for example memory, thread etc. The syntax of the destroy method of the Servlet interface is given below:
  1. public void destroy()  
 
  1. Loading Servlet Class : A Servlet class is loaded when first request for the servlet is received by the Web Container.
  2. Servlet instance creation :After the Servlet class is loaded, Web Container creates the instance of it. Servlet instance is created only once in the life cycle.
  3. Call to the init() method : init() method is called by the Web Container on servlet instance to initialize the servlet.

    Signature of init() method :

    public void init(ServletConfig config) throws ServletException
    
  4. Call to the service() method : The containers call the service() method each time the request for servlet is received. The service() method will then call the doGet() or doPost() methos based ont eh type of the HTTP request, as explained in previous lessons.

    Signature of service() method :

    public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException
    
  5. Call to destroy() method: The Web Container call the destroy() method before removing servlet instance, giving it a chance for cleanup activity.

What is the difference between the Reader/Writer class hierarchy and the InputStream/OutputStream class hierarchy?

The Reader/Writer class hierarchy is character-oriented, and the InputStream/OutputStream class hierarchy is byte-oriented.

reader/writer support only cahracter and input/output 
stream support only bytes input stram and the java reader 
class has only one differnce and that is input stream only 
support bytes and the reader class only supports the 
character.

What is URL rewriting?

You can append some extra data on the end of each URL that identifies the session, and the server can associate that session identifier with data it has stored about that session. For example, with http://tutorialspoint.com/file.htm;sessionid=12345, the session identifier is attached as sessionid=12345 which can be accessed at the web server to identify the client.

URL manipulation, also called URL rewriting, is the process of altering (often automatically by means of a program written for that purpose) the parameters in aURL (Uniform Resource Locator). URL manipulation can be employed as a convenience by a Web server administrator, or for nefarious purposes by a hacker.

What is ADB in android?

It is acts as bridge between emulator and IDE, it executes remote shell commands to run applications on an emulator
adb is Android Debug Bridge. To restart adb by command line: adb kill-server adb start-server To restart adb in Eclipse: Window > Show View > Other... > Android/Devices When the view is showing: View Menu of "Devices" > Reset adb

Android Debug Bridge

This is the literal meaning of ADB. Though at first glance it doesn’t appear to tell you anything, it actually does. It’s a “bridge” for developers to work out bugs in their Android applications. This is done by connecting a device that runs the software through a PC, and feeding it terminal commands. ADB lets you modify your device (or device’s software) via a PC command line.

If command line syntax confuses or intimidates you, have no fear. For most average users, the only time you’ll need to use ADB is when you have step-by-step instructions in front of you.

What is a JDBC Driver?

JDBC driver is an interface enabling a Java application to interact with a database. To connect with individual databases, JDBC requires drivers for each database. The JDBC driver gives out the connection to the database and implements the protocol for transferring the query and result between client and database.

JDBC Driver is a  an application program interface (API).  that enables java application to interact with the database.There are 4 types of JDBC drivers:

There are 4 types of JDBC drivers:

  • JDBC-ODBC bridge driver
  • Native-API driver (partially java driver)
  • Network Protocol driver (fully java driver)
  • Thin driver (fully java driver)

1) JDBC-ODBC bridge driver

The JDBC-ODBC bridge driver uses ODBC driver to connect to the database. The JDBC-ODBC bridge driver converts JDBC method calls into the ODBC function calls. This is now discouraged because of thin driver.

Advantages:

  • easy to use.
  • can be easily connected to any database.

Disadvantages:

  • Performance degraded because JDBC method call is converted into the ODBC function calls.
  • The ODBC driver needs to be installed on the client machine.

2) Native-API driver

The Native API driver uses the client-side libraries of the database. The driver converts JDBC method calls into native calls of the database API. It is not written entirely in java.

Advantage:

  • performance upgraded than JDBC-ODBC bridge driver.

Disadvantage:

  • The Native driver needs to be installed on the each client machine.
  • The Vendor client library needs to be installed on client machine.

3) Network Protocol driver

The Network Protocol driver uses middleware (application server) that converts JDBC calls directly or indirectly into the vendor-specific database protocol. It is fully written in java.

Advantage:

  • No client side library is required because of application server that can perform many tasks like auditing, load balancing, logging etc.

Disadvantages:

  • Network support is required on client machine.
  • Requires database-specific coding to be done in the middle tier.
  • Maintenance of Network Protocol driver becomes costly because it requires database-specific coding to be done in the middle tier.

4) Thin driver

The thin driver converts JDBC calls directly into the vendor-specific database protocol. That is why it is known as thin driver. It is fully written in Java language.

Advantage:

  • Better performance than all other drivers.
  • No software is required at client side or server side.

Disadvantage:

  • Drivers depends on the Database.

What are Wrapper classes?

These are classes that allow primitive types to be accessed as objects. Example: Integer, Character, Double, Boolean etc.

Wrapper class in java provides the mechanism to convert primitive into object and object into primitive.

ince J2SE 5.0, autoboxing and unboxing feature converts primitive into object and object into primitive automatically. The automatic conversion of primitive into object is known as autoboxing and vice-versa unboxing.

The eight classes of java.lang package are known as wrapper classes in java. The list of eight wrapper classes are :

Primitive TypeWrapper class
booleanBoolean
charCharacter
byteByte
shortShort
intInteger
longLong
floatFloat
doubleDouble
 

it is used to convert primitive into object and object into primitive data type.

Why Java is considered dynamic?

It is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

Java is considered as Dynamic because of Bytecode[a class file]. A source code writen in one platform, the same code can be executed in any platform[ which JDK is installed.]. And it also loads the class files at runtime. anything that happes at runtime is considered as Dynamic

Because byte code and source code written in one platform ,but some code will run on JDK thats why java is considered as a dynamic language.

How to delete a session in servlet?

When you are done with a user's session data, you have several options:

  • Remove a particular attribute: You can call public void removeAttribute(String name) method to delete the value associated with a particular key.

  • Delete the whole session: You can call public void invalidate() method to discard an entire session. Setting Session timeout: You can call public void setMaxInactiveInterval(int interval) method to set the timeout for a session individually.

  • Log the user out: The servers that support servlets 2.4, you can call logout to log the client out of the Web server and invalidate all sessions belonging to all the users.

To delete a session you can either call session.invalidate() method or session.setMaxInactiveInterval(0)

If you mean this by manually using removeAttribute() for every single attribute which can be obtained by getAttributeNames(), then this makes really no sense. I'm not sure whether it's the course/tutor which is bad or that you misinterpreted the course/tutor.


So one of my classmate asked - "How about we delete the HttpSession permanently after we've done using it?"

Yes, you can "delete" it by invalidating it.

session.invalidate();
response.sendRedirect("login.jsp");

Any subsequent request will force the server to create a new session. The redirect is by the way not necessary, but mandatory if you'd like to present the view in a fresh new session.