Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
Old 04-29-2004, 07:05 AM   #1 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,486
sde is on a distinguished road
is java.util.Date more efficient than java.util.*

i'm probably splitting hairs here, but i would like to understand how this works.

when i import java.util.* , how does java handle this?

if i'm only using java.util.Date in this class, .. will the compiler only import the date class? or will it still import all other classes even though they are not being used.

hmm .. hope this makes sense. i'm sure you don't see any performance hits, but i want to understand how the compiler works a little better.

thanks
__________________
Mike
sde is offline   Reply With Quote
Old 04-29-2004, 08:01 AM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
Just as a note, you probably don't want to use Date. Try Calendar instead.

The compiler is smart enough to only include what you use. It's more a matter of best practices than optimization. You're being explicit in what you use when you say java.util.Date instead of java.util.*. However, most of us break down and just use java.util.*.

The principle reason one would explicitly say which classes are being imported is because one of the packages you're importing might already have a Date class. Should you wish to say in your code Date foo = new Date() instead of java.util.Date foo = new java.util.Date(), you'll need to specify all the classes from the other package that are getting used, omitting the Date class.

For instance, say you wrote a package "myPackage", and created both a "Time" and "Date" class. You wanted to use the "Time" class, but the java.util.Date class in place of the custom one you wrote. What you should do is import myPackage.Time and java.util.Date. It would correct to say import java.util.*, and you'd still be using the java.util.Date class, but it might confuse someone coming in and looking at your code, as they might think you're using the myPackage.Date class instead.

Here are some links on the nitty gritty aspects of Java below the API level:

Java Language Specification
Java Virtual Machine Specifications
And while it's not on topic, I think you'll make use of this link:
Java Code Conventions
__________________
GitS
Belisarius is offline   Reply With Quote
Old 04-29-2004, 08:45 AM   #3 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,486
sde is on a distinguished road
i ran into that problem of multiple classes with java.util.* and java.sql.* ( i think those were them )

thanks for the links!
__________________
Mike
sde is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 02:42 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting