Difference Between Using C # and Java Import

I know that in java we use * (asterisk) to import all the contents in a package, e.g.

import java.lang.*; 

Then why don't we use the same * (asterisk) in C # to import all the content, is there any method, for example, in java to import all the content. What's the difference between

 import java.awt.*; 

and

 using System.windows.forms; 
+6
source share
3 answers

What Java import does what .NET is called a reference - adding a reference to an assembly in .NET allows you to use the (public) types defined in that assembly.

The C # using directive is just a way to access these types without entering the entire namespace.

You can also use the directive to provide namespace aliases.

+9
source

In Java without * you must import individual classes. In C #, the use of directives refers to namespaces (but not to namespaces, i.e. using System, not System.Windows.Forms for you). Thus, import java.awt. * Gives you about the same as using System.Windows.Forms, so there is no need for * in .Net.

0
source

Clarify what Java import does. Despite this name, .class files are loaded. All you do is save yourself. Java import allows you to reference a class using its short name instead of its fully qualified class name (e.g. String instead of java.lang.String ).

C # using is different from Java import if it actually adds something to the assembly. The Java.class bytecode is loaded as needed by the class loader, not earlier.

0
source

Source: https://habr.com/ru/post/911088/


All Articles