CodeGym /Courses /New Java Syntax /Full class name

Full class name

New Java Syntax
Level 8 , Lesson 6
Available
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."

Comments (44)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
larsintech Level 15, Switzerland Expert
25 November 2024
Use import java.io.* to import all Java IO classes.
Fadhil Radhian Level 18, Semarang, Indonesia
13 March 2023
concise and clear as always 👍
Anonymous #10798360 Level 8, Woking, United Kingdom
31 May 2022
Hi. Can someone please explain...... Can't you import the package name in its entirety instead of singling each one out? or is that bad for the memory? Like: Java.io."All"; Instead of: Java.io.something1 Java.io.something2 Thanks in advance.
Ivan Level 28, Cordoba, Argentina
21 September 2022
Hi, yes there is a way to import the whole package. You can use this: import java.io.*; It's recommended to import the classes you are going to use, but the program is not gonna bring all the classes from the package you import. Apparently it only affects the compiler but nothing serious.
TheLordJackMC Level 39, Princeton, idk somewhere
12 July 2021
If there are robots that have lived on a planet with rain for generations, why have they not invented some sort of waterproof coating? that sounds like a smart thing to have
Syed Umar Level 1, Gothenburg , Sweden
27 December 2020
This Robot, Diego is made of titanium and he doesn't rust unlike Amigo 😉😅
Dinesh Level 7, Delhi, India
21 October 2020
Though I have specified the file name but there is an error
Ahmad Level 7, Detroit, United States
30 December 2020
If you are sure the file name is correct and it exists in the "E" drive then make it a double slash "\\" instead of a single one. Like what the example above shows.
Dinesh Level 7, Delhi, India
1 January 2021
Thanks for your kind consideration. I had already used \\ I think issue is something else
Eros nullfeathers Level 4, Salt Lake City, United States
23 March 2021
Did you try running the CLI as administrator. In linux i had a similar problem even when I ran sudo, but then I switched to root user and was able to run program.
Gigi Suchan Level 3, Los Angeles, United States
15 August 2020
/* Comment has been deleted */
mastere Level 9, Rochester, United States
25 September 2020
Try to do the tasks first if this is the case and then go to the associated lessons after and retry the task if you need to. It might help you retain things easier. The way I have been doing it is going to the tasks and completing what I can and then coming to the lessons when I get stuck. Then completing a few lessons and returning to the tasks to complete what I can again and repeat. It may take a little more effort to do it this way, but it is worth it if it helps you learn things better.
Stephen Haokip Level 12, imphal, India
26 June 2020
water makes us rust fast and yet the robot is drinking coffeee in the pics
M Till Level 7, San Jose, United States
23 July 2020
He's clearly a human spy!
Kọ́láwọlé Fasasi Level 2, Ògùn, Nigeria
25 July 2020
Aha!
Rajamanjusha Amirapu Level 3, Albany, United States
31 August 2020
ur smart!!!
Jack Level 4, Yerevan, Armenia
9 April 2020
i'm confused the first example is with "full names" but its shorter and simpler than the2nd example which just has all of the 1st example + import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException;
Fuzzy_Melon Level 9, United States
10 April 2020
The idea is to import the package once so you don't have to retype the full path for each class every time its used in the program. For example, "java.io.FileInputStream" becomes just "FileInputStream" throughout the whole program if we import the package at the beginning (import java.io.FileInputStream;). Hope that helps.
Potato Sheep Level 3, Sampaloc, Philippines
30 October 2019
In java full class name doesn't call "FULL NAME" it calls "fully qualified name"