Saturday, August 29, 2009

Java Interview Questions

Q1. How could Java classes direct program messages to the system console, but error messages, say to a file?

A. The class System has a variable out that represents the standard output, and the variable err that represents the standard error device. By default, they both point at the system console. This how the standard output could be re-directed:
Stream st = new Stream(new FileOutputStream(”output.txt”)); System.setErr(st); System.setOut(st);

Q2. What’s the difference between an interface and an abstract class?

A. An abstract class may contain code in method bodies, which is not allowed in an interface. With abstract classes, you have to inherit your class from it and Java does not allow multiple inheritance. On the other hand, you can implement multiple interfaces in your class.

Q3. Why would you use a synchronized block vs. synchronized method?
A. Synchronized blocks place locks for shorter periods than synchronized methods.

Q4. Explain the usage of the keyword transient?

A. This keyword indicates that the value of this member variable does not have to be serialized with the object. When the class will be de-serialized, this variable will be initialized with a default value of its data type (i.e. zero for integers).

Q5. How can you force garbage collection?

A. You can’t force GC, but could request it by calling System.gc(). JVM does not guarantee that GC will be started immediately.

Q6. How do you know if an explicit object casting is needed?

A. If you assign a superclass object to a variable of a subclass’s data type, you need to do explicit casting. For example:
Object a; Customer b; b = (Customer) a;
When you assign a subclass to a variable having a supeclass type, the casting is performed automatically.

Q7. What’s the difference between the methods sleep() and wait()

A. The code sleep(1000); puts thread aside for exactly one second. The code wait(1000), causes a wait of up to one second. A thread could stop waiting earlier if it receives the notify() or notifyAll() call. The method wait() is defined in the class Object and the method sleep() is defined in the class Thread.

Q8. Can you write a Java class that could be used both as an applet as well as an application?

A. Yes. Add a main() method to the applet.

Q9. What’s the difference between constructors and other methods?

A. Constructors must have the same name as the class and can not return a value. They are only called once while regular methods could be called many times.

Q10. Can you call one constructor from another if a class has multiple constructors
A. Yes. Use this() syntax.

Q11. Explain the usage of Java packages.

A. This is a way to organize files when a project consists of multiple modules. It also helps resolve naming conflicts when different packages have classes with the same names. Packages access level also allows you to protect data from being used by the non-authorized classes.

Q12. If a class is located in a package, what do you need to change in the OS environment to be able to use it?

A. You need to add a directory or a jar file that contains the package directories to the CLASSPATH environment variable. Let’s say a class Employee belongs to a package
com.xyz.hr; and is located in the file c:\dev\com\xyz\hr\Employee.java. In this case, you’d need to add c:\dev to the variable CLASSPATH. If this class contains the method main(), you could test it from a command prompt window as follows:
c:\>java com.xyz.hr.Employee

Q13. What’s the difference between J2SDK 1.5 and J2SDK 5.0?

A.There’s no difference, Sun Microsystems just re-branded this version.

Q14. What would you use to compare two String variables - the operator == or the method equals()?

A. I’d use the method equals() to compare the values of the Strings and the == to check if two variables point at the same instance of a String object.

Q15. Does it matter in what order catch statements for FileNotFoundException and IOExceptipon are written?

A. Yes, it does. The FileNoFoundException is inherited from the IOException. Exception’s subclasses have to be caught first.

Q16. Can an inner class declared inside of a method access local variables of this method?

A. It’s possible if these variables are final.

Q17. What can go wrong if you replace && with & in the following code:
String a=null; if (a!=null && a.length()>10) {…}

A. A single ampersand here would lead to a NullPointerException.

Q18. What’s the main difference between a Vector and an ArrayList

A. Java Vector class is internally synchronized and ArrayList is not.

Q19. When should the method invokeLater()be used?

A. This method is used to ensure that Swing components are updated through the event-dispatching thread.

Q20. How can a subclass call a method or a constructor defined in a superclass?

A. Use the following syntax: super.myMethod(); To call a constructor of the superclass, just write super(); in the first line of the subclass’s constructor.

For senior-level developers:
Q21. What’s the difference between a queue and a stack?

A. Stacks works by last-in-first-out rule (LIFO), while queues use the FIFO rule

Q22. You can create an abstract class that contains only abstract methods. On the other hand, you can create an interface that declares the same methods. So can you use abstract classes instead of interfaces?

A. Sometimes. But your class may be a descendant of another class and in this case the interface is your only option.

Q23. What comes to mind when you hear about a young generation in Java?

A. Garbage collection.

Q24. What comes to mind when someone mentions a shallow copy in Java?

A. Object cloning.

Q25. If you’re overriding the method equals() of an object, which other method you might also consider?

A. hashCode()

Q26. You are planning to do an indexed search in a list of objects. Which of the two Java collections should you use:ArrayList or LinkedList?

A. ArrayList

Q27. How would you make a copy of an entire Java object with its state?

A. Have this class implement Cloneable interface and call its method clone().

Q28. How can you minimize the need of garbage collection and make the memory use more effective?

A. Use object pooling and weak object references.

Q29. There are two classes: A and B. The class B need to inform a class A when some important event has happened. What Java technique would you use to implement it?

A. If these classes are threads I’d consider notify() or notifyAll(). For regular classes you can use the Observer interface.

Q30. What access level do you need to specify in the class declaration to ensure that only classes from the same directory can access it?

A. You do not need to specify any access level, and Java will use a default package access leve

JDBC Interview Questions

THIS IS FOR YOUR INFORMATION ONLY, ANY ERRORS/ DISCREPANCIES ARE REGRETTED. IN CASE OF DOUBTS PLEASE REFER THE BOOKS OR COMMENT HERE

Q) What are the steps involved in establishing a JDBC connection?
A)
This action involves two steps:

loading the JDBC driver and making the connection.


Q) How can you load the drivers?
A)
Loading the driver or drivers you want to use is very simple and involves just one line of code. If, for example, you want to use the JDBC-ODBC Bridge driver, the following code will load it:

Class.forName(”sun.jdbc.odbc.JdbcOdbcDriver”);

Your driver documentation will give you the class name to use. For instance, if the class name is jdbc.DriverXYZ, you would load the driver with the following line of code:

Class.forName(”jdbc.DriverXYZ”);


Q) What will Class.forName do while loading drivers?
A)
It is used to create an instance of a driver and register it with the DriverManager. When you have loaded a driver, it is available for making a connection with a DBMS.


Q) How can you make the connection?

A) To establish a connection you need to have the appropriate driver connect to the DBMS. The following line of code illustrates the general idea:

String url = “jdbc:odbc:Fred”;
Connection con = DriverManager.getConnection(url, “Fernanda”, “J8?);


Q) How can you create JDBC statements and what are they?

A) A Statement object is what sends your SQL statement to the DBMS. You simply create a Statement object and then execute it, supplying the appropriate execute method with the SQL statement you want to send. For a SELECT statement, the method to use is executeQuery. For statements that create or modify tables, themethod to use is executeUpdate. It takes an instance of an active connection to create a Statement object. In the following example, we use our Connection object con to create the Statement object

Statement stmt = con.createStatement();



Q) How can you retrieve data from the ResultSet?

A) JDBC returns results in a ResultSet object, so we need to declare an instance of the class ResultSet to hold our results. The following code demonstrates declaring the ResultSet object rs.

ResultSet rs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);

String s = rs.getString(”COF_NAME”);


The method getString is invoked on the ResultSet object rs, so getString() will retrieve (get) the value stored in the column COF_NAME in the current row of rs.


Q) What are the different types of Statements?
A)
Regular statement (use createStatement method), prepared statement (use prepareStatement method) and callable statement (use prepareCall)


Q) How can you use PreparedStatement?
A)
This special type of statement is derived from class Statement.If you need a Statement object to execute many times, it will normally make sense to use a PreparedStatement object instead. The advantage to this is that in most cases, this SQL statement will be sent to the DBMS right away, where it will be compiled. As a result, the PreparedStatement object contains not just an SQL statement, but an SQL statement that has been precompiled. This means that when the PreparedStatement is executed, the DBMS can just run the PreparedStatement’s SQL statement without having to compile it first.

PreparedStatement updateSales =con.prepareStatement(”UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?”);


Q) What does setAutoCommit do?

A) When a connection is created, it is in auto-commit mode. This means that each individual SQL statement is treated as a transaction and will be automatically committed right after it is executed. The way to allow two or more statements to be grouped into a transaction is to disable auto-commit mode:

con.setAutoCommit(false);

Once auto-commit mode is disabled, no SQL statements will be committed until you call the method commit explicitly.

con.setAutoCommit(false);
PreparedStatement updateSales =
con.prepareStatement( “UPDATE COFFEES SET SALES = ? WHERE COF_NAME LIKE ?”);
updateSales.setInt(1, 50); updateSales.setString(2, “Colombian”);
updateSales.executeUpdate();
PreparedStatement updateTotal =
con.prepareStatement(”UPDATE COFFEES SET TOTAL = TOTAL + ? WHERE COF_NAME LIKE ?”);
updateTotal.setInt(1, 50);
updateTotal.setString(2, “Colombian”);
updateTotal.executeUpdate();
con.commit();
con.setAutoCommit(true);


Q) How do you call a stored procedure from JDBC?


A)
The first step is to create a CallableStatement object. As with Statement an and PreparedStatement objects, this is done with an open Connection object. A CallableStatement object contains a call to a stored procedure.

CallableStatement cs = con.prepareCall(”{call SHOW_SUPPLIERS}”);
ResultSet rs = cs.executeQuery();


Q) How do I retrieve warnings?


A)
SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warnings do not stop the execution of an application, as exceptions do; they simply alert the user that something did not happen as planned. A warning can be reported on a Connection object, a Statement object (including PreparedStatement and CallableStatement objects), or a ResultSet object. Each of these classes has a getWarnings method, which you must invoke in order to see the first warning reported on the calling object:

SQLWarning warning = stmt.getWarnings();
if (warning != null)
{
System.out.println(”n—Warning—n”);
while (warning != null)
{
System.out.println(”Message: ” + warning.getMessage());
System.out.println(”SQLState: ” + warning.getSQLState());
System.out.print(”Vendor error code: “);
System.out.println(warning.getErrorCode());
System.out.println(”");
warning = warning.getNextWarning();
}
}


Q) How can you move the cursor in scrollable result sets?
A)
One of the new features in the JDBC 2.0 API is the ability to move a result set’s cursor backward as well as forward. There are also methods that let you move the cursor to a particular row and check the position of the cursor.


Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_READ_ONLY);
ResultSet srs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);


The first argument is one of three constants added to the ResultSet API to indicate the type of a ResultSet object: TYPE_FORWARD_ONLY, TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE. The second argument is one of two ResultSet constants for specifying whether a result set is read-only or updatable: CONCUR_READ_ONLY and CONCUR_UPDATABLE. The point to remember here is that if you specify a type, you must also specify whether it is read-only or updatable. Also, you must specify the type first, and because both parameters are of type int , the compiler will not complain if you switch the order.

Specifying the constant TYPE_FORWARD_ONLY creates a nonscrollable result set, that is, one in which the cursor moves only forward. If you do not specify any constants for the type and updatability of a ResultSet object, you will automatically get one that is TYPE_FORWARD_ONLY and CONCUR_READ_ONLY.


Q) What’s the difference between TYPE_SCROLL_INSENSITIVE , and TYPE_SCROLL_SENSITIVE?


A)
You will get a scrollable ResultSet object if you specify one of these ResultSet constants.The difference between the two has to do with whether a result set reflects changes that are made to it while it is open and whether certain methods can be called to detect these changes. Generally speaking, a result set that is TYPE_SCROLL_INSENSITIVE does not reflect changes made while it is still open and one that is TYPE_SCROLL_SENSITIVE does. All three types of result sets will make changes visible if they are closed and then reopened:

Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet srs = stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);
srs.afterLast();
while (srs.previous())
{
String name = srs.getString(”COF_NAME”);
float price = srs.getFloat(”PRICE”);
System.out.println(name + ” ” + price);
}


Q) How to Make Updates to Updatable Result Sets?

A) Another new feature in the JDBC 2.0 API is the ability to update rows in a result set using methods in the Java programming language rather than having to send an SQL command. But before you can take advantage of this capability, you need to create a ResultSet object that is updatable. In order to do this, you supply the
ResultSet constant CONCUR_UPDATABLE to the createStatement method.

Connection con =DriverManager.getConnection(”jdbc:mySubprotocol:mySubName”);
Statement stmt =con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);
ResultSet uprs =stmt.executeQuery(”SELECT COF_NAME, PRICE FROM COFFEES”);

Hibernate Interview Questions

THIS IS FOR YOUR INFORMATION ONLY, ANY ERRORS/ DISCREPANCIES ARE REGRETTED. IN CASE OF DOUBTS PLEASE REFER THE BOOKS OR COMMENT HERE

Q) What are the most common methods of Hibernate configuration?

A) The most common methods of Hibernate configuration are:
* Programmatic configuration
* XML configuration (hibernate.cfg.xml)


Q) What are the important tags of hibernate.cfg.xml?

A) An Action Class is an adapter between the contents of an incoming HTTP rest and the corresponding business logic that should be executed to process this rest.


Q) What are the Core interfaces are of Hibernate framework?

A) People who read this also read:
The five core interfaces are used in just about every Hibernate application. Using these interfaces, you can store and retrieve persistent objects and control transactions.
* Session interface
* SessionFactory interface
* Configuration interface
* Transaction interface
* Query and Criteria interfaces


Q) What role does the Session interface play in Hibernate?

A) The Session interface is the primary interface used by Hibernate applications. It is a single-threaded, short-lived object representing a conversation between the application and the persistent store. It allows you to create query objects to retrieve persistent objects.

Session session = sessionFactory.openSession();

Session interface role:

* Wraps a JDBC connection
* Factory for Transaction
* Holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier


Q) What role does the SessionFactory interface play in Hibernate?

A) The application obtains Session instances from a SessionFactory. There is typically a single SessionFactory for the whole application—created during application initialization. The SessionFactory caches generate SQL statements and other mapping metadata that Hibernate uses at runtime. It also holds cached data that has been read in one unit of work and may be reused in a future unit of work

SessionFactory sessionFactory = configuration.buildSessionFactory();


Q) What is the general flow of Hibernate communication with RDBMS?

A) The general flow of Hibernate communication with RDBMS is :
* Load the Hibernate configuration file and create configuration object. It will automatically load all hbm mapping files
* Create session factory from configuration object
* Get one session from this session factory
* Create HQL Query
* Execute query to get list containing Java objects


Q) What is Hibernate Query Language (HQL)?

A) Hibernate offers a query language that embodies a very powerful and flexible mechanism to query, store, update, and retrieve objects from a database. This language, the Hibernate query Language (HQL), is an object-oriented extension to SQL.


Q) How do you map Java Objects with Database tables?

* First we need to write Java domain objects (beans with setter and getter). The variables should be same as database columns.
* Write hbm.xml, where we map java class to table and database columns to Java class variables.


Q) What Does Hibernate Simplify?

A) Hibernate simplifies:

* Saving and retrieving your domain objects
* Making database column and table name changes
* Centralizing pre save and post retrieve logic
* Complex joins for retrieving related items
* Schema creation from object model


Q) What’s the difference between load() and get()?

A) load() vs. get()

load() :-
Only use the load() method if you are sure that the object exists.
load() method will throw an exception if the unique id is not found in the database. load() just returns a proxy by default and database won’t be hit until the proxy is first invoked.

get():-
If you are not sure that the object exists, then use one of the get() methods.
get() method will return null if the unique id is not found in the database.
get() will hit the database immediately.


Q) What is the difference between and merge and update ?

A)Use update() if you are sure that the session does not contain an already persistent instance with the same identifier, and merge() if you want to merge your modifications at any time without consideration of the state of the session.


Q) How do you define sequence generated primary key in hibernate?

A) Using tag.
Example:-

SEQUENCE_NAME



Q) Define cascade and inverse option in one-many mapping?

A) cascade - enable operations to cascade to child entities.
cascade=”all|none|save-update|delete|all-delete-orphan”
inverse - mark this collection as the “inverse” end of a bidirectional association.
inverse=”true|false”
Essentially “inverse” indicates which end of a relationship should be ignored, so when persisting a parent who has a collection of children, should you ask the parent for its list of children, or ask the children who the parents are?

Q) What does it mean to be inverse?

A) It informs hibernate to ignore that end of the relationship. If the one–to–many was marked as inverse, hibernate would create a child–>parent relationship (child.getParent). If the one–to–many was marked as non–inverse then a child–>parent relationship would be created.

Q) What do you mean by Named – SQL query?

A) Named SQL queries are defined in the mapping xml document and called wherever required.
example:

SELECT emp.EMP_ID AS {emp.empid},
emp.EMP_ADDRESS AS {emp.address},
emp.EMP_NAME AS {emp.name}
FROM Employee EMP WHERE emp.NAME LIKE :name

Invoke Named Query :
List people = session.getNamedQuery(”empdetails”)
.setString(”TomBrady”, name)
.setMaxResults(50)
.list();

Q) How do you invoke Stored Procedures?

A) { ? = call selectAllEmployees() }


Q) Explain Criteria API

A) Criteria is a simplified API for retrieving entities by composing Criterion objects. This is a very convenient approach for functionality like “search” screens where there is a variable number of conditions to be placed upon the result set.
Example :
List employees = session.createCriteria(Employee.class)
.add(Restrictions.like(”name”, “a%”) )
.add(Restrictions.like(”address”, “Boston”))
.addOrder(Order.asc(”name”) )
.list();


Q) Define HibernateTemplate?

A) org.springframework.orm.hibernate.HibernateTemplate is a helper class which provides different methods for querying/retrieving data from the database. It also converts checked HibernateExceptions into unchecked DataAccessExceptions.


Q) What are the benefits does HibernateTemplate provide?

A) The benefits of HibernateTemplate are :
* HibernateTemplate, a Spring Template class simplifies interactions with Hibernate Session.
* Common functions are simplified to single method calls.
* Sessions are automatically closed.
* Exceptions are automatically caught and converted to runtime exceptions.


Q) How do you switch between relational databases without code changes?

A) Using Hibernate SQL Dialects , we can switch databases. Hibernate will generate appropriate hql queries based on the dialect defined.


Q) If you want to see the Hibernate generated SQL statements on console, what should we do?

A) In Hibernate configuration file set as follows:
true


Q) What are derived properties?

A) The properties that are not mapped to a column, but calculated at runtime by evaluation of an expression are called derived properties. The expression can be defined using the formula attribute of the element.


Q) What is component mapping in Hibernate?

A)
* A component is an object saved as a value, not as a reference
* A component can be saved directly without needing to declare interfaces or identifier properties
* Required to define an empty constructor
* Shared references not supported


Q) What is the difference between sorted and ordered collection in hibernate?

A) sorted collection vs. order collection
sorted collection :-
A sorted collection is sorting a collection by utilizing the sorting features provided by the Java collections framework. The sorting occurs in the memory of JVM which running Hibernate, after the data being read from database using java comparator.
If your collection is not large, it will be more efficient way to sort it.

order collection :-
Order collection is sorting a collection by specifying the order-by clause for sorting this collection when retrieval.

If your collection is very large, it will be more efficient way to sort it .

Q) Different States of Hibernate Objects

* Transient Objects - Object instantiated using the new Operator aren't immediately persistent. Their state is Transient, which means they aren't associated with any database tables row and so their state is lost as soon as they're no longer referenced by any other object
* Persistant Objects- is an Entity instance with a database identity. Means a persistent and managed instance has a primary key value set as its database identifier. They are always associated with a persistence context
*Removed Objects- when object is scheduled for deletion
*Detached Objects - When object is no longer guaranteed to be synchronized with DB state. They are no longer attached to persistence context.

Wednesday, August 26, 2009

java.lang.OutOfMemoryError: Java heap space Solutions

Two JVM options are often used to tune JVM heap size: -Xmx for maximum heap size, and -Xms for initial heap size. Here are some common mistakes I have seen when using them:


Missing m, M, g or G at the end (they are case insensitive). For example,

java -Xmx128 BigAppjava.lang.OutOfMemoryError: Java heap space
The correct command should be: java -Xmx128m BigApp. To be precise, -Xmx128 is a valid setting for very small apps, like HelloWorld. But in real life, I guess you really mean -Xmx128m


Extra space in JVM options, or incorrectly use =. For example,

java -Xmx 128m BigAppInvalid maximum heap size: -XmxCould not create the Java virtual machine.java -Xmx=512m HelloWorldInvalid maximum heap size: -Xmx=512mCould not create the Java virtual machine.

The correct command should be java -Xmx128m BigApp, with no whitespace nor =. -X options are different than -Dkey=value system properties, where = is used.


Only setting -Xms JVM option and its value is greater than the default maximum heap size, which is 64m. The default minimum heap size seems to be 0. For example,

java -Xms128m BigAppError occurred during initialization of VMIncompatible initial and maximum heap sizes specified
The correct command should be java -Xms128m -Xmx128m BigApp. It's a good idea to set the minimum and maximum heap size to the same value. In any case, don't let the minimum heap size exceed the maximum heap size.


Heap size is larger than your computer's physical memory. For example,

java -Xmx2g BigAppError occurred during initialization of VMCould not reserve enough space for object heapCould not create the Java virtual machine.
The fix is to make it lower than the physical memory: java -Xmx1g BigApp


Incorrectly use mb as the unit, where m or M should be used instead.

java -Xms256mb -Xmx256mb BigAppInvalid initial heap size: -Xms256mbCould not create the Java virtual machine.
The heap size is larger than JVM thinks you would ever need. For example,

java -Xmx256g BigAppInvalid maximum heap size: -Xmx256gThe specified size exceeds the maximum representable size.Could not create the Java virtual machine.
The fix is to lower it to a reasonable value: java -Xmx256m BigApp

The value is not expressed in whole number. For example,

java -Xmx0.9g BigAppInvalid maximum heap size: -Xmx0.9gCould not create the Java virtual machine.
The correct command should be java -Xmx928m BigApp

********************************************************************

How to set java heap size in Tomcat?
Stop Tomcat server, set environment variable CATALINA_OPTS, and then restart Tomcat. Look at the file tomcat-install/bin/catalina.sh or catalina.bat for how this variable is used. For example,

set CATALINA_OPTS="-Xms512m -Xmx512m" (Windows)export CATALINA_OPTS="-Xms512m -Xmx512m" (ksh/bash)setenv CATALINA_OPTS "-Xms512m -Xmx512m" (tcsh/csh)
In catalina.bat or catallina.sh, you may have noticed CATALINA_OPTS, JAVA_OPTS, or both can be used to specify Tomcat JVM options. What is the difference between CATALINA_OPTS and JAVA_OPTS? The name CATALINA_OPTS is specific for Tomcat servlet container, whereas JAVA_OPTS may be used by other java applications (e.g., JBoss). Since environment variables are shared by all applications, we don't want Tomcat to inadvertently pick up the JVM options intended for other apps. I prefer to use CATALINA_OPTS.

How to set java heap size in JBoss?
Stop JBoss server, edit $JBOSS_HOME/bin/run.conf, and then restart JBoss server. You can change the line with JAVA_OPTS to something like:

JAVA_OPTS="-server -Xms128m -Xmx128m"

How to set java heap size in Eclipse?
You have 2 options:
1. Edit eclipse-home/eclipse.ini to be something like the following and restart Eclipse.

-vmargs-Xms64m-Xmx256m

2. Or, you can just run eclipse command with additional options at the very end. Anything after -vmargs will be treated as JVM options and passed directly to the JVM. JVM options specified in the command line this way will always override those in eclipse.ini. For example,

eclipse -vmargs -Xms64m -Xmx256m

How to set java heap size in NetBeans?
Exit NetBeans, edit the file netbeans-install/etc/netbeans.conf. For example,

netbeans_default_options="-J-Xms512m -J-Xmx512m -J-XX:PermSize=32m -J-XX:MaxPermSize=128m -J-Xverify:none

How to set java heap size in Apache Ant?
Set environment variable ANT_OPTS. Look at the file $ANT_HOME/bin/ant or %ANT_HOME%\bin\ant.bat, for how this variable is used by Ant runtime.

set ANT_OPTS="-Xms512m -Xmx512m" (Windows)export ANT_OPTS="-Xms512m -Xmx512m" (ksh/bash)setenv ANT_OPTS "-Xms512m -Xmx512m" (tcsh/csh)


How to increase heap size :
step 1.
open D:\jakarta-tomcat-5.0.28\bin\catalina.bat
step 2.
add -Xmx512M before %JAVA_OPTS%

Where you find %JAVA_OPTS% .. before this just put -Xmx512M

like this
%_EXECJAVA% -Xmx512M %JAVA_OPTS%

or

these are the lines i have changed in my machine
this is for 512 MB Setting.


All the line are there already ..just replace
-------------------------------------------------
rem Execute Java with the applicable properties

if not "%JPDA%" == "" goto doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurity
%_EXECJAVA% -Xmx512M %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doSecurity
%_EXECJAVA% -Xmx512M %JAVA_OPTS% %CATALINA_OPTS% %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doJpda
if not "%SECURITY_POLICY_FILE%" == "" goto doSecurityJpda
%_EXECJAVA% -Xmx512M %JAVA_OPTS% %CATALINA_OPTS% -Xdebug -Xrunjdwp:transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=n %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end
:doSecurityJpda
%_EXECJAVA% -Xmx512M %JAVA_OPTS% %CATALINA_OPTS% -Xrunjdwp:transport=%JPDA_TRANSPORT%,address=%JPDA_ADDRESS%,server=y,suspend=n %DEBUG_OPTS% -Djava.endorsed.dirs="%JAVA_ENDORSED_DIRS%" -classpath "%CLASSPATH%" -Djava.security.manager -Djava.security.policy=="%SECURITY_POLICY_FILE%" -Dcatalina.base="%CATALINA_BASE%" -Dcatalina.home="%CATALINA_HOME%" -Djava.io.tmpdir="%CATALINA_TMPDIR%" %MAINCLASS% %CMD_LINE_ARGS% %ACTION%
goto end

:end

Saturday, August 22, 2009

Google Maps Creation using Wizards


Google Maps can be created and embedded into your blog / website very easily! There are two very easy ways of creating maps, with little or no knowledge of Google Maps.

Way-1


You can check out the following link You can create the map by filling the following details. You can even embedded a search control for easier navigation.

Give details like Area in Pixels, You can Zoom level to City level or Street Level and fill the name of the area where you want your map to be centered.



Way-2
You can visit maps.google.com ! Search for your favourite place and you can find links like Link and Send! When you click on Link, you will find the above menu (in the image) with following details


Paste link in email or IM - Copy the link and paste it in your status message or email link !

Paste HTML to embed in website - If you own a website or blog, you can copy this code and paste wherever you want !!

You can even take Printout and compose the mail then and there itself by clicking on Send.

My Technology Blogs ...

Google Maps is one of the most popular APIs released by Google. Technically it is called as Geo Spatial Viewing Tool. You can use the API and embed these maps into your website / blog etc., With the huge success of this API, other players like Microsoft, Amazon followed. It even made AJAX popular !!

Google Maps is the first public API, I have worked with. The API is every easy learn - APIs are meant to be that way ;). FYI Google Maps is free to use.

What is Google Maps?
Google Maps provides a highly responsive, intuitive mapping interface with embedded, detailed street and aerial imagery data. In addition, map controls can be embedded in the product to give users full control over map navigation and the display of street and imagery data.

How to use Google Maps ?
We need to register with google here you will get a API Key, which you need to use in every Map you make.



A Typical Map looks like this. We have a Marker, Info Window, Zoom / unZoom & Direction control on the map.There are lots of possiblities with this API. Many use this API as a part of his/her Mashup.

Next part : We will look on how to create a map and add Markers to it, with map.



Hello friends, I will be starting a new blog !

Ganex Improves .. Headline Animator