Full class name - 1

"Hi, Amigo. I'd like to tell you about full class names."

"As you already know, classes are stored in packages. So, a class's full name consists of the names of all the packages, separated by periods, and the class name. Here are some examples:"

Class name Package name Full name
String
java.lang java.lang.String
FileInputStream
java.io java.io.FileInputStream
ArrayList
java.util java.util.ArrayList
IOException
java.io java.io.IOException;

"To use a class in your code, you need to indicate its full name. You can also use its short name, i.e. just the class name, but you'll need to 'import the class'. This means that before you declare your class, you indicate the word import followed by the name of the class you want to import. Classes from the java.lang packages are imported by default, so you don't need to import them. Here's an example:"

Full class name:
package com.codegym.lesson2;

public class FileCopy2
{
    public static void main(String[] args) throws java.io.IOException
    {
        java.io.FileInputStream fileInputStream =
                        new java.io.FileInputStream("c:\\data.txt");
        java.io.FileOutputStream fileOutputStream =
                        new java.io.FileOutputStream("c:\\result.txt");

        while (fileInputStream.available() > 0)
        {
            int data = fileInputStream.read();
            fileOutputStream.write(data);
        }

        fileInputStream.close();
        fileOutputStream.close();
    }
}

"Here's an example that uses short names:"

Short class name:
package com.codegym.lesson2;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileCopy
{
    public static void main(String[] args) throws IOException
    {
        FileInputStream fileInputStream =
                        new FileInputStream("c:\\data.txt");
        FileOutputStream fileOutputStream =
                        new FileOutputStream("c:\\result.txt");

        while (fileInputStream.available() > 0)
        {
            int data = fileInputStream.read();
            fileOutputStream.write(data);
        }

        fileInputStream.close();
        fileOutputStream.close();
    }
}

"Got it."

"Great."

undefined
2
Опрос
Types and keyboard input,  2 уровень,  9 лекция
недоступен
Types and keyboard input
Types and keyboard input