PUB ID

Saturday, 4 March 2017

Different Ways To Iterate Map In JAVA......?

package in.blogspot.myjavadoubts

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

public class DifferentWaysToIterateMap {

    public static void main(String[] args) {

        Map<Integer, String> map = new HashMap<Integer, String>(); //create new Instance For Map
      
        //inserting elements into Map
        map.put(0, "Sunday");
        map.put(1, "Monday");
        map.put(2, "Tuesday");
        map.put(3, "Wednesday");
        map.put(4, "Thursday");
        map.put(5, "Friday");
        map.put(6, "Saturday");

        //1-way to Iterate Map
        Iterator<Entry<Integer,String>> iterator = map.entrySet().iterator();
        while (iterator.hasNext()) {
            Map.Entry<Integer,String> entry = (Map.Entry<Integer,String>) iterator.next();
            System.out.println("Key : " + entry.getKey() + " Value :" + entry.getValue());
        }
      
        // 2-Way to Iterate Map
        for (Object key : map.keySet()) {
            System.out.println("Key : " + key.toString() + " Value : " + map.get(key));
        }

        // 3-way to Iterate Map -->recomended way to Iterate Map
        for (Map.Entry<Integer, String> entry : map.entrySet()) {
            System.out.println("Key : " + entry.getKey() + " Value : " + entry.getValue());
        }

        //4-Way to Iterate Map-->supports java 8 Only
        map.forEach((k,v)->System.out.println("Key : " + k + " Value : " + v));
    }

}

Tuesday, 28 February 2017

Most Tricky Question in Java Exception Handling.Does Finally Block Execute Always?

Does Finally Block Execute Always?

 Answer Is -No
 Finally Block Does Not Execute Always...

in Java is that finally block will execute even if you put a return statement in the try block or catch block but finally block won't run if you call System.exit() from try or catch block.

Thursday, 30 June 2016

10 Limitations of Servlets

  1. Servlets of web application requires strong knowledge of Java.
  2. Servlets are very difficult for Non-Java Programmers to understand and carry out.
  3. We know that, Servlet is a picture of both Presentation logic(HTML) and Business Logic(Java) . At the time of development of Servlet by using both of the above (Presentation and Business Logic), it may become imbalance, because a Servlet developer can’t be  good in both Presentation logic and Business logic.
  4. Servlet never provides  separation between or clarity between Presentation Logic and Business Logic.
    So that servlets do not give Parallel Development.
  5. If we do any changes in a servlet, then we need to do Re-deployment process i.e. Servlets modifications requires redeployment, which is one of the time-consuming process.
  6. If we develop any web application with servlets, then it is mandatory for the web application developer to configure web-application configuration file. (Deployment descriptor- web.xml)
  7. Servlets do not offer any implicit object. [implicit objects generally provided by containers during the dynamic program execution ].
  8. Servlets do not contain a facility called Custom Tags Development.
  9. Servlets don’t provide Global/Implicit exception handling facility.
  10. Servlets don’t vontain Automatic Page compilation concept.

Thursday, 19 May 2016

Can we write constructor inside interface in java?

  • No. Interfaces does not allow constructors.
  • Why interface does not have constructor?
  •  The variables inside interfaces are static final variables means constants and we can not create object for interface so there is no need of constructor in interface that is the reason interface doesn't allow us to create constructor.

What will happens if we try to create constructor inside interfaces in java 


  • If we try to create constructor in interface compile time error will come.
  • Error description: Interfaces cannot have constructors.

Sunday, 28 February 2016

12 Rules of Overriding a Method in Java You Should Know

Rule #1: Only inherited methods can be overridden.
Rule #2: Final and static methods cannot be overridden.
Rule #3: The overriding method must have same argument list.
Rule #4: The overriding method must have same return type (or subtype).
Rule #5: The overriding method must not have more restrictive access modifier.
Rule #6: The overriding method must not throw new or broader checked exceptions.
Rule #7: Use the super keyword to invoke the overridden method from a subclass.
Rule #8: Constructors cannot be overridden.
Rule #9: Abstract methods must be overridden by the first concrete (non-abstract)          subclass
Rule #10: A static method in a subclass may hide another static one in a  superclass, and that’s        called hiding.
Rule #11: The synchronized modifier has no effect on the rules of overriding.
Rule #12: The strictfp modifier has no effect on the rules of overriding.

for more details with examples click here

what is the difference between database and datawarehouse?

The purpose of a data warehouse is to provide flexible access to the data to the user. Data warehousing generally refers to the combination of many different databases across an entire enterprise. Data warehouses store current as well as historical data, so that all of the relevant data may be used for analysis. The analysis helps to find and show relationships among the data, to extract meaning from the data.
A database, on the other hand, is the basis or any data storage. It is an organized collection of data. Data from various sources are collected in to a single place, this place is the database. The data is organized into a structure of some sort, mainly according to a database model. The most commonly used database model is the relational model, others include hierarchical model, network model, etc.

Some differences between a database and a data warehouse:
  • A database is used for Online Transactional Processing (OLTP) but can be used for other purposes such as Data Warehousing.
  • A data warehouse is used for Online Analytical Processing (OLAP). This reads the historical data for the Users for business decisions.
  • In a database the tables and joins are complex since they are normalized for RDMS. This reduces redundant data and saves storage space.
  • In data warehouse, the tables and joins are simple since they are de-normalized. This is done to reduce the response time for analytical queries.
  • Relational modeling techniques are used for RDMS database design, whereas modeling techniques are used for the Data Warehouse design.
  • A database is optimized for write operation, while a data warehouse is optimized for read operations.
  • In a database, the performance is low for analysis queries, while in a data warehouse, there is high performance for analytical queries.
  • A data warehouse is a step ahead of a database. It includes a database in its structure.

In Simple words a dataware house is a  collection of different databases.





Friday, 5 February 2016

what is Serialization?

The Process Of Sending An Object Data Across the Network is called as Serializaton.

But Strictly speaking it is the process of converting an object from java support from to stream supported form (or) stream of bytes.

To serialize any object the class must be implements Serializable interface.

Serializable interface is present in java.io.package.