Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Can you prove to me wiht some documents??

Posted on 2004-04-14
6
Medium Priority
?
238 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 300 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 300 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Simulator games are perfect for generating sample realistic data streams, especially for learning data analysis. It is even useful for demoing offerings such as Azure stream analytics, PowerBI etc.
In this post, I will showcase the steps for how to create groups in Office 365. Office 365 groups allow for ease of flexibility and collaboration between staff members.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

971 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