Logo

Navigation
  • Home
  • Services
    • ERP Solutions
    • Implementation Solutions
    • Support and Maintenance Solutions
    • Custom Solutions
    • Upgrade Solutions
    • Training and Mentoring
    • Web Solutions
    • Production Support
    • Architecture Designing
    • Independent Validation and Testing Services
    • Infrastructure Management
  • Expertise
    • Microsoft Development Expertise
    • Mobile Development
    • SQL Server Database and BI
    • SAP BI, SAP Hana, SAP BO
    • Oracle and BI
    • Oracle RAC
  • Technical Training
    • Learn Data Management
      • Business Intelligence
      • Data Mining
      • Data Modeling
      • Data Warehousing
      • Disaster Recovery
    • Learn Concepts
      • Application Development
      • Client Server
      • Cloud Computing Tutorials
      • Cluster Computing
      • CRM Tutorial
      • EDI Tutorials
      • ERP Tutorials
      • NLP
      • OOPS
      • Concepts
      • SOA Tutorial
      • Supply Chain
      • Technology Trends
      • UML
      • Virtualization
      • Web 2.0
    • Learn Java
      • JavaScript Tutorial
      • JSP Tutorials
      • J2EE
    • Learn Microsoft
      • MSAS
      • ASP.NET
      • ASP.NET 2.0
      • C Sharp
      • MS Project Training
      • Silverlight
      • SQL Server 2005
      • VB.NET 2005
    • Learn Networking
      • Networking
      • Wireless
    • Learn Oracle
      • Oracle 10g
      • PL/SQL
      • Oracle 11g Tutorials
      • Oracle 9i
      • Oracle Apps
    • Learn Programming
      • Ajax Tutorial
      • C Language
      • C++ Tutorials
      • CSS Tutorial
      • CSS3 Tutorial
      • JavaScript Tutorial
      • jQuery Tutorial
      • MainFrame
      • PHP Tutorial
      • VBScript Tutorial
      • XML Tutorial
    • Learn Software Testing
      • Software Testing Types
      • SQA
      • Testing
  • Career Training
    • Career Improvement
      • Career Articles
      • Certification Articles
      • Conflict Management
      • Core Skills
      • Decision Making
      • Entrepreneurship
      • Goal Setting
      • Life Skills
      • Performance Development
      • Personal Excellence
      • Personality Development
      • Problem Solving
      • Relationship Management
      • Self Confidence
      • Self Supervision
      • Social Networking
      • Strategic Planning
      • Time Management
    • Education Help
      • Career Tracks
      • Essay Writing
      • Internship Tips
      • Online Education
      • Scholarships
      • Student Loans
    • Managerial Skills
      • Business Communication
      • Business Networking
      • Facilitator Skills
      • Managing Change
      • Marketing Management
      • Meeting Management
      • Process Management
      • Project Management
      • Project Management Life Cycle
      • Project Management Process
      • Project Risk Management
      • Relationship Management
      • Task Management
      • Team Building
      • Virtual Team Management
    • Essential Life Skills
      • Anger Management
      • Anxiety Management
      • Attitude Development
      • Coaching and Mentoring
      • Emotional Intelligence
      • Stress Management
      • Positive Thinking
    • Communication Skills
      • Conversation Skills
      • Cross Culture Competence
      • English Vocabulary
      • Listening Skills
      • Public Speaking Skills
      • Questioning Skills
    • Soft Skills
      • Assertive Skills
      • Influence Skills
      • Leadership Skills
      • Memory Skills
      • People Skills
      • Presentation Skills
    • Finding a Job
      • Etiquette Tips
      • Group Discussions
      • HR Interviews
      • Interview Notes
      • Job Search Tips
      • Resume Tips
      • Sample Resumes
 

Why It is Important To Focus On Java Exceptions For Your Programs

By Exforsys | on July 27, 2006 |
J2EE

Why It is Important To Focus On Java Exceptions For Your Programs

If you work with Java, it is important to understand exceptions. Exceptions are uncanny situations that can destroy the normal behavior of a program.

They are common in the Java programming language, and it is something you will have to deal with if you want to write good applications. Exceptions are defined as unchecked or checked, and they are also defined as being objects. Exceptions which are checked will stretch java.lang.Exception, and they will need to be controlled with a try/catch block. It is also possible to control them with a throws clause.

An exception which is unchecked will stretch java.lang.RuntimeException. They will not be reviewed by a compiler. While the checked exceptions can be useful, they may have a negative side effect, which is known as the "try/catch/do nothing" code. You can see an example of this here:

try
{
// Some code that generates checked exceptions
}
catch(Exception e)
{
// do nothing
}

Many documents have revealed information about the problems that this code causes. It is best for programmers to avoid it if possible. There are a large number of Java programs which contain this code. One reason for this is because many programmers don’t know how to deal with exceptions. Many Java APIs will create multiple exceptions, and it is not always easy to handle them. The best way to deal with this situation is to give the task of dealing with exceptions to other portions of the program. You can also get rid of exceptions that you don’t want to deal with. However, this may not always solve the problem. There is a simple method you can use to deal with exceptions.

Being able to properly handle exceptions will allow you to work on the parts of your program which are important. If you are building a Java program that will connect to a database, you will probably use the Java database connectivity API. You will always want to get a database connection element first. The code that you will need to use in order to obtain a connection object will be added within a single method. Below is an example of this code:

Listing 1: How a Database Connection Is Usually Retrieved

public static Connection getConnection() throws ClassNotFoundException, SQLException
{
Connection connection = null;

// Load the JDBC driver for your database
String driverName = "oracle.jdbc.driver.OracleDriver";
Class.forName(driverName);

// Create a connection to the database, usually those values are retrieved from a properties file
String serverName = "127.0.0.1";
String portNumber = "1521";
String sid = "mydatabase";
String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber + ":" + sid;
String username = "username";
String password = "password";

connection = DriverManager.getConnection(url, username, password);

return connection;
}

The primary problem with using this method is that you will have to deal with java.lang.ClassNotFoundException, along with java.sql.SQLException. There is little you can do with these exceptions other than throw them. Both of these exceptions will keep a database connection for being reclaimed. Using a newer version of getConnection can allow you to avod having to deal with these exceptions. At the same time, a runtime behavior may occur, and this is something you probably don’t want. The exceptions in the above example should not be present once you’ve completed your application. If these exceptions are present while you design the application, it will not be able to correct them.

If it causes problems with a network, you will need the help of an adminstrator. If it is any other issue, you will need help from a programmer who is skilled with Java. In this situation, trying to write code to handle the exceptions is generally useless.

« « Understanding Your Memory
The Importance of Task Allocation » »

Author Description

Avatar

Editorial Team at Exforsys is a team of IT Consulting and Training team led by Chandra Vennapoosa.

Free Training

RSSSubscribe 394 Followers
  • Popular
  • Recent
  • What You Can Do To Deal With Java’s Memory Retention Problems

    July 22, 2006 - 0 Comment
  • New Features In Java 5.0 – From Managers Point of View

    November 26, 2005 - 0 Comment
  • How To Create High Quality Tables With JavaScript

    July 5, 2006 - 0 Comment
  • What You Should Know About Java XML

    July 25, 2006 - 0 Comment
  • New Features in Java 5 – From Programmers Point of View

    November 26, 2005 - 0 Comment
  • Determine the Effectiveness of your Java Software

    July 5, 2006 - 0 Comment
  • Important Features of Java – Multithreading, AWT

    July 26, 2006 - 0 Comment
  • Performance Tuning of Java Applications

    December 2, 2005 - 0 Comment
  • How To Develop RFID Applications In Java

    July 8, 2006 - 0 Comment
  • J2EE Overview

    December 6, 2005 - 0 Comment
  • Important Features of Java – Multithreading, AWT

    July 26, 2006 - 0 Comment
  • What You Should Know About Java XML

    July 25, 2006 - 0 Comment
  • What You Can Do To Deal With Java’s Memory Retention Problems

    July 22, 2006 - 0 Comment
  • Java Overview

    July 17, 2006 - 0 Comment
  • How To Use Java DB as Your Client Mobile Database

    July 14, 2006 - 0 Comment
  • How To Run J2ME Programs on Palm Devices

    July 14, 2006 - 0 Comment
  • Java Virtual Machine

    July 13, 2006 - 0 Comment
  • Quickly Develop Java Programs With Tapestry

    July 12, 2006 - 0 Comment
  • A Java TOC2 Class Which Can Contact Aim

    July 12, 2006 - 0 Comment
  • How To Perform Class Loading With Java

    July 8, 2006 - 0 Comment

Exforsys e-Newsletter

ebook
 

Related Articles

  • Important Features of Java – Multithreading, AWT
  • What You Should Know About Java XML
  • What You Can Do To Deal With Java’s Memory Retention Problems
  • Java Overview
  • How To Use Java DB as Your Client Mobile Database

Latest Articles

  • Project Management Techniques
  • Product Development Best Practices
  • Importance of Quality Data Management
  • How to Maximize Quality Assurance
  • Utilizing Effective Quality Assurance Strategies
  • Sitemap
  • Privacy Policy
  • DMCA
  • Trademark Information
  • Contact Us
© 2023. All Rights Reserved.IT Training and Consulting
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.AcceptReject Read More
Privacy & Cookies Policy

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT