Java Developers Tool Apache Ant on Windows

Apache Ant on windows,You want install Ant's Zip file from bellow given location.
After that you want to unzip and configure the ANT_HOME on Windows.

1.JAVA_HOME
First make sure JDK is installed in your system and JAVA_HOME is configure as windows environment variable.




2.Download Apache Ant
Downloaded the Apache ant from official website example : Apache-ant-1.9 ,unzip it to the folder you want to store Apache Ant.



3.Configure ANT_HOME
Add the ANT_HOME as in the Windows environment variable ,and point it to your ant folder and also added Path variable,append %ANT_HOME%\bin at the end ,becuase you can run the ant's comment everywhere on console.

Example :PATH=%PATH%;%JAVA_HOME%\bin;%ANT_HOME%\bin 

4.Test The Ant Command
Once you have done configuration ,Open a new command prompt to and run ant and see something like this.


That means Ant is installed properly and is looking for build.xml file

Java Developers Tool Apache Log4j

The Log4j API provide the interface that applications should code to and provide the adapter components required for implementers to create a logging implementation.
In our project Log4j will be usually configured using a properties file or xml file externally, without modifying the source code we can easily control log statement.In log4j three main components you needed to configure to obtain the result logger, appender and layout.

- Logger object is the used to log message.
- Appender is the specifies the ouput source like as console or file location.
- Layout is the specify the format in which the log message should be logged


let's see the log4j.properties file in bellow −

# Define the root logger with appender file
log = /usr/home/log4j 
log4j.rootLogger = DEBUG,FILE
# Define the file appender
log4j.appender.FILE=org.apache.log4j.FileAppender
log4j.appender.FILE.File=${log}/log.out
# Define the layout for file appender
log4j.appender.FILE.layout=org.apache.log4j.PatternLayout

log4j.appender.FILE.layout.conversionPattern=%m%n

See the sample example with Java calss is using the log4j library 

import org.apache.log4j.Logger;
public class log4jExample{
   /* Class Name to be printed on */
   static Logger log = Logger.getLogger(log4jExample.class.getName());
   public static void main(String[] args){
      log.debug("Hello this is a debug message");
      log.info("Hello this is an info message");
   }



when you will compile and run above java program. 
You would get the following result inside 

path : /usr/home/log4j/log.out file −

Hello this is a debug message
Hello this is an info message

Java Interview Question Part - 4

Q1. What is an exception?
Ans : An exception is an abnormal event that come during the program execution and disrupts the normal flow of the program's instruction.

Q2. What is purpose of the throw and throws keyword in exception?
Ans : throws keyword is used to specify that a method may raise an exception during it's execution.It enforces explicity excepiton
exception handling when we call this method.

public void getLone() throws Exception{
}
throw keyword used in normal condition ,when object to interrupt the normal flow of the program.throw keyword is mostly commanly
used when a program fail to stisfy a given condition.

if(card.isFinalAmout()){
throw new FinalAmoutException("The Card amount is not complited");
}

Q3. What is difference between a checked and an unchecked exception?
Ans: Checked exception must be handled within a try-catch block or declared in a throws clause but uncheck exception is not required to handle not be declared.
All exception are checked exceptions, except those indicated by Error ,RuntimeException and their subclasses.
checked and unchecked exception also know as compile time and run time exception.

Q4.How to create custom exception?
Ans: Your class should extend class Exception or any of it's subclasses to create out custom  exception. Tis custom exception class can have it's own variable and methods
that we can use to pass error code or other exception related information to the exception handler.
let's see in bellow example:

import java.io.Exception;
public class AccountBalance extends IOException{
private static final long serialVersionUID = 4664459809499611218L;
private String errorCode="UnKnownException";
public AccountBalance (String message ,String errorCode){
   Super(message);
   this.errorCode = errorCode;
}
public String getErrorCode(){
return this.errorCode;
}
}

Q5. What is OutOfMemoryError in Java ?
Ans: In Java OutOfMemoryError is subclass of java.lang.vertualMachineError and it's throws by JVM, when it run out heap memory.
We can fix this error by providing more memory to run the java application.
Exp:

$>java <> -Xms1024m -Xmx1024m -XX:PermSize=64M -XX:MaxPermSize=256m

Technology Configurations