Saturday, September 27, 2008

What is a Bank and How it works

Source : HowStuffWorks

The funny thing about how a bank works is that it functions because of our trust. We give a bank our money to keep it safe for us, and then the bank turns around and gives it to someone else in order to make money for itself. Banks can legally extend considerably more credit than they have cash. Still, most of us have total trust in the bank's ability to protect our money and give it to us when we ask for it.

Banks are critical to our economy. The primary function of banks is to put their account holders' money to use by lending it out to others who can then use it to buy homes, businesses, send kids to college...

When you deposit your money in the bank, your money goes into a big pool of money along with everyone else's, and your account is credited with the amount of your deposit. When you write checks or make withdrawals, that amount is deducted from your account balance. Interest you earn on your balance is also added to your account.

Banks create money in the economy by making loans. The amount of money that banks can lend is directly affected by the reserve requirement set by the Federal Reserve. The reserve requirement is currently 3 percent to 10 percent of a bank's total deposits

When a bank gets a deposit of $100, assuming a reserve requirement of 10 percent, the bank can then lend out $90. That $90 goes back into the economy, purchasing goods or services, and usually ends up deposited in another bank. That bank can then lend out $81 of that $90 deposit, and that $81 goes into the economy to purchase goods or services and ultimately is deposited into another bank that proceeds to lend out a percentage of it.

In this way, money grows and flows throughout the community in a much greater amount than physically exists. That $100 makes a much larger ripple in the economy than you may realize!

What are Mortgage Backed Securities:

Mortgage-backed securities resemble bonds, instruments issued by governments and corporations that promise to pay a fixed amount of interest for a defined period of time. Mortgage-backed securities are created when a company such as Bear Stearns buys a bunch of mortgages from a primary lender—that is, from the company you actually got your mortgage from—and then uses your monthly payments, and those of thousands of others, as the revenue stream to pay investors who have bought chunks of the offering. They allow lenders to sell the mortgages they make, thus replenishing their coffers and allowing them to lend again. For their part, buyers of mortgage-backed securities take security in the knowledge that the value of the bond doesn't just rest on the creditworthiness of one borrower, but on the collective creditworthiness of a group of borrowers.

Saturday, September 20, 2008

Java Mail API examples

Mail w/o attachments
public class SendJavaMail
{
public static void main(String[] args)
{
try
{
// Create a properties file containing the host address of
// your SMTP server
Properties mailProps = new Properties();
mailProps.put("mail.smtp.host", "smtp.myispserver.net");
// Create a session with the Java Mail API
Session mailSession =
Session.getDefaultInstance(mailProps);
// Create a transport object for sending mail
Transport transport = mailSession.getTransport("smtp");
// Create a new mail message
MimeMessage message = new MimeMessage(mailSession);
// Set the From and the Recipient
message.setFrom(new InternetAddress(
"senorcoffeebean@wutka.com"));
message.setRecipient(Message.RecipientType.TO,
new InternetAddress("mark@wutka.com"));
// Set the subject
message.setSubject("Hello from Java Mail!");
// Set the message text
message.setText("Hello!\n"+
"It is I, Senor Coffee Bean! I bring you greetings \n"+
"from the Java Mail API!. \n"+
" Senor Coffee Bean, Esp.\n");
// Save all the changes you have made to the message
message.saveChanges();
// Send the message
transport.send(message);
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
}
public class SendJavaMail
{
public static void main(String[] args)
{
try
{
// Create a properties file containing the host address of
// your SMTP server
Properties mailProps = new Properties();
mailProps.put("mail.smtp.host", "smtp.myispserver.net");
// Create a session with the Java Mail API
Session mailSession =
Session.getDefaultInstance(mailProps);
// Create a transport object for sending mail
Transport transport = mailSession.getTransport("smtp");
// Create a new mail message
MimeMessage message = new MimeMessage(mailSession);
// Set the From and the Recipient
message.setFrom(new InternetAddress(
"senorcoffeebean@wutka.com"));
message.setRecipient(Message.RecipientType.TO,
new InternetAddress("mark@wutka.com"));
// Set the subject
message.setSubject("Hello from Java Mail!");
// Set the message text
message.setText("Hello!\n"+
"It is I, Senor Coffee Bean! I bring you greetings \n"+
"from the Java Mail API!. \n"+
" Senor Coffee Bean, Esp.\n");
// Save all the changes you have made to the message
message.saveChanges();
// Send the message
transport.send(message);
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
}


Mail w/ attachments and text:
import java.io.*;
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
/** Uses the Java Mail API to send a message via SMTP. */
public class SendAttachment
{
public static void main(String[] args)
{
try
{
// Create a properties file containing the host address of
// your SMTP server
Properties mailProps = new Properties();
mailProps.put("mail.smtp.host", "smtp.myispserver.net");
// Create a session with the Java Mail API
Session mailSession =
Session.getDefaultInstance(mailProps);
// Create a transport object for sending mail
Transport transport = mailSession.getTransport("smtp");
// Create a new mail message
MimeMessage message = new MimeMessage(mailSession);
// Set the From and the Recipient
message.setFrom(new InternetAddress(
"senorcoffeebean@wutka.com"));
message.setRecipient(Message.RecipientType.TO,
new InternetAddress("mark@wutka.com"));
// Set the subject
message.setSubject("Hello from Java Mail!");
// Create the multipart object for doing attachments
MimeMultipart multi = new MimeMultipart();
// Create the message part for the main message text
BodyPart textBodyPart = new MimeBodyPart();
// Set the message text
textBodyPart.setText("Hello!\n"+
"It is I, Senor Coffee Bean! I bring you an attachment \n"+
"from the Java Mail API!. \n"+
" Senor Coffee Bean, Esp.\n");
// Add the body part to the multipart object
multi.addBodyPart(textBodyPart);
// Create an input stream to read the attachment data
FileInputStream in = new FileInputStream("SendAttachment.java");


// Create the body part for the attachment
BodyPart fileBodyPart = new MimeBodyPart(in);
// Give the attachment a filename (the name that appears when someone
// reads the message--it doesn't have to be the same as the file
// you're reading).
fileBodyPart.setFileName("SendAttachment.java");
// Add the attachment to the multipart object
multi.addBodyPart(fileBodyPart);
// The multipart object is the content for the email message
message.setContent(multi);
// Save all the changes you have made to the message
message.saveChanges();
// Send the message
transport.send(message);
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
}

Tuesday, September 9, 2008

Thoughtfully static

Static = One instance / jvm. So make sure you initialize your static variables in the factory in a particular order.
When you create a factory class, and make the objects as static and final, it is absolutely necessary that you initialize dependencies prior to the actual class.
Ex: my tfpService depends on the tfpDao so make sure you initialize the tfp dao fist and then the actual service. Else you get null ptr when you refernce tfpDao in tfpService.
private static final TFPDao tfpDao=new TFPDaoImpl();
private static final TFPParser tfpParser=new TFPParserImpl();
private static final TFPService tfpService=new TFPServiceImpl();