Java import statement - Techist - Tech Forum

Go Back   Techist - Tech Forum > Computer Software > Programming
Click Here to Login
Closed Thread
 
Thread Tools Display Modes
 
Old 06-16-2007, 04:52 AM   #1 (permalink)
Junior Techie
 
Join Date: May 2005
Posts: 66
Default Java import statement

i'm trying to make a simple console application here that would be simplified by importing some class from Java.

import static java.lang.Character.isLowerCase;
import static java.lang.Character.isUpperCase;
import static java.lang.Character.isDigit;

public class LetterCheck{
public static void main(String[] args){
char symbol = 'A';
symbol = (char)(128*Math.random());

if (isUpperCase(symbol)){
System.out.println("It is CAPITAL letter ("+symbol+")");
}else {
if(isLowerCase(symbol)){
System.out.println("It is small letter ("+symbol+")");
}else {
System.out.println("It is NOT a letter ("+symbol+")");
}
}
}
}

i just wondering that if i remove the "static" in the import static, it won't work.. when do we put "static" in the import statement and when do not?
__________________

__________________
dingdong-man is offline  
Old 06-16-2007, 11:15 AM   #2 (permalink)
Software Developer
 
Join Date: Mar 2006
Location: USA
Posts: 632
Default Re: Java import statement

You use the 'static' keyword in an import statement when importing static methods. However, it is not good style to import methods only because your code becomes less readable. In this particular instance, you should remove all your import statements and explicitly call each static method using the type (or class, if you prefer that terminology) as shown below.
Code:
boolean x = Character.isUpperCase('A');
boolean y = Character.isLowerCase('b');
__________________

__________________
jaeusm is offline  
Old 06-21-2007, 07:18 PM   #3 (permalink)
Monster Techie
 
Join Date: May 2004
Location: USA
Posts: 1,178
Default Re: Java import statement

Quote:
Originally Posted by jaeusm View Post
You use the 'static' keyword in an import statement when importing static methods. However, it is not good style to import methods only because your code becomes less readable. In this particular instance, you should remove all your import statements and explicitly call each static method using the type (or class, if you prefer that terminology) as shown below.
Code:
boolean x = Character.isUpperCase('A');
boolean y = Character.isLowerCase('b');
In that case, calling Character.method, Character would be a class and not a type.

But...I didn't know this: you can import static methods? That's funny. :laughing: But anyhow, he did that, didn't he?
__________________
Vormund is offline  
Old 06-21-2007, 07:41 PM   #4 (permalink)
Software Developer
 
Join Date: Mar 2006
Location: USA
Posts: 632
Default Re: Java import statement

Quote:
In that case, calling Character.method, Character would be a class and not a type.
Technically, a class is a type, especially during runtime. To your credit, that terminology isn't used as frequently in the Java world.
__________________
jaeusm is offline  
Old 06-21-2007, 09:02 PM   #5 (permalink)
Monster Techie
 
Join Date: May 2004
Location: USA
Posts: 1,178
Default Re: Java import statement

Quote:
Originally Posted by jaeusm View Post
Technically, a class is a type, especially during runtime. To your credit, that terminology isn't used as frequently in the Java world.
I thought about that..."a class is a type and a type is a class"...but note what I said: "in that case". What does his example have to do with runtime?
__________________
Vormund is offline  
Old 06-21-2007, 10:16 PM   #6 (permalink)
Software Developer
 
Join Date: Mar 2006
Location: USA
Posts: 632
Default Re: Java import statement

Quote:
What does his example have to do with runtime?
Nothing. My previous post was in response to you, not the OP. Moreover, what have your posts contributed to this discussion at all?

If you really want to split hairs, a class is a "design time" construct, while a type is a runtime construct.
__________________
jaeusm is offline  
Old 06-22-2007, 11:16 AM   #7 (permalink)
Monster Techie
 
Join Date: May 2004
Location: USA
Posts: 1,178
Default Re: Java import statement

Quote:
Originally Posted by jaeusm View Post
Nothing. My previous post was in response to you, not the OP. Moreover, what have your posts contributed to this discussion at all?

If you really want to split hairs, a class is a "design time" construct, while a type is a runtime construct.
Exactly, but remember, he's starting in the Java world, so any tips (at least I always appreciate 'em) are always welcome.

Nonetheless, that was a side-remark to my question at your original reply:
Quote:
Originally Posted by Vormund View Post
But...I didn't know this: you can import static methods? That's funny. :laughing: But anyhow, he did that, didn't he?
His post does have import static, and since you commented on it, I figured something was wrong? Anyhow...enough.
__________________

__________________
Vormund is offline  
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
hacking online java program. Z e i g Internet Software and Browsers 8 06-23-2007 12:50 AM
Java Game Yek Programming 5 06-16-2007 03:29 AM
Help with objects in Java PnkFloyd27 Programming 20 06-15-2007 07:50 PM
Java SCript Help NEEDED! kellee91 Internet Software and Browsers 1 06-05-2007 11:20 AM
n00b - java array mitzi Programming 3 03-27-2007 06:36 PM



Copyright 2002- Social Knowledge, LLC All Rights Reserved.

All times are GMT -5. The time now is 12:02 AM.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2018, vBulletin Solutions, Inc.