User defined Exceptions are the separate Exception classes defined by the user for specific purposed. An user defined can created by simply sub-classing it to the Exception class. This allows custom exceptions to be generated (using throw) and caught in the same way as normal exceptions.
Example:
class myCustomException extends Exception {
// The class simply has to exist to be an exception
}
Archive for February, 2009
Question: Explain the user defined Exceptions?
Question: What is transient variable?
Transient variable can’t be serialize. For example if a variable is declared as transient in a Serializable class and the class is written to an ObjectStream, the value of the variable can’t be written to the stream instead when the class is retrieved from the ObjectStream the value of the variable becomes null.
how to create excel page using jsp
use third party API which is Apache POI. Apache POI is open source java library to access Microsoft file formats. This API is available through apache website. You can download poi-bin-3.1-beta2-20080526.zip(POI.jar) form Apache Jakarta Project.
<%@ page import="java.io.InputStream" %>
<%@ page import="org.apache.poi.hssf.usermodel.HSSFWorkbook"%>
<%@ page import="java.io.*" %>
<%
try {
HSSFWorkbook wb = new HSSFWorkbook();
FileOutputStream fileOut = new FileOutputStream
("C:\\excel\\firstExcel.xls");
wb.write(fileOut);
fileOut.close();
} catch ( Exception ex ) {
}
%>
Basics of a Spreadsheet
So let’s get started digging into what makes a spreadsheet work. Spreadsheets are made up of
- columns
- rows
- and their intersections are called cells
In each cell there may be the following types of data
- text (labels)
- number data (constants)
- formulas (mathematical equations that do all the work)
Spreadsheet
A spreadsheet is the computer equivalent of a paper ledger sheet. It consists of a grid made from columns and rows. It is an environment that can make number manipulation easy and somewhat painless.
The math that goes on behind the scenes on the paper ledger can be overwhelming. If you change the loan amount, you will have to start the math all over again (from scratch). But lets take a closer look at the computer version.
Reserved Keyword in Java
abstract assert boolean break byte case catch char class
const continue default do double else enum extends final
finally float for goto if implements import instanceof
int interface long native new package private protected public
return short static strictfp super switch synchronized this throw
throws transient try void volatile while
Java Mail
import java.util.Properties;
import javax.mail.Address;
import javax.mail.Message;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class MailClass {
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.put(“mail.host”, “mail.dwp.com”);
Session mailConnection = Session.getInstance(props, null);
Message msg = new MimeMessage(mailConnection);
Address a = new InternetAddress(“vishal2000@a.com”, “Vishal Kumar”);
Address b = new InternetAddress(“kamal_ss@java2s.com”,”kamal sharn”);
msg.setContent(“Mail contect”, “text/plain”);
msg.setFrom(a);
msg.setRecipient(Message.RecipientType.TO, b);
msg.setSubject(“subject”);
Transport.send(msg);
}
}
Making Your Objects Comparable and Sortable
You can make objects comparable by implementing the java.lang.Comparable and java.util.Comparator interfaces.
Classes such as java.lang.String, java.util.Date, and primitive wrapper classes all implement java.lang.Comparable.
int[] intArray = new int[] { 5, 4, 3, 2, 1 };
Arrays.sort(intArray);
for (int i : intArray) {
System.out.println(i);
}
get class from an object
String s = “”;
Class c = s.getClass ();
System.out.println (c.getName ());
c = new ClassInfoDemo1 ().getClass ();
System.out.println (c.getName ());
Create new instance
try {
String pc = String.class.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}