Wednesday 14 December 2016

Advantages and Disadvantages of java

Advantages:

  1. Java is Simple: Java was designed to be easy to use and is therefore easy to write, compile, debug, and learn than other programming languages.
  2. Java is Object-Oriented: Java is object-oriented because programming in Java is centered on creating objects, manipulating objects, and making objects work together. This allows you to create modular programs and reusable code.
  3. Java is Platform-Independent: One of the most significant advantages of Java is its ability to move easily from one computer system to another.
  4. Java is Distributed: Distributed computing involves several computers on a network working together.
  5. Java is Interpreted: An interpreter is needed in order to run Java programs. The programs are compiled into Java Virtual Machine code called bytecode. The bytecode is machine independent and is able to run on any machine that has a Java interpreter.
  6. Java is Secure: Java is one of the first programming languages to consider security as part of its design.
  7. Java is Multithreaded: Multithreaded is the capability for a program to perform several tasks simultaneously within a program.
  8. Language is common. Pick two random Java developers and you can be certain they "speak" same Java. Pick two random Haskell developers and you may be surprised.
  9. Lots of mature off-the-shelf libraries and tooling, both free and commercial.
  10. JVM provides a lot of standard off-the-shelf functionality that would otherwise need custom devopsing.



Disadvantages:


  1. Performance: Java can be perceived as significantly slower and more memory-consuming than natively compiled languages such as C or C++.
  2. Look and feel: The default look and feel of GUI applications written in Java using the Swing toolkit is very different from native applications.
  3. Single-paradigm language: Java is predominantly a single-paradigm language. However, with the addition of static imports in Java 5.0 the procedural paradigm is better accommodated than in earlier versions of Java.
  4. Checked Exceptions
  5. Thread.currentThread().stop(e)
  6. Using static
  7. Singletons
  8. Get a library or framework
  9. Using double
  10. Using null value
  11. Limited options for latency-critical tuning. If you have to spare every millisecond, Java is not the best choice.
  12. Not very handy for one-off throwaway scripts.
  13. Desktop GUI packages take effort to make application look native; especially on Mac.

                Wednesday 7 December 2016

                Advantages Of Using ArrayList Over Arrays

                Array and ArrayList are most used data types while developing any java applications. Both are used to store group of objects. 

                In this post I have tried to list down the advantages of using ArrayList over Arrays. Before discussing the advantages of ArrayList, let’s see what are the drawbacks of arrays.

                Following Advantages:
                1. An array is type specific i.e. one array can only store data of only one data type where as arraylist can store multiple data in the form of objects. So multiple objects of different data types can be stored in arraylist.
                2. In array you cannot increase or decrease the size dynamically where as in arraylist the size can be increased or decreased dynamically
                3. You can make arraylist readonly.
                4. You can insert element at any location in arraylist
                5. Arraylist supports BinarySearch
                6. ArrayLists implement iterable , which means you can easily iterate them.
                7. If an arraylist is modifed by another thread while it is being iterated by one thread , then it fails fast , which means you don't end up with unreliable data in the list.
                8. An array can be of any data type and contain one data type while array list can contain any data type in the form of the object.

                Tuesday 6 December 2016

                How to sort an ArrayList in java with it's example

                ArrayList’s elements are display according to the sequence it is put inside. The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed.

                Example:
                1. import java.util.ArrayList;
                2. import java.util.Collections;
                3. import java.util.List;
                4. public class DemoSortArrayList{
                5. public static void main(String args[]){
                6. List<String> unsortList = new ArrayList<String>();
                7. unsortList.add("CCC");
                8. unsortList.add("111");
                9. unsortList.add("AAA");
                10. unsortList.add("BBB");
                11. unsortList.add("ccc");
                12. unsortList.add("bbb");
                13. unsortList.add("aaa");
                14. unsortList.add("333");
                15. unsortList.add("222");
                16. //before sort the source now
                17. System.out.println("ArrayList is unsort");
                18. for(String temp: unsortList){
                19. System.out.println(temp);
                20. }
                21. //sort the list now
                22. Collections.sort(unsortList);
                23. //after sorted now
                24. System.out.println("ArrayList is sorted");
                25. for(String temp: unsortList){
                26. System.out.println(temp);
                27. }
                28. }
                29. }
                Output:
                ArrayList is unsort
                CCC
                111
                AAA
                BBB
                ccc
                bbb
                aaa
                333
                222
                ArrayList is sorted
                111
                222
                333
                AAA
                BBB
                CCC
                aaa
                bbb
                ccc

                Monday 5 December 2016

                Why java is not pure object oriented programming language

                Java is support preemptive types that's why it is not pure object oriented programming language. Preemptive types means int, float, char, boolean, long.

                Java is not Fully Object Oriented langauge because of it has Primitive Datatypes like float, int, char etc.

                Reasons:
                1. It does not support Multiple inheritance. 
                2. It allows use of primitive data types which are not an objects.
                3. It allows static methods to call without creating the instance. 

                Sunday 4 December 2016

                Why java is platform independent

                Because complied java file are executed through the JVM. When Java Code is compiled a byte code is generated which is independent of the system.




                The compiler converts source code file into bytecode files. These codes are machine independent and can be run on any machine. Java interpreter reads the bytecode files and translates them into machine code for the specific machine on which the Java program in running. java compiled program can be run on any operating system.

                Sunday 31 January 2016

                Use of request.getRequestDispatcher with example

                Use of request.getRequestDispatcher 


                It is interface. It provides the facility of dispatching the request to another resource it may be html, servlet or jsp.


                ## Example This example is for you how to use it.

                import java.io.*;  
                import javax.servlet.*;  
                import javax.servlet.http.*;    
                public class register extends HttpServlet {  
                  
                public void doPost(HttpServletRequest request, HttpServletResponse response)  
                        throws ServletException, IOException {  
                  
                    response.setContentType("text/html");  
                    PrintWriter out = response.getWriter();  
                          
                    String n=request.getParameter("userName");  
                    String p=request.getParameter("userPass");  
                          
                    if(p.equals("servlet"){  
                        RequestDispatcher rd=request.getRequestDispatcher("servlet2");  
                        rd.forward(request, response);  
                // here servlet2 is get Dispatcher.
                    }  
                    else{  
                        out.print("Unsucessful!");  
                        RequestDispatcher rd=request.getRequestDispatcher("/index.html");  
                        rd.include(request, response);  

                  }
                    }
                }

                Sunday 17 January 2016

                Operators in java with precedence

                Many types of operator in java like as :


                1. Postfix operator
                2. Unary operator
                3. Multiplicative operator
                4. Additive operator
                5. Shift operator
                6. Relation operator
                7. Equality operator
                8. Bitwise AND operator
                9. Bitwise exclusive OR operator
                10. Bitwise inclusive OR operator
                11. Logical AND operator
                12. Logical OR operator
                13. Ternary Operator
                14. Assognment operator





                Tuesday 12 January 2016

                Differents between object and class in java

                Object :-
                Any entity that has state and behavior is known as an object. For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.


                Class :-

                A class is a prototype that defines the variables and the methods common to all objects of a certain kind.





                Saturday 2 January 2016

                What is JVM(Java Virtual Machine) in java

                The Java Virtual machine (JVM) is the virtual machine that run the Java bytecodes. 





                It is a specification that provides runtime environment in which java bytecode can be executed. It is available for many hardware and software platforms.


                ## It's Performs Following main Tasks :

                1. Loads code
                2. Executes code
                3. Verifies code
                4. Provides returns environment
                The java virtual machine provides a platform independent way of executing code; that mean compile once any machine and run it any where.