Solved

Can you prove to me wiht some documents??

Posted on 2004-04-14
6
225 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
ID: 10822125
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
ID: 10822132
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
ID: 10822208
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
ID: 10827376
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Running Java Servlet inside Eclipse Luna 6 147
java.util.concurrent.Callable way of creating threads 2 102
maven project jars 7 50
spring example non maven 4 80
When converting a physical machine to a virtual machine using VMware vCenter Converter Standalone or vCenter Converter Enterprise, if an adapter type is not selected during the initial customization the resulting virtual machine may contain an IDE d…
If your vDisk VHD file gets deleted from the image store accidentally or on purpose, you won't be able to remove the vDisk from the PVS console. There is a known workaround that is solid.
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

948 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

21 Experts available now in Live!

Get 1:1 Help Now