Navigation

Thursday, 27 February 2014

Create,Delete and Compile by ANT build file.(Ant Part-3)

In our last post we have seen 
Now we will see some core task which can be performed by using ant such as create a folder or delete folder and to compile the java source.If till now you have not got 1% idea about ANT don't worry it is not needed also just check the below XML build file.

<?xml version="1.0"?>
<project name="MyfirstAnt" default="main" basedir=".">
  <!-- Sets variables which can later be used. -->
  <!-- The value of a property is accessed via ${} -->
  <property name="create.dir" location="D:/MyAnt/NewFolder" />
  <property name="delete.dir" location="D:/MyAnt/OldFolder" />                  
  <!-- Deletes oldFolder from the path delete.dir-->
  <target name="cleanFolder">
    <delete dir="${delete.dir}" />
  </target>

  <!-- Creates a newfolder on the path create.dir-->
  <target name="makefolder">
    <mkdir dir="${create.dir}" />
  </target>

  <!-- Compiles the java code (including the usage of library for JUnit -->
  <target name="compile" depends="cleanFolder, makefolder">                 <javac srcdir="${src.dir}" destdir="${build.dir}">
    </javac>

  </target>
  <target name="main" depends="compile">
    <description>Main target</description>
  </target>

</project> 

Here we have written three tasks first is to delete a particular folder from file system  the path which you will give in dir attribute it will clean the particular folder means it can be used to clean the class files before building .

Second task is to create a folder so you can create any folder in file system it can be temp .

and last task is to compile the the java source files here we have to give the source path of java files and destination folder where you have to keep the class files you can also set class-path for proper compilation which we will discuss in our coming posts.


You may also like:-

Using JConsole in java And creating memory dump by it

Heap analysis by Memory Analyzer (MAT) - Eclipse java

Main causes of Out-Of-Memory Errors in java

Five main types of Memory leaks in java

How to Reduce Garbage-Collection Pause Time?

4 Mains causes of Long Garbage Collection Pause?


How Application Performance get impacted by Garbage Collection?


Java Performance Tuning options Java heap


Why Memory leak in Java ?


What is a Memory Leak in java?


What is Garbage collector in java and how it works?


What is Garbage Collector Compaction in Java?


What are Java heap Young, Old and Permanent Generations?


What is difference between Web Server and Application Server ?


What is the maximum ram for 32 bits and 64 bits computer?


Some Amazing fact about memory (petabyte,exabyte,zettabyte) And How much data exists on the Web?

Setting Apache ANT on Computer (Ant part-2)

 Setting up your machine with Ant

Follow the steps to setup the Ant in your computer.

1. Download the following  files(apache-ant-1.7.0-bin.zip) to your hard drive.

2. Unzip the file to anywhere in your hard drive in any folder.

3. Right click your My Computer icon in the Desktop and choose the properties.

4. In the properties now select the Advanced tab and open Environment Variables button.

5. Click on the New button in the System Variable options and enter the following
Variable name - ANT_HOME
Variable value – The ant path location in your system (for example C:\ant\myant)

6. Click the OK button ans save the setting

7. Set the PATH as below in your system (If you have a PATH variable exists in your system then
append the ANT_HOME to it)
set PATH=%PATH%;%ANT_HOME%\bin


Tuesday, 25 February 2014

What is Apache Ant ("Another Neat Tool") in java?(ANT Part-1)



Apache Ant ("Another Neat Tool") is a  build tool with special support for the Java programming language however it may be used for regarding everything. Ant is platform-independent. Ant is especially sensible at automating difficult repetitive tasks and so is well matched for automating standardized build processes. Ant accepts directions within the type of XML documents so is extensile and simple to take care of.So you can say it is a xml file you running by the help of Ant.

An ant build file comes within the sort of an XML document, all that's needed may be a straightforward text editor to edit the build file(s). an editor that gives XML syntax lightness is desirable. The ant installation comes with a JAXP-Compliant(Which is XML parser) ,this implies that the installation of AN external XML computer program isn't necessary

For Installation 

1)You will need to download a file apache-ant-1.7.0-bin.zip
2)Extract it 
3)Here you will get "bin" folder
4)In "bin" run the ant.bat file from cmd.


Now let us try this with a simple build.xml for this.

1)create a file in notepad or any other file editor

2)copy the below code in that

<?xml version="1.0"?>
   <project name="My First Project" default="whatsup">
       <target name="whatsup">
          <echo>Hi this is my first ant build file</echo>
       </target>
   </project>

3)Save this as build.xml file(in ant bin directory where ant.bat is present)
apache ant

4)You can run this from a DOS  command prompt by typing

  ant
Ant will search for the build file in the current directory and run the build.xml file.

5)your out put will


Buildfile: build.xml
  
  whatsup: 
     [echo] Hi this is my first ant build file!
  
  Build Successful
  Total time 0 seconds

If you have many targets which you have run or execute in series then you can use depends attribute.
The depends attribute may be enclosed within the target tag to specify that this target needs another target to be executed before being executed itself. Multiple targets may be nominal and separated with commas.

<target name="ab" depends="bc, cd,de">

<?xml version="1.0" encoding="UTF-8"?>

 <project default="3">
     <target name="1">
        <echo>Running first</echo>
     </target>
  
     <target name="2" depends="1">
        <echo>Running second</echo>
     </target>
  
     <target name="3" depends="2">
        <echo>Running third</echo>
     </target>
  </project>

Buildfile: build.xml
  
  one:
     [echo] Running first
  
  two:
     [echo] Running second
  
  three:
     [echo] Running third
  
  BUILD SUCCESSFUL
  Total time: 0 seconds


Ant Task – one thing that ant will execute like a compile, copy or replace. Most tasks have much convenient default values. See the ant manual for an entire list of tasks.

Ant Target – a hard and fast series of ant tasks in an exceedingly nominal order that may depend on alternative named targets. Targets will depend solely on alternative targets, not on projects or tasks. A target represents a specific item to be created, it can be one item sort of a jar, or a group of things, like classes.

Ant Project – a set of named targets that may run in any order looking on the time stamps of the files within the file system. every build file contains one project.


Here are a few things to note:

1.The Begin and finish tags for project (<project> and </project>) MUST Begin and end the file.

2.The tag project MUST have an attribute called default which is the targets called first.

3.There should be at least one target in each build file.

4.The Begin and finish tags for <target> and </target> must  match EXACTLY.

5.Each target should  have a name.

6.Targets will only depend  on other targets and reference them by their name(target name). it NEVER depend on projects or tasks.

7.Target depends are not mandatory.

8.To print any thing in output on console write it in <echo> and </echo> tags.

9.All task has to be in a target.


You may also like:-

Using JConsole in java And creating memory dump by it

Heap analysis by Memory Analyzer (MAT) - Eclipse java

Main causes of Out-Of-Memory Errors in java

Five main types of Memory leaks in java

How to Reduce Garbage-Collection Pause Time?

4 Mains causes of Long Garbage Collection Pause?


How Application Performance get impacted by Garbage Collection?


Java Performance Tuning options Java heap


Why Memory leak in Java ?


What is a Memory Leak in java?


What is Garbage collector in java and how it works?


What is Garbage Collector Compaction in Java?


What are Java heap Young, Old and Permanent Generations?


What is difference between Web Server and Application Server ?


What is the maximum ram for 32 bits and 64 bits computer?


Some Amazing fact about memory (petabyte,exabyte,zettabyte) And How much data exists on the Web?
http://www.casino-online.us

Saturday, 15 February 2014

20 Facts about google you must know



1) The biggest irony of Larry Page and Sergey Brin’s life is that there original goal for these  two enthusiastic PH.D. Students was to to sell their Google search idea for $1 million to whoever was willing to purchase it. However, luckily for them (and us?), nobody turned up... and In the year 1997, Yahoo rejected an offer to buy Google for $1 million ,whereas Google has grown up to $200 Billion. 


2) Google was originally named Googol but when  Larry Page and Sergey Brin received their first $100,000 paycheck in the name of Google Inc. and they had to run and create a bank account for the name, so that they could cash it. Therefore, the naming ceremony was nothing but an accident.


3)Google's first ever Twitter post was as

For anyone not fluent in binary, here's a hint — it's a well known phrase from the company's homepage. Got it? Yep, it reads: "I'm feeling lucky."


4)Google estimates that the "I'm feeling lucky!" button has cost 

approximately $100 million dollars in lost ad revenue, but Google still keeps the button because the users like it.

5) Google announced its spell checker i.e. “Did you mean…” feature. This instantly doubled their traffic.



6) Google rents out goats. Yes you read that right. It rents goats from a company called California Grazing to help cut down the amount of weeds and brush at Google HQ.


7)The word Google is now a Google definition in Google dictionary


formal English word, and was included in the Oxford English Dictionary in 2006. Now, you can listen to more and more people saying “google it" used as a synonym for general web searching.


8) Many Google products originated as services provided by companies that Google has since acquired 143 one of which is deepmind a best AI company.


9) October 9, 2006, it was announced that the YouTube would be purchased by Google for US$1.65    billion (Though google has its own google vedious)


10) Some facts about YouTube.



  • More than 1 billion unique users visit YouTube each month
  • Over 6 billion hours of video are watched each month on YouTube—that's almost an hour for every person on Earth, and 50% more than last year
  • 100 hours of video are uploaded to YouTube every minute
  • 80% of YouTube traffic comes from outside the US
  • YouTube is localized in 61 countries and across 61 languages



11) The home page of google was dimple because at that time they dont know much HTML so they they designed it in simple manner.Over the years, the founders still prefer and insist to keep the home page simple and they insist that the words on the home page do not exceed 28 words.

12) Google estimates that an ad on its homepage would cost around  $10 million, but the page is still not for sale. The founders of the company want to keep the page as it started years ago.

13) Google written backwards is elgooG, but did you know you could search backwards too at http://elgoog.im

14)The private planes of Sergey Brin and Larry page land on the strips of NASA HQ, where no other planes can land. Talk about royalty -  Googlers are having the best of it.

15) Google Earth reached one-billion downloads in 2011.


 16) “(Google)…receives more than 20,000 resumes a week, or two every minute, according to Sunny Gettinger, a Google spokeswoman.”


17)  Out of which only less then 0.5% gets selected after series of 29 Interviews.


18) Employees are encouraged to use 20% of their time working on their own projects. Google News, Orkut are both examples of projects that grew from this working model.


19) 620 million users 
visit www.google.com daily. Does that number stand for half the world’s population? Maybe not, but it definitely stands for almost all the people who use the Internet.

20) Google processes around 20 petabytes 1015 or 1,000,000,000,000,000 bytes of information Data petebytes processed by google daily, which is an unbelievable number to put your mind around. The number suggests that approximately almost every person using the Internet uses Google at least once.
You may also like:-

Using JConsole in java And creating memory dump by it

Heap analysis by Memory Analyzer (MAT) - Eclipse java

Main causes of Out-Of-Memory Errors in java

Five main types of Memory leaks in java

How to Reduce Garbage-Collection Pause Time?

4 Mains causes of Long Garbage Collection Pause?


How Application Performance get impacted by Garbage Collection?


Java Performance Tuning options Java heap


Why Memory leak in Java ?


What is a Memory Leak in java?


What is Garbage collector in java and how it works?


What is Garbage Collector Compaction in Java?


What are Java heap Young, Old and Permanent Generations?


What is difference between Web Server and Application Server ?


What is the maximum ram for 32 bits and 64 bits computer?


Some Amazing fact about memory (petabyte,exabyte,zettabyte) And How much data exists on the Web?



Friday, 14 February 2014

Compression of HttpServletRequest and HttpServletResponse by gzip encoding


Description 
This filter is on HTTP headers in a HttpServletRequest, compress data written to the HttpServletResponse, or decompress data read from the request. When supported by the client browser, this can potentially greatly reduce the number of bytes written across the network from and to the client. As a Filter, this class can also be easily added to any J2EE 1.3+ web application.





Installation

1).Add the pjl-comp-filter-XX.jar file containing CompressingFilter to your web application's WEB-INF/lib directory.

2).Add the following entries to your web.xml deployment descriptor:

 <filter>
  <filter-name>CompressingFilter</filter-name>
  <filter-class>com.planetj.servlet.filter.compression.CompressingFilter</filter-class>
 </filter>

 <filter-mapping>
  <filter-name>CompressingFilter</filter-name>
  <url-pattern>/*</url-pattern>
 </filter-mapping>

The below data is of my application where i tested this compression techniques

The count is based on data fetched from fiddler when running  app  with and without compression Filter.

Data compression ratio=5:1

Header space savings =80%

Encoding used= gzip

Below header data is actual and after installing CompressingFilter.



Before encoding
After using gzip encoding
    Request Count: 12
    Bytes Sent: 8,212
    Bytes Received: 92,623

    ACTUAL PERFORMANCE
    --------------
    Requests started at: 17:58:52:1558
    Responses completed at: 17:58:57:9514
    Aggregate Session time: 00:00:05:1525
    Sequence (clock) time: 00:00:05.7955795

    RESPONSE CODES
    --------------
    HTTP/404: 1
    HTTP/304: 10
    HTTP/200: 1

    RESPONSE BYTES (by Content-Type)
    --------------
    ~headers: 1,384
    text/html: 91,239
    Request Count: 12
    Bytes Sent: 8,206
    Bytes Received: 15,392

    ACTUAL PERFORMANCE
    --------------
    Requests started at: 18:30:13:7882
    Responses completed at: 18:30:14:9522
    Aggregate Session time: 00:00:00:7760
    Sequence (clock) time: 00:00:01.1640000

    RESPONSE CODES
    --------------
    HTTP/404: 1
    HTTP/304: 10
    HTTP/200: 1

    RESPONSE BYTES (by Content-Type)
    --------------
    ~headers: 1,661
    text/html: 13,731

Wednesday, 12 February 2014

Example of Garbage collection .

This post is dedicated to explain how Garbage collection works and what can cause memory leaks.
Here we will manually run a small program and will check how memory is allocated to objects and how they it
is collected back when they needed no more.

Lets create a Valueobject which we will access from a class .
below is a Employee Vo which contains name and id of a employees

Lets create a Test class to accesses this Vo .

The above class contains a method m1 and a main method.

When JVM starts it creates to portions to store data
1) heap to keep objects 
2) stack to keep primitive data types and references to heap.Each method will have there own heap

So when we will run the above Test class the memory snap at line number 4 will be

Heap
===================
Empty


Stack
=============
main method
---------------
args:null


so initially heap will be empty and stack will contain the args passed to main method.
Every method has its own stack.
At line number 5 it will store the value of val in stack . it will be in stack because val is of primitive data type.
now memory snap will.

Heap
===================



Stack
=============
main method
---------------
args:null
val:10


On next line i.e. line number 6 it will create a object of Employee and 
will store in heap and will maintain its reference in stack
So it will look like 

Heap
===================
1000X:EmployeeObj name=2000X , id=2
2000X:StringObj "Ravi"


Stack
=============
main method
---------------
args : null
val : 10
e : 1000X

Here 1000X and 2000X are memory addresses and since "Ravi"
is a object of String class it will be stored at different address


On next line number 7 it is calling a method m1 so a new stack will be created in a
stack and will hold the passed parameter i.e. object e

Heap
===================
1000X:EmployeeObj name=2000X , id=2
2000X:StringObj "Ravi"


Stack
=============

main method
---------------
args : null
val : 10
e : 1000X

m1 method
--------------------
e : 1000X----passed as reference 


Now in next line 12 it has changed the value of id from 2 to 5 
so it will be like

Heap
===================
1000X:EmployeeObj name=2000X , id=5
2000X:StringObj "Ravi"


Stack
=============
main method
---------------
args : null
val : 10
e : 1000X

m1 method
--------------------
e : 1000X


The reference of e will be the same 
At next line number 13 its creating a new object.
Remember When we use New key word always a new object is created
So the heap stack position will be like.


Heap
===================
1000X:EmployeeObj name=2000X , id=5
2000X:StringObj "Ravi"
3000X:EmployeeObj name=4000X , id=7
4000X:StringObj "Gaurav"


Stack
=============

main method
---------------
args : null
val : 10
e : 1000X

m1 method
--------------------
e : 3000X


Now at line number 14 its id value will be changed to 9
so memory snap will

Heap
===================
1000X:EmployeeObj name=2000X , id=5
2000X:StringObj "Ravi"
3000X:EmployeeObj name=4000X , id=9
4000X:StringObj "Gaurav"


Stack
=============

main method
---------------
args : null
val : 10
e : 1000X

m1 method
--------------------
e : 3000X


At line 15 method will be finished and its stack will be removed

Heap
===================
1000X:EmployeeObj name=2000X , id=5
2000X:StringObj "Ravi"
3000X:EmployeeObj name=4000X , id=9
4000X:StringObj "Gaurav"


Stack
=============

main method
---------------
args : null
val : 10
e : 1000X

So finaly the value of the id at line number (8) will 5
Heap
===================
1000X:EmployeeObj name=2000X , id=5
2000X:StringObj "Ravi"
3000X:EmployeeObj name=4000X , id=9
4000X:StringObj "Gaurav"

Stack
=============
main method
---------------
args : null
val : 10
e : 1000X


Now let at this point garbage collector runs
So first it will mark all the live object which can be referred from stack.
and will remove all other objects from memory

Heap
===================
1000X:EmployeeObj name=2000X , id=5
2000X:StringObj "Ravi"
3000X:EmployeeObj name=4000X , id=9
4000X:StringObj "Gaurav"

Stack
=============
main method
---------------
args : null
val : 10
e : 1000X


After running GC

Heap
===================
1000X:EmployeeObj name=2000X , id=5
2000X:StringObj "Ravi"
4000X:StringObj "Gaurav" not be collected 

Stack
=============
main method
---------------
args : null
val : 10
e : 1000X


String objects will not be removed since they are sorted in separate memory called String pool.

You may also like:-

Using JConsole in java And creating memory dump by it

Heap analysis by Memory Analyzer (MAT) - Eclipse java

Main causes of Out-Of-Memory Errors in java

Five main types of Memory leaks in java

How to Reduce Garbage-Collection Pause Time?

4 Mains causes of Long Garbage Collection Pause?


How Application Performance get impacted by Garbage Collection?


Java Performance Tuning options Java heap


Why Memory leak in Java ?


What is a Memory Leak in java?


What is Garbage collector in java and how it works?


What is Garbage Collector Compaction in Java?


What are Java heap Young, Old and Permanent Generations?


What is difference between Web Server and Application Server ?


What is the maximum ram for 32 bits and 64 bits computer?


Some Amazing fact about memory (petabyte,exabyte,zettabyte) And How much data exists on the Web?