0% found this document useful (0 votes)
4 views3 pages

Java Input Techniques and Error Handling

The document outlines three data input techniques in Java: initialization or literals, parameters, and the scanner class. It describes various Java API packages, their functionalities, and the advantages of using packages, such as effective management and encapsulation. Additionally, it covers error types in Java, including syntax, runtime, and logical errors, along with common examples and debugging processes.

Uploaded by

Amrit Tandan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Java Input Techniques and Error Handling

The document outlines three data input techniques in Java: initialization or literals, parameters, and the scanner class. It describes various Java API packages, their functionalities, and the advantages of using packages, such as effective management and encapsulation. Additionally, it covers error types in Java, including syntax, runtime, and logical errors, along with common examples and debugging processes.

Uploaded by

Amrit Tandan
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

INPUTS IN JAVA

The three types of data input techniques in Java.


1. Input using initialization or literals
2. Input using parameters (bluej)
3. Input using scanner class
PACKAGES
Package is a named collection of Java classes that are grouped on
the basis of their functionality.
JAVA API PACKAGES
Package Description
[Link] Provides classes for printing and scanning
[Link] Provides classes for primitive datatypes, string and
Math functions
[Link] Provides classes for input and output
[Link] Provides classes for implementing Graphical User
Interface
[Link] Provides classes for networking
[Link] Provides classes for implementing applets

ADVANTAGES OF PACKAGE
1. Packages grouped related classes so that they can be
managed effectively
2. The classes contained in other packages can easily be reused.
3. You can declare multiple classes with the same name in
different packages.
4. Encapsulation can be implemented by using packages.
Method Description
nextShort() This method is used to read a short.
nextInt() This method is used to read a integer
nextLong() This method is used to read a long
nextFloat() This method is used to read a float.
nextDouble() This method is used to read a double.
next().charAt(0) This method is used to read a character.
next() This method is used to read a word.
nextLine() This method is used to read a sentence.
ERRORS
An error is a mistake in a program that prevent it from normal
working. Errors are often referred to as bugs.
DEBUGGING
The process of finding and eliminating errors is called debugging.
Errors are broadly classified into three categories as defined as
syntax error, runtime error and logical error.
SYNTAX ERROR (COMPILE TIME ERROR)
Syntax error occur due to the fact that the syntax of a programming
language has not been followed correctly. The syntax errors are
analogous to spelling or grammatical mistakes in a language.
Common syntax errors in java
1. Missing semi colon ( ; )after a statement
2. Missing or unmatched brackets
3. Incorrect spelling of keywords or identifiers
4. Using variables that have not been defined but are being used
in a program
5. In compatible assignments.
6. Missing double quotes in a string or single quotes in a
character
7. Using an assignment operator ( = ) instead of equality
operator (== )

RUNTIME ERROR
A runtime error occurs during the execution of a program. The
program may compile successfully but may not run properly as
planned or may not execute at all.
Common runtime errors in java.
1. Divide by zero error.
2. Parsing an invalid string into a numeric value.
3. Running out of memory during program execution.
4. Trying to access a data file which does not exist.
5. Entering a string value where a numeric value is expected for
the scanner object.
LOGICAL ERRORS
When a program compiles and runs without errors but produces an
incorrect result this type of error is known as logical error. It is
caused by a mistake in the program logic which is often due to
human error.
Common logical errors in Java.
1. Using the wrong variable name
2. Using integer division by mistake instead of floating point
division.
3. Using operators without understanding their precedence and
associativity.
4. Displaying the wrong message.

You might also like