473,385 Members | 1,593 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Avoiding imports

3
For some reason, I have to rewrite a program to avoid using import statements. I know it's possible, but cannot seem to find it in my text book. Can someone please give me a sample outline of how it's done?

Thanks
Nov 8 '06 #1
3 1674
horace1
1,510 Expert 1GB
For some reason, I have to rewrite a program to avoid using import statements. I know it's possible, but cannot seem to find it in my text book. Can someone please give me a sample outline of how it's done?

Thanks
in Java you can either specify the API package names using import statements or when you call the methods.

For example a program using import
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. public class Test1
  5. {
  6. public static void main(String args[])
  7. {
  8.     Vector v = new Vector();
  9.     v.addElement(Math.asin(1.0));
  10. }
  11. }
  12.  
and same program using no import statements
Expand|Select|Wrap|Line Numbers
  1. public class Test
  2. {
  3. public static void main(String args[])
  4. {
  5.     java.util.Vector v = new java.util.Vector();
  6.     v.addElement(java.lang.Math.asin(1.0));
  7. }
  8. }
  9.  
Nov 8 '06 #2
r035198x
13,262 8TB
in Java you can either specify the API package names using import statements or when you call the methods.

For example a program using import
Expand|Select|Wrap|Line Numbers
  1. import java.util.*;
  2. import java.lang.*;
  3.  
  4. public class Test1
  5. {
  6. public static void main(String args[])
  7. {
  8. Vector v = new Vector();
  9. v.addElement(Math.asin(1.0));
  10. }
  11. }
  12.  
and same program using no import statements
Expand|Select|Wrap|Line Numbers
  1. public class Test
  2. {
  3. public static void main(String args[])
  4. {
  5. java.util.Vector v = new java.util.Vector();
  6. v.addElement(java.lang.Math.asin(1.0));
  7. }
  8. }
  9.  
Perhaps not related to the question but you do not have to import anything from java.lang. The package is automatically imported for you.
So you can just do
v.addElement(Math.asin(1.0));
Nov 9 '06 #3
using fully qualified names in the body is a bad coding practice. try not to do it
Nov 9 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Wolfgang Kaml | last post by:
I am not sure if this is more of an expert question, but I am sure that they are out there. I'd like to setup a general application or bin directory on my Win2003.Net Server that will hold some...
1
by: Steven K | last post by:
Hello, Is there a way to declare imports so that they don't have to be declared both in Master Page.vb and the Content Page.vb? For example, I have the following in the Master Page.vb Imports...
19
by: Tiraman | last post by:
Hi , I have an assembly that hold few class and few imports which are not used in all of the class's . so my question is when to use the "Imports XXX" And when to use this kind of statement...
4
by: Jeff Jarrell | last post by:
I am not really there yet with namespaces. I have a "common.dll" that is referenced from another project. now in the consuming project, source file to i'd like to have a "imports common". ...
7
by: pcnerd | last post by:
In Java I can use, for example, " Imports java.util.* ". Can I use, for example, " Imports System.* " instead of several different "Imports" statements? Thank you. David
1
by: Arpan | last post by:
What's the difference between "Imports" & "Inherits"? For e.g. both the codes below work without any errors: Imports System Imports System.Data Imports System.Web.UI Namespace Constructors...
0
by: vincenzoelettronico | last post by:
I am making the pages asp of one library on-linens with visual study 2003. I have created the datagrid, the subroutine UpdateCommand. .now I want to avoid to always insert the same element....
1
by: Thomas Wittek | last post by:
Hi! Is there any possibility/tool to automatically organize the imports at the beginning of a module? I don't mean automatic imports like autoimp does as I like seeing where my...
5
by: kimiraikkonen | last post by:
Hello, I want to ask about "imports" statement. Some projects must be inserted with "imports xxxx" statements before beginning coding. But how do i know when to use or do i have to use "imports"...
0
by: Kay Schluehr | last post by:
Since their introduction in Python 2.5 I only reviewed the new "relative import" notation briefly by reading the "What's new in Python 2.5" article. Now I wanted checkout if I get comfortable with...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.