Computer Forums

Member Login

Remember Me? Sign Up! | Forgot Password
 
Slogan
 
Closed Thread
Old 06-16-2007, 05:52 AM   #1 (permalink)
 
Junior Techie

Join Date: May 2005

Posts: 66

dingdong-man

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, 12:15 PM   #2 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

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, 08:18 PM   #3 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
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, 08:41 PM   #4 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

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, 10:02 PM   #5 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
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? :rolleyes:
__________________
Vormund is offline  
Old 06-21-2007, 11:16 PM   #6 (permalink)
 
Software Developer

Join Date: Mar 2006

Location: Columbus, OH

Posts: 569

jaeusm is on a distinguished road

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.

Last edited by jaeusm; 06-21-2007 at 11:21 PM.
jaeusm is offline  
Old 06-22-2007, 12:16 PM   #7 (permalink)
 
Monster Techie

Join Date: May 2004

Location: Tucson, AZ, USA

Posts: 1,183

Vormund

Send a message via AIM to Vormund Send a message via MSN to Vormund Send a message via Yahoo to Vormund
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.
__________________

Last edited by Vormund; 06-22-2007 at 12:18 PM.
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 On


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