Monday, August 29, 2011

What is Log4J and Where it is Used..?


Log4J is a Open Source framework/debugging
Log4J is from ASF(Apache Software Foundation)
Log4J is Written in Java

No Project can Exist without Log4J (in Java)
Every Project in Java Most be Used Log4J

What is Logging :

 Logging is the act of recording the events occurred in the execution of application

Sunday, August 28, 2011

Quick Shortcuts for My Eclipse


  • control-F4 - close current editor window
  • control-shift-F4 - close all editor windows
  • control-F6 - switch between editor windows
  • control-F7 - switch between views
  • control-F8 - switch between perspectives
  • control-space - code completion
  • control-1 - quick fix
  • F3 - (or control-click) - jumps to the class/method at your cursor
  • F4 - shows class hierarchy
  • F11 - launch the last debug configuration (in debug mode)
  • Alt-r, followed by t - stop the debug configuration
  • F12 - give focus to the editor window
  • Highlight text and control-/ - comment/uncomment code
  • control-j - incremental find
  • control-m - expand/contract current editor window
  • control-shift-f - format code
  • control-shift-g - searches for references to selected class/method/etc
  • control-shift-o - organize imports (automatically fix your class imports)
  • control-shift-r - open resource - great search utility
  • control-shift-t - open type (Java class/interface finder)
  • Standard Windows shortcuts also apply (home, end, control-home, control-end, control-leftArrow, control-rightArrow, all these in combination with shift, etc)

Eclipse Tutorials

http://www.avajava.com


Eclipse Tutorials with Real time Example for best Practicing 

 

Wednesday, March 30, 2011

A Sample Program on User-define Exception


class MyException extends Exception{
}
class voting{
public static void isEligible(int age) throws MyException{
if(age<19)
throw new MyException();
else
System.out.println("can caste vote");
}
}
class MyTest{
public static void main(String args[]){
try{
int age=Integer.parseInt(args[0]);
voting.isEligible(age);
}
catch(MyException e){
e.printStackTrace();
System.out.println("Invalid Age can't vote");
}
catch(NumberFormatException e){
e.printStackTrace();
System.out.println("please supply age must be digits");
}
catch(Exception e){
e.getMessage();
}
}
}

Without Handle ArithmeticException in a Sample Program


class WithoutHandle{
public static void main(String args[])
{
System.out.println("started");
int n,d,q=1;
n=Integer.parseInt(args[0]);
d=Integer.parseInt(args[1]);
q=n/d;
System.out.println("the result");
System.out.println("complete");
}
}

How to Handle ArithmeticException throw command Line Argument


class WithHandle{
public static void main(String args[])
{
System.out.println("started");
int n,d,q=1;
n=Integer.parseInt(args[0]);
d=Integer.parseInt(args[1]);
try{
q=n/d;
System.out.println("the result value is"+q);
}
catch(ArithmeticException e){
System.out.println("Divisible fails...2nd value shouldn't be 0");
}
}
}

Saturday, March 19, 2011

How to Use Setters & Getters Methods in Java



public class Student {
private String studentNo;
private String studentName;
private float studentFee;

public float getStudentFee() {
return studentFee;
}
public void setStudentFee(float studentFee) {
this.studentFee = studentFee;
}
public String getStudentNo() {
return studentNo;
}
public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}

}

Data Represent in the form User-defined Object (Bean)



public class Student {
private String studentNo;
private String studentName;
private float studentFee;

public float getStudentFee() {
return studentFee;
}
public void setStudentFee(float studentFee) {
this.studentFee = studentFee;
}
public String getStudentNo() {
return studentNo;
}
public void setStudentNo(String studentNo) {
this.studentNo = studentNo;
}
public String getStudentName() {
return studentName;
}
public void setStudentName(String studentName) {
this.studentName = studentName;
}

}

Monday, February 28, 2011

Print the Object Adress with Hashcode and returns Null


class Student{
int rollno;
int marks;
Student(){
rollno=1001;
marks=75;
}
public String toString(){
System.out.println(getClass().getName()+"@"+Integer.toString(hashCode()));
return null;
}
}
public class TestingExample {

/**
* @param args
*/
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Student s=new Student();
System.out.println(s);
}
}