Solved

Can you prove to me wiht some documents??

Posted on 2004-04-14
6
223 Views
Last Modified: 2010-04-01
Hi there, i have some "Debate" so call with some peoples regarding this issues. I or we are just hope to knw the truth.. please procide me some prove or document to support your point.

This is javaBean

abc.java
=======

import java.sql.*;
import java.io.*;
import java.math.*;


we are arguing that if we put the code like this (with .*) , it's will somehow "consume" our memory. Because it'll load all the java.sql's API into our program althouge we didnt use that.

and some say it will not affect at all. Because the Java is smart enough to clean or only load those package that the is used below the code.

So, which version is correct? Will it consume or not?

I am planned to do soething like

System.getMemory .. or something to see the different.. do you think i can do such?

Please provide me some URL so that we can read better...

tahnk you.

0
Comment
Question by:kuching
  • 3
6 Comments
 
LVL 7

Expert Comment

by:searlas
Comment Utility
The .* is interpreted at *compile time*, not at runtime.  The Java compiler will include all necessary references in a compiled class file, and no unnecessary ones.

All you have to do is check the size of the compiled class file:
import java.util.Date;
public class UtilDate {
    public static void main(String args[]) {
        System.out.println(new Date());
    }
}


-rwxrwxrwx    1 searlas  mkgroup-      434 Apr 14 12:03 UtilDate.class

import java.util.*;
public class UtilDate {
    public static void main(String args[]) {
        System.out.println(new Date());
    }
}

-rwxrwxrwx    1 searlas  mkgroup-      434 Apr 14 12:04 UtilDate.class
0
 
LVL 7

Expert Comment

by:searlas
Comment Utility
And for completeness, not using an import at all:

public class UtilDate {
    public static void main(String args[]) {
        System.out.println(new java.util.Date());
    }
}

-rwxrwxrwx    1 searlas  mkgroup-      434 Apr 14 12:06 UtilDate.class
0
 
LVL 7

Accepted Solution

by:
searlas earned 75 total points
Comment Utility
As a document reference, the class file spec should do:
http://java.sun.com/docs/books/vmspec/2nd-edition/html/ClassFile.doc.html

Note the structure of a class file - it contains no references to import statements at all.  Reading the document in more depth should satisfy you that this is indeed the case.
ClassFile {
    u4 magic;
    u2 minor_version;
    u2 major_version;
    u2 constant_pool_count;
    cp_info constant_pool[constant_pool_count-1];
    u2 access_flags;
    u2 this_class;
    u2 super_class;
    u2 interfaces_count;
    u2 interfaces[interfaces_count];
    u2 fields_count;
    field_info fields[fields_count];
    u2 methods_count;
    method_info methods[methods_count];
    u2 attributes_count;
    attribute_info attributes[attributes_count];
    }
0
 
LVL 4

Assisted Solution

by:john-at-7fff
john-at-7fff earned 75 total points
Comment Utility
Here's a short and sweet answer: It will not consume memory in your running program.

So import foo.* all you want!!

http://www.javaperformancetuning.com/news/qotm031.shtml

0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
session bean client machine 9 53
servlet init param and contect param 3 53
excpetion with multiple catch 11 104
java operators 3 87
HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
A procedure for exporting installed hotfix details of remote computers using powershell
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now