Java Import Statement - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript Java Import Statement - Supercoders | Web Development and Design | Tutorial for Java, PHP, HTML, Javascript

Breaking

Post Top Ad

Post Top Ad

Thursday, March 14, 2019

Java Import Statement

Java Import Statement


üA java package is a collection of related classes.

üIn order to access the available classes in the package, the 
program must specify the complete dot seperated package path.

üThe general format:

  import package-level1.[package-level2.]classname|*

ü Two form of import statement:

  1. import.package.class;
  2. import package.*;

Example:

import java.util.Scanner;
import java.util.*;

Example

INPUT

import java.util.Random;


class random

{
        public static void main(String args[])

        {
                Random r = new Random();

                int i;

                float v;

                for(i=0;i<5;i++)

                {

                        v=r.nextFloat();

                        System.out.println(v);
                }
        }
}

Predefined Stream




Stream:

-A stream is an abstraction that either produces or 

consumes information.

-It is linked to a physical device by a java I/O system.

-The hide the details of the physical device to which

 they are connected.

System:

-System is a predefined class included in the package 

java.lang. (Imported automatically by all java 

programs).

-It includes three predefined stream variables:


  1. in   2. out.   3. err

The Predefined Streams

System.out: refers to the standard output stream. It

 is an object of type PrintStream.

System.in: refers to the standard input stream. It is an

 object of type InputStream.

System.err: refers to the standard error stream. It is

 an object of type PrintStream.

Note: they are defined as public and static.

InputStream:

-This class in included in the package java.io.

-It has some subclasses the handle the differences
 between various devices.

-Includes some methods that the subclasses will implement.


No comments:

Post a Comment

Post Top Ad