Skip to main content

Posts

JAVA : W1-M4

Interface Learning Objective Welcome Back!. In this Module let us solve Problems related to Interface . Defining an Interface Implementing Interfaces Applying Interfaces Variables in Interfaces Interfaces can be extended Orientation Video Introduction Interface: In the Java programming language, an interface is a reference type, similar to a class, that can contain only constants, method signatures, and nested types. There are no method bodies. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces. Extension is discussed later in this lesson. Defining an interface: Interfaces are defined with the following syntax (compare to Java's class definition). [ visibility ] interface InterfaceName [ extends other interfaces ] { constant declarations member type declarations abstract method declarations } The body of the interface contains abstract methods, but since all met...

JAVA : W1-M5

Packages Learning Objective * Package Concepts in Java Orientation Video Introduction Packages: Multiple classes of larger programs are usually grouped together into a package. Packages correspond to directories in the file system, and may be nested just as directories are nested. Package = directory. Reasons to use packages • Grouping related classes. • To allow classes to be combined in a single ".jar" file. • To control the namespace. • To limit the scope of names. Grouping related classes. If you are writing a normal one-programmer application, it will typically be in one package. The purpose of a package is to group all related classes together. If you are working on a program that is divided into separate sections that are worked on by others, each section might be in its own package. This prevents class name conflicts and reduces coupling by allowing package scope to be used effectively. Package declarations: Each file may have a ...

JAVA : W1-M6

Exception Handling Learning Objective Welcome Back!. In this Module let us solve Problems related to Exception Handling in java . Orientation Video Introduction Exception, that means exceptional errors. Actually exceptions are used for handling errors in programs that occurs during the program execution. During the program execution if any error occurs and you want to print your own message or the system message about the error then you write the part of the program which generate the error in the try{} block and catch the errors using catch() block. Exception turns the direction of normal flow of the program control and send to the related catch() block. Error that occurs during the program execution generate a specific object which has the information about the errors occurred in the program. In the following example code you will see that how the exception handling can be done in java program. This example reads two integer numbers for the variables a and b. I...

JAVA : W1-M7

File I/O Learning Objective Welcome to the Day4 in Java . Here we would concentrate on solving File I/O Problems. Introduction The Java I/O means Java Input/Output. It is provided by the java.io package. This package has an InputStream and OutputStream. Java InputStream is defined for reading the stream, byte stream and array of byte stream. Java offers extensive - yet easy to use - file handling classes that make it a breeze to read and write files. In this tutorial, we'll start by covering the basics of file input and output, as well as covering some associated topics, such as trapping exceptions and I/O errors. File output Our first example will be a program that writes a string to a file. In order to use the Java file classes, we must import the Java input/output package (java.io) in the following manner import java.io.*; Inside the main method of our program, we m...