Java

Arrays vs Collections

Image Posted on Updated on

colArr

Advertisements

Web Application/Enterprise Application

Posted on

  • Web application can be developed only by web related technologies like html, jsp’s ,servelets etc. Ex:Online Shopping App etc
  • Enterprise application can be developed using anything from java J2EE,hence enterprise application is a superior application. Ex:Banking,Telecom projects etc.

 

Web Server vs Application Server

Posted on

  • Web Server: Provides environment to run Web applications.
  • Application Server:->Provides environment to run Enterprise applications.

    –>Every Application server has an inbuilt web server.

 

 

 

Jar vs War vs Ear

Posted on Updated on

  • jar: Java archieve file- It is a group of .class files.
  • war: Web archieve file-It represents a web application in single zip file .(all the jsp,html,servelets etc).
  • ear: Enterprise archieve file-It represents a enterpriseapplication in single zip file .(all the jsp,EJB’s,jms,servelets etc).

Difference between Streams and Collections in Java

Posted on Updated on

Main differences between Collection and Stream API in Java 8 are:

I. Version: Collection API is in use since Java 1.2. Stream API is recent addition to Java in version 8.

II. Usage: Collection API is used for storing data in different kinds of data structures. Stream API is used for computation of data on a large set of Objects.

III. Finite: With Collection API we can store a finite number of elements in a data structure. With Stream API, we can handle streams of data that can contain infinite number of elements.

IV. Eager vs. Lazy: Collection API constructs objects in an eager manner. Stream API creates objects in a lazy manner.

V. Multiple consumption: Most of the Collection APIs support iteration and consumption of elements multiple times. With Stream API we can consume or iterate elements only once.

 

With a stream you can basically treat collections as you would in a functional language. For example you can map and filter on them. The idea is that the java developers didn’t add this functionality to collections before so they added streams.

As an example say you had a list of integers and you wanted to select those which are below 10. Without streams you would do something like this

List<Integer> listBelowTen = new ArrayList<Integer>

for (Int i : listOfInts) {

if (i < 10) {

listBelowTen.add(i);

}

}

This is a lot of lines of code to do a relatively simple thing.

With streams you simply do this:

List<Integer> listBelowTen = listOfInts.stream().filter(i -> i< 10).collect(AsList ());

So it basically adds a lot more functionality to your collections.

Java:String Pooling

Posted on Updated on

  • String Pool in java is a pool of Strings stored in Java Heap Memory. We know that String is special class in java.
  • String pooling concept can be better understood with the below diagram.

String-Pool-Java1

  • Hence when u do not use the new keyword the object is referenced to the same memory location.

Java: Difference between path & Classpath

Posted on Updated on

Difference between path and classpath

path classpath
  • path variable is used to set path for all java software tools like javac.exe, java.exe, javadoc.exe, and so on.
  • Path is an environment variable which is used by the operating system to find the executables i.e setting up environment for operating system
  • If u do not set path ,commands like javac will not work i.e our system doesnot knw the meaning of command.
  • Classpath is an environment variable which is used by the Java compiler/jvm to find the path, of classes.ie in J2EE we give the path of jar files.
  • classpath variable is used to set path for java classes which are used in our application.
  • It describes location where required .class files are available.

difference between path and classpath