Solved

Can you prove to me wiht some documents??

Posted on 2004-04-14
6
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
issue with pdf generation 2 95
best tutorial on log4j and logging for servlets/jsp codes 1 65
struts hibernate integration example 28 146
java operators 3 125
Adults who share images on social media aren’t the only ones who need to worry about their privacy. Our culture’s tendency to share every move and celebration affects the privacy of our children, too.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

740 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