Solved

Can you prove to me wiht some documents??

Posted on 2004-04-14
6
233 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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
web service Rest Client creation 4 103
Set up Wildfly 10 8 470
immutable object concept 5 143
struts hibernate integration example 28 158
Check out this step-by-step guide for asking an anonymous question on Experts Exchange.
How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

751 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