Friday 27 June 2014

Exception Handling in JAVA

Exception Handling in JAVA
An exception is a problem that arises during the execution of a program. An exception can occur for many different reasons, including the following:
  • A user has entered invalid data.
  • A file that needs to be opened cannot be found.
  • A network connection has been lost in the middle of communications or the JVM has run out of memory.
Some of these exceptions are caused by user error, others by programmer error, and others by physical resources that have failed in some manner.
To understand how exception handling works in Java, you need to understand the three categories of exceptions:
  • Checked exceptions: A checked exception is an exception that is typically a user error or a problem that cannot be foreseen by the programmer. For example, if a file is to be opened, but the file cannot be found, an exception occurs. These exceptions cannot simply be ignored at the time of compilation.
  • Runtime exceptions: A runtime exception is an exception that occurs that probably could have been avoided by the programmer. As opposed to checked exceptions, runtime exceptions are ignored at the time of compilation.
  • Errors: These are not exceptions at all, but problems that arise beyond the control of the user or the programmer. Errors are typically ignored in your code because you can rarely do anything about an error. For example, if a stack overflow occurs, an error will arise. They are also ignored at the time of compilation.

Exception Hierarchy:

All exception classes are subtypes of the java.lang.Exception class. The exception class is a subclass of the Throwable class. Other than the exception class there is another subclass called Error which is derived from the Throwable class.
Errors are not normally trapped form the Java programs. These conditions normally happen in case of severe failures, which are not handled by the java programs. Errors are generated to indicate errors generated by the runtime environment. Example : JVM is out of Memory. Normally programs cannot recover from errors.
The Exception class has two main subclasses: IOException class and RuntimeException Class.
Java Exceptions
Here is a list of most common checked and unchecked Java's Built-in Exceptions.
Following is the list of important medthods available in the Throwable class.
SNMethods with Description
1public String getMessage()
Returns a detailed message about the exception that has occurred. This message is initialized in the Throwable constructor.
2public Throwable getCause()
Returns the cause of the exception as represented by a Throwable object.
3public String toString()
Returns the name of the class concatenated with the result of getMessage()
4public void printStackTrace()
Prints the result of toString() along with the stack trace to System.err, the error output stream.
5public StackTraceElement [] getStackTrace()
Returns an array containing each element on the stack trace. The element at index 0 represents the top of the call stack, and the last element in the array represents the method at the bottom of the call stack.
6public Throwable fillInStackTrace()
Fills the stack trace of this Throwable object with the current stack trace, adding to any previous information in the stack trace.

Catching Exceptions:

A method catches an exception using a combination of the try and catch keywords. A try/catch block is placed around the code that might generate an exception. Code within a try/catch block is referred to as protected code, and the syntax for using try/catch looks like the following:
try
{
   //Protected code
}catch(ExceptionName e1)
{
   //Catch block
}
A catch statement involves declaring the type of exception you are trying to catch. If an exception occurs in protected code, the catch block (or blocks) that follows the try is checked. If the type of exception that occurred is listed in a catch block, the exception is passed to the catch block much as an argument is passed into a method parameter.

Example:

The following is an array is declared with 2 elements. Then the code tries to access the 3rd element of the array which throws an exception.
// File Name : ExcepTest.java
import java.io.*;
public class ExcepTest{

   public static void main(String args[]){
      try{
         int a[] = new int[2];
         System.out.println("Access element three :" + a[3]);
      }catch(ArrayIndexOutOfBoundsException e){
         System.out.println("Exception thrown  :" + e);
      }
      System.out.println("Out of the block");
   }
}
This would produce the following result:
Exception thrown  :java.lang.ArrayIndexOutOfBoundsException: 3
Out of the block

Multiple catch Blocks:

A try block can be followed by multiple catch blocks. The syntax for multiple catch blocks looks like the following:
try
{
   //Protected code
}catch(ExceptionType1 e1)
{
   //Catch block
}catch(ExceptionType2 e2)
{
   //Catch block
}catch(ExceptionType3 e3)
{
   //Catch block
}
The previous statements demonstrate three catch blocks, but you can have any number of them after a single try. If an exception occurs in the protected code, the exception is thrown to the first catch block in the list. If the data type of the exception thrown matches ExceptionType1, it gets caught there. If not, the exception passes down to the second catch statement. This continues until the exception either is caught or falls through all catches, in which case the current method stops execution and the exception is thrown down to the previous method on the call stack.

Example:

Here is code segment showing how to use multiple try/catch statements.
try
{
   file = new FileInputStream(fileName);
   x = (byte) file.read();
}catch(IOException i)
{
   i.printStackTrace();
   return -1;
}catch(FileNotFoundException f) //Not valid!
{
   f.printStackTrace();
   return -1;
}

The throws/throw Keywords:

If a method does not handle a checked exception, the method must declare it using the throwskeyword. The throws keyword appears at the end of a method's signature.
You can throw an exception, either a newly instantiated one or an exception that you just caught, by using the throw keyword. Try to understand the different in throws and throw keywords.
The following method declares that it throws a RemoteException:
import java.io.*;
public class className
{
   public void deposit(double amount) throws RemoteException
   {
      // Method implementation
      throw new RemoteException();
   }
   //Remainder of class definition
}
A method can declare that it throws more than one exception, in which case the exceptions are declared in a list separated by commas. For example, the following method declares that it throws a RemoteException and an InsufficientFundsException:
import java.io.*;
public class className
{
   public void withdraw(double amount) throws RemoteException,
                              InsufficientFundsException
   {
       // Method implementation
   }
   //Remainder of class definition
}

The finally Keyword

The finally keyword is used to create a block of code that follows a try block. A finally block of code always executes, whether or not an exception has occurred.
Using a finally block allows you to run any cleanup-type statements that you want to execute, no matter what happens in the protected code.
A finally block appears at the end of the catch blocks and has the following syntax:
try
{
   //Protected code
}catch(ExceptionType1 e1)
{
   //Catch block
}catch(ExceptionType2 e2)
{
   //Catch block
}catch(ExceptionType3 e3)
{
   //Catch block
}finally
{
   //The finally block always executes.
}

Example:

public class ExcepTest{

   public static void main(String args[]){
      int a[] = new int[2];
      try{
         System.out.println("Access element three :" + a[3]);
      }catch(ArrayIndexOutOfBoundsException e){
         System.out.println("Exception thrown  :" + e);
      }
      finally{
         a[0] = 6;
         System.out.println("First element value: " +a[0]);
         System.out.println("The finally statement is executed");
      }
   }
}
This would produce the following result:
Exception thrown  :java.lang.ArrayIndexOutOfBoundsException: 3
First element value: 6
The finally statement is executed
Note the following:
  • A catch clause cannot exist without a try statement.
  • It is not compulsory to have finally clauses when ever a try/catch block is present.
  • The try block cannot be present without either catch clause or finally clause.
  • Any code cannot be present in between the try, catch, finally blocks.
Article by
----------------
CSE Department
Sri Sunflower College of Engineering & Technology

Sri Sunflower College of Engineering & Technology

Electronic Circuits and Its types

Electronic Circuits
An electronic circuit is composed of individual electronic components, such as resistors, transistors, capacitors, inductors and diodes, connected by conductive wires or traces through which electric current can flow. The combination of components and wires allows various simple and complex operations to be performed: signals can be amplified, computations can be performed, and data can be moved from one place to another.[1] Circuits can be constructed of discrete components connected by individual pieces of wire, but today it is much more common to create interconnections by photolithographic techniques on a laminated substrate (a printed circuit board or PCB) and solder the components to these interconnections to create a finished circuit. In an integrated circuit or IC, the components and interconnections are formed on the same substrate, typically a semiconductor such as silicon or (less commonly) gallium arsenide.
Breadboards, perfboards, and stripboards are common for testing new designs. They allow the designer to make quick changes to the circuit during development.
An electronic circuit can usually be categorized as an analog circuit, a digital circuit, or a mixed-signal circuit (a combination of analog circuits and digital circuits).
Analog Circuits
Analog electronic circuits are those in which current or voltage may vary continuously with time to correspond to the information being represented. Analog circuitry is constructed from two fundamental building blocks: series and parallel circuits. In a series circuit, the same current passes through a series of components. A string of Christmas lights is a good example of a series circuit: if one goes out, they all do. In a parallel circuit, all the components are connected to the same voltage, and the current divides between the various components according to their resistance.
A simple schematic showing wires, a resistor, and a battery
The basic components of analog circuits are wires, resistors, capacitors, inductors, diodes, and transistors. (In 2012 it was demonstrated that memristors can be added to the list of available components.) Analog circuits are very commonly represented in schematic diagrams, in which wires are shown as lines, and each component has a unique symbol. Analog circuit analysis employs Kirchhoff's circuit laws: all the currents at a node (a place where wires meet), and the voltage around a closed loop of wires is 0. Wires are usually treated as ideal zero-voltage interconnections; any resistance or reactance is captured by explicitly adding a parasitic element, such as a discrete resistor or inductor. Active components such as transistors are often treated as controlled current or voltage sources: for example, a field-effect transistor can be modeled as a current source from the source to the drain, with the current controlled by the gate-source voltage.
When the circuit size is comparable to a wavelength of the relevant signal frequency, a more sophisticated approach must be used. Wires are treated as transmission lines, with (hopefully) constant characteristic impedance, and the impedances at the start and end determine transmitted and reflected waves on the line. Such considerations typically become important for circuit boards at frequencies above a GHz; integrated circuits are smaller and can be treated as lumped elements for frequencies less than 10 10GHz or so.
An alternative model is to take independent power sources and induction as basic electronic units; this allows modeling frequency dependent negative resistors, gyrators, negative impedance converters, and dependent sources as secondary electronic components.
Digital Circuits
In digital electronic circuits, electric signals take on discrete values, to represent logical and numeric values.[3] These values represent the information that is being processed. In the vast majority of cases, binary encoding is used: one voltage (typically the more positive value) represents a binary '1' and another voltage (usually a value near the ground potential, 0 V) represents a binary '0'. Digital circuits make extensive use of transistors, interconnected to create logic gates that provide the functions of Boolean logic: AND, NAND, OR, NOR, XOR and all possible combinations thereof. Transistors interconnected so as to provide positive feedback are used as latches and flip flops, circuits that have two or more metastable states, and remain in one of these states until changed by an external input. Digital circuits therefore can provide both logic and memory, enabling them to perform arbitrary computational functions. (Memory based on flip-flops is known as static random-access memory (SRAM). Memory based on the storage of charge in a capacitor, dynamic random-access memory (DRAM) is also widely used.)
The design process for digital circuits is fundamentally different from the process for analog circuits. Each logic gate regenerates the binary signal, so the designer need not account for distortion, gain control, offset voltages, and other concerns faced in an analog design. As a consequence, extremely complex digital circuits, with billions of logic elements integrated on a single silicon chip, can be fabricated at low cost. Such digital integrated circuits are ubiquitous in modern electronic devices, such as calculators, mobile phone handsets, and computers. As digital circuits become more complex, issues of time delay, logic races, power dissipation, non-ideal switching, on-chip and inter-chip loading, and leakage currents, become limitations to the density, speed and performance.
Digital circuitry is used to create general purpose computing chips, such as microprocessors, and custom-designed logic circuits, known as application-specific integrated circuit (ASICs). Field-programmable gate arrays (FPGAs), chips with logic circuitry whose configuration can be modified after fabrication, are also widely used in prototyping and development.
Mixed Circuits
Mixed-signal or hybrid circuits contain elements of both analog and digital circuits. Examples include comparators, timers, phase-locked loops, analog-to-digital converters, and digital-to-analog converters. Most modern radio and communications circuitry uses mixed signal circuits. For example, in a receiver, analog circuitry is used to amplify and frequency-convert signals so that they reach a suitable state to be converted into digital values, after which further signal processing can be performed in the digital domain.
----------------------------------------------------------------------------------------------------------------
Article by 
---------------
ECE Department
Sri Sunflower College of Engineering & Technology



Sri Sunflower College of Engineering & Technology,Lankapalli

Most Important & Common Question for Interview

Most Important & Common Question for Interview
Interviews are about presenting yourself in a positive and confident manner and we have interview skills and tips to help you. Many candidates are often worried that by "overselling" themselves they may appear arrogant and, as a result, they opt for mainstream answers which can sometimes appear fairly vague.
Planning for the interview
Prepare yourself, interviews are two-way meetings. It is an opportunity for the interviewer to find out about you as a suitable candidate for the position. But they are also an opportunity for you to find out about the organization that will provide you with the challenge and job satisfaction you are looking for. Prepare some questions to ask at the interview At the first interview it would be wise to restrict your questions to the details of the job and the organization.Find out everything you can about the company and what it makes or does. Look current news-show you are up to date.
What skills/qualities/experience do you have to match?
The interview rating sheet consists of following parameters:

Appearance 
Grooming, Posture, Dress, Manners
Communication
Grammar, Non verbal, Eye contact, Presentation
Personality
Attitude, Motivation, Enthusiasm, Sincerity 
Maturity
Responsibility, Dependability, Confident, Composure
Goals
Future Goals, Interest in Jobs, Knowledge, Set Plan

Tell me about yourself
The most often asked question in interviews. You need to have a short statement prepared in your mind. Be careful that it does not sound rehearsed. Limit it to work-related items unless instructed otherwise. Talk about things you have done and jobs you have held that relate to the position you are interviewing for. Start with the item farthest back and work up to the present.
What experience do you have in this field?
Speak about specifics that relate to the position you are applying for. If you do not have specific experience, get as close as you can.
What do you know about this organization?
- This question is one reason to do some research on the organization before the interview. Find out where they have been and where they are going. What are the current issues and who are the major players?
What have you done to improve your knowledge in the last year?
 - Try to include improvement activities that relate to the job. A wide variety of activities can be mentioned as positive self-improvement. Have some good ones handy to mention.
Are you applying for other jobs? - Be honest but do not spend a lot of time in this area. Keep the focus on this job and what you can do for this organization. Anything else is a distraction.
Why do you want to work for this organization?
 - This may take some thought and certainly, should be based on the research you have done on the organization. Sincerity is extremely important here and will easily be sensed. Relate it to your long-term career goals.
• Do you know anyone who works for us?
 - Be aware of the policy on relatives working for the organization. This can affect your answer even though they asked about friends not relatives. Be careful to mention a friend only if they are well thought of.
Are you a team player?
- You are, of course, a team player. Be sure to have examples ready. Specifics that show you often perform for the good of the team rather than for yourself are good evidence of your team attitude. Do not brag, just say it in a matter-of-fact tone. This is a key point.
How long would you expect to work for us if hired?
 - Specifics here are not good. Something like this should work: I’d like it to be a long time. Or As long as we both feel I’m doing a good job.
What is your philosophy towards work?
 - The interviewer is not looking for a long or flowery dissertation here. Do you have strong feelings that the job gets done? Yes. That’s the type of answer that works best here. Short and positive, showing a benefit to the organization.
Explain how you would be an asset to this organization?
 - You should be anxious for this question. It gives you a chance to highlight your best points as they relate to the position being discussed. Give a little advance thought to this relationship.
Why should we hire you?
 - Point out how your assets meet what the organization needs. Do not mention any other candidates to make a comparison.
Tell me about a suggestion you have made - Have a good one ready. Be sure and use a suggestion that was accepted and was then considered successful. One related to the type of work applied for is a real plus.
What is your greatest strength?
 - Numerous answers are good, just stay positive. A few good examples: Your ability to prioritize, Your problem-solving skills, Your ability to work under pressure, Your ability to focus on projects, Your professional expertise, Your leadership skills, Your positive attitude .
Tell me about your dream job?
- Stay away from a specific job. You cannot win. If you say the job you are contending for is it, you strain credibility. If you say another job is it, you plant the suspicion that you will be dissatisfied with this position if hired. The best is to stay genetic and say something like: A job where I love the work, like the people, can contribute and can’t wait to get to work.
Why do you think you would do well at this job?
- Give several reasons and include skills, experience and interest.
• What kind of person would you refuse to work with?
 - Do not be trivial. It would take disloyalty to the organization, violence or lawbreaking to get you to object. Minor objections will label you as a whiner.
What is more important to you: the money or the work?
- Money is always important, but the work is the most important. There is no better answer.
What kind of salary do you need?
- A loaded question. A nasty little game that you will probably lose if you answer first. So, do not answer it. Instead, say something like, That’s a tough question. Can you tell me the range for this position? In most cases, the interviewer, taken off guard, will tell you. If not, say that it can depend on the details of the job. Then give a wide range.
What has disappointed you about a job?
 - Don’t get trivial or negative. Safe areas are few but can include: Not enough of a challenge. You were laid off in a reduction Company did not win a contract, which would have given you more responsibility.
Tell me about your ability to work under pressure?
 - You may say that you thrive under certain types of pressure. Give an example that relates to the type of position applied for.
Do your skills match this job or another job more closely?
 - Probably this one. Do not give fuel to the suspicion that you may want another job more than this one.
What motivates you to do your best on the job?
- This is a personal trait that only you can say, but good examples are: Challenge, Achievement, and Recognition
Are you willing to work overtime? Nights? Weekends?
 - This is up to you. Be totally honest.
• How would you know you were successful on this job?
- Several ways are good measures: You set high standards for yourself and meet them. Your outcomes are a success. Your boss tell you that you are successful
Do you consider yourself successful?
- You should always answer yes and briefly explain why. A good explanation is that you have set goals, and you have met some and are on track to achieve the others.
• Would you be willing to relocate if required?
- You should be clear on this with your family prior to the interview if you think there is a chance it may come up. Do not say yes just to get the job if the real answer is no. This can create a lot of problems later on in your career. Be honest at this point and save yourself future grief.
Are you willing to put the interests of the organization ahead of your own?
 - This is a straight loyalty and dedication question. Do not worry about the deep ethical and philosophical implications. Just say yes.
• What have you learned from mistakes on the job?
- Here you have to come up with something or you strain credibility. Make it small, well intentioned mistake with a positive lesson learned. An example would be working too far ahead of colleagues on a project and thus throwing coordination off.
If you had enough money to retire right now, would you?
- Answer yes if you would. But since you need to work, this is the type of work you prefer. Do not say yes if you do not mean it.
Have you ever been asked to leave a position? - If you have not, say no. If you have, be honest, brief and avoid saying negative things about the people or organization involved.
Do you have any blind spots?
- Trick question. If you know about blind spots, they are no longer blind spots. Do not reveal any personal areas of concern here. Let them do their own discovery on your bad points. Do not hand it to them.
If you were hiring a person for this job, what would you look for? - Be careful to mention traits that are needed and that you have.
Do you think you are overqualified for this position?
 - Regardless of your qualifications, state that you are very well qualified for the position.
How do you propose to compensate for your lack of experience?
- First, if you have experience that the interviewer does not know about, bring that up: Then, point out (if true) that you are a hard working quick learner.
What qualities do you look for in a boss?
 - Be generic and positive. Safe qualities are knowledgeable, a sense of humor, fair, loyal to subordinates and holder of high standards. All bosses think they have these traits.
Tell me about a time when you helped resolve a dispute between others.
- Pick a specific incident. Concentrate on your problem solving technique and not the dispute you settled.
What position do you prefer on a team working on a project?
- Be honest. If you are comfortable in different roles, point that out.
• Describe your work ethic.
- Emphasize benefits to the organization. Things like, determination to get the job done and work hard but enjoy your work are good.
Have you ever had to fire anyone? How did you feel about that?
 - This is serious. Do not make light of it or in any way seem like you like to fire people. At the same time, you will do it when it is the right thing to do. When it comes to the organization versus the individual who has created a harmful situation, you will protect the organization. Remember firing is not the same as layoff or reduction in force.
What has been your biggest professional disappointment?
 - Be sure that you refer to something that was beyond your control. Show acceptance and no negative feelings.
Tell me about the most fun you have had on the job.
 - Talk about having fun by accomplishing something for the organization.
Do you have any questions for me?
- Always have some questions prepared. Questions prepared where you will be an asset to the organization are good. How soon will I be able to be productive? And what type of projects will I be able to assist on? Are examples.
..............................................................................................................................................
Article by
...............
Training & Placement Cell
Sri Sunflower College of Engineering & Technology
                                           
Training & Placement Cell
Sri Sunflower College of Engineering & Technology
Sri Sunflower College of Engineering & Technology
                                 


                                                                                                                                          

Time Base Generators

Time Base Generators

A time base generator is an electronic circuit which generates voltage or current that varies linearly with time. Ideally the output waveform of time base generator should be a ramp. The most popular and important application of such a ramp voltage is in a cathode ray oscilloscope (CRO), for deflecting the electron beam horizontally across the screen we need sweep voltages or ramp voltages. This sweep signal is either voltage or current.
To generate these signals we go for linear time base generators. It generates a voltage or current which varies linearly with time.There are two kinds of sweep generators, based on its output

  •       Voltage time base generator
  •      Current time base generator
Time base generator also finds application in radar, television, time modulation and precise time measurements etc.
Time –base wave forms are generated by the following methods
o    Exponent charging
o    Constant current charging
o    Miller circuit
o    Boot strap sweep circuit

Now we will discuss about the principle and working of Bootstrap sweep circuit

Bootstrap sweep generator

Principle: This constant current flowing through the capacitor develops ramp voltage across it.

Operation:

The circuit of a transistor bootstrap ramp generator is shown in figure. The ramp is generated across capacitor C1, which is charged via resistance R1. The discharge transistor Q1 holds the capacitor voltage V1 down to VCE (sat) until a negative input pulse is applied. Transistor Q2 is an emitter follower that provides a low output impedance emitter through Re is connected to a negative supply level, rather than to ground. This is to ensure that Q2 remains conducting when its base voltage V1 is close to ground. Capacitor C3, known as the bootstrapping capacitor, has a much higher capacitance than C1. The function of C3, as will be shown, is to maintain a constant voltage across R1 and thus maintain the charging current constant.
The input Vi is a pulse voltage, when the input signal Vi is positive, the transistor Q1 becomes ON i.e. goes into saturation. Potential of point VA= VCE(sat)=0.3v
Output voltage VO=VA-VBE (Q2) (in active region)
                              = 0.3-0.6= -0.3


The emitter of Q2 is coupled to the collector of Q1 through the capacitor C3.         
Hence point B becomes negative, hence Diode D readily conducts, with the result that potential at VB =Vcc
    When the input Vi goes negative, Q1 becomes OFF.C1 startscharging via R1.voltage V1 now increases, and the emitter voltage Vo of Q2 also increases. As Vo increases, the lower terminal of C3 is pulled up. Because C3 has a high capacitance, it retains its charge and as Vo increases, the voltage at the upper terminal of C3 also increases .the result is that the potential of B also rises by the same amount.
Thus VB rises from Vcc to Vcc +VA =>    VB=Vcc +VA
Let I denote the current through R1
i.e   I =(VB-VA)/R1 =Vcc/R1
Since VB=Vcc +VA
Since both Vcc and R1 are of fixed magnitude, the ratio (Vcc/R1) is constant. Hence current I is of constant magnitude.
Since the collector current of Q1 is (Ic1=0) zero, I=I1+IB2
IB2    is the base current of Q2.since Q2 is an emitter follower, its input impedance is very, very high and hence IB2 is practically zero therefore I1=I, a constant current As the current flows through the capacitor C1,a ramp voltage develops across it.

For an emitter follows, voltage gain is almost unity. Therefore, the output Voltage Vo is also a ramp voltage. Thus the bootstrap circuit generates a ramp voltage.
----------------------------------------------------------------------------------------------------------------
Article by 
---------------
ECE Department
Sri Sunflower College of Engineering & Technology



Sri Sunflower College of Engineering & Technology,Lankapalli