Saturday, May 12, 2012

Useful Technical Web Links

Following are some useful web links.
These are the result while executing a project using PHP, MySQL & PERL technologies.

HTML & Javascript Related


PHP MySQL, Perl Related


File Uploads using PHP

Java Must Know OOPs Concepts

Java is Object Oriented Programming Language and widely used language for web development or stand alone applications today. Its so popular due its feature "Write once, run anywhere". This simply means that the java program that you write can run on multiple JVMs and Operating Systems such as Windows, Linux, Mac etc. Java is architecture neutral. The language has been evolving day by day adding new features, improving existing implementations to help programmer write better java code with ease. Today there are many frameworks developed basing the language and are popular for writing 3-tier applications that are scalable. Before going on to all of that, lets understand the basics of object oriented concepts.

Encapsulation 

 "The wrapping up of data and functions into a single unit" is what is called an encapsulation. You can also define encapsulation as "process of hiding implementation details of an object".   Once an object is encapsulated, its implementation details are not immediately accessible any more. Instead they are packaged and are only indirectly accessed via the interface of the object achieved by access modifiers.

Abstraction
"Showing the essential and hiding the non-essential" is what is called abstraction. As an example, List interface is an abstraction. It only defines the general behavior of a list and leaves it open how it gets implemented.

Inheritance
 An object is able to inherit(re-use) characteristics from another object or an object is able to pass on its state and behavior to its children. Inheritance provides a powerful and natural mechanism for organizing and structuring your software. When use inheritance? When we want to create an entirely new class but wish to borrow a group of existing attributes or methods resident in an existing abstract or super class instead of re-inventing the wheel. Inheritance allows us to treat a subclass as if it was a super class. A subclass can only extend one super class. There can be any number of sub classes for a super class.

Polymorphism
"Ability to appear in many forms". Ability of a reference variable to change behavior according to what object instance it is holding.
Example:
                class Person{
                    public String getName(){ }
               }
              class Student extends Person{
                         public String getName(){
                                  return "Student Name";
                        }
              }
             class Employee extends Person{
                      public String getName(){
                               return "Employee Name";
                      }
              }
Now,
          Student studentObj = new Student();
          Employee employeeObj = new Enployee();

          Person personRef = studentObj;
                     personRef.getName(); //Student Name gets printed
          public static printName(Person p){
                p.getName(); // getName() of actual object passed is called
          }

Characteristics of polymorphism are (a) Simplicity - Easy to understand the code and (b) Extensibility - Other sub classes can be added to the family of types. Objects of these sub classes work with existing code.

There are 3 forms of polymorphism in Java
  • Method Overriding: Method of sub classes override the methods of a super class
  • Method overriding (Implementation) of abstract methods. Methods of subclass implement abstract methods of an abstract class.
  • Method overriding through Java Inheritance - Methods of a concrete class implement the methods of the interface.
Compile time polymorphism is achieved by method overloading (Early binding)
Runtime polymorphism is achieved by method overriding  (Late binding)

Rules of method overloading:
  • Arguments  ---> Must cahnge
  • Return type ---> Can change
  • Exceptions  ---> Can change
  • Invocations ---> Which method to call is based on the reference type at compile time
Rules of method overriding
  • Arguments ---> Must NOT change
  • Return type--->Can't change except for co-variant (subtypes) returns
  • Exceptions ---> Can reduce/eliminate. Must not throw new/broader exceptions
  • Access      ---> Must NOT be more restrictive. Can be less restrictive
  • Invocations---> Which method to call is based on the object type at run time. 
I will be writing more on Java Technologies in my future articles.

Configure Ant In Eclipse IDE

Eclipse is the software development IDE that is used widely by developer because of its ease of use and flexibility to have new/required features by installing Eclipse plug ins. Users can create new projects and develop source files and build the same. However in case of complex projects (Involving many dependent projects) Ant (Yet Another Tool) is used build the projects. Ant targets can be invoked from command prompt or from within Eclipse IDE itself by configuring Ant in Eclipse. In this article I'm going show how we can configure Ant in Eclipse and build software projects. This article assumes that you already have a ant build xml file with required ant targets to build your project.

1. Install Ant tool. Follow instructions available at http://ant.apache.org/manual/install.html
2. Update the environment variable PATH  to include the bin directory of Ant installation (Ex: D:\apache-ant-1.7.0\bin. This is required if you want to run ant targets from command prompt being in any directory location.
3. Open your eclipse IDE. Double click Eclipse.exe to open it and select Preferences off Window as shown below

4. Click 'Ant-Home' shown in red color below
5. Browse through the Ant-home location of your Ant installation and click OK to close the dialog


6. Open Ant View in eclipse as shown below


7.Add Ant builds as shown below

8. Browse to a valid ant build file and select. Eclipse lists all the ant targets available under that build xml file


9. Double click on the required ant target to run it. View the Eclipse Console for logs and you are done!


Sunday, May 6, 2012

Prevent OutOfPermGenSpace Java Error

PermGen space error is thrown by the Java Application if the application loads more number of classes into the memory than limited by the JVM PermSpace limit. This happens in a bigger Java applications and typically observed if the same application is loaded into the memory several times. PermGen space error is not same as Heap Space error. This error can also occur if there are memory leaks by your application or memory leaks in class loaders themselves. PermGen space is the memory in JVM to keep the loaded classes.

Let's understand different types of memory allocated by JVM for Java applications.
  • den Space (heap): The pool from which memory is initially allocated for most objects.
  • Survivor Space (heap): The pool containing objects that have survived the garbage collection of the Eden space.
  • Tenured Generation (heap): The pool containing objects that have existed for some time in the survivor space.
  • Permanent Generation (non-heap): The pool containing all the reflective data of the virtual machine itself, such as class and method objects. With Java VMs that use class data sharing, this generation is divided into read-only and read-write areas.
  • Code Cache (non-heap): The HotSpot Java VM also includes a code cache, containing memory that is used for compilation and storage of native code.
If we look at the definitions above there two categories (1) Heap and the other (2) Non-Heap. Heap is run time 'Data Area' meaning that memory allocated by JVM for all class instances and arrays whereas Non-Heap is 'Method Area' meaning that the memory required for internal processing or optimization for the JVM.

Both types of memories Heap and Non heap may be of fixed size or variable size. It depends on implementation of the underlying JVM. The Non-heap space may or may not be garbage collected unlike the heap memory. Though there are ways to increase these types of memories but its unlikely that out of PermGenSpace error is resolved since its a shared memory. However increasing the global heap space size may prevent OutOfHeap error in a Java Application.

What can be done to solve OutOfPermGenSpace Error?

1. Try out increasing the size limit using  "-XX:PermSize" and  "-XX:MaxPermSize" options as JVM arguments. This is a workaround but not a solution.
2. Check if your application has any memory leaks using Java Profiling Tools.
3. Check if there are any memory leaks by the class loaders. Yes, there could be memory leaks by class loaders too.

References

PermGen is not part of Heap Space
http://docs.oracle.com/javase/6/docs/technotes/guides/management/jconsole.html

Issues with Perm Space growing are seen while we manipulates class loaders.
http://stackoverflow.com/questions/2051734/why-is-permgen-space-growing

Fix the memory leaks found
http://www.springsource.com/files/uploads/all/pdf_files/news_event/Inside_the_JVM.pdf



Related Posts Plugin for WordPress, Blogger...