Forums Register Login

Static import statements

+Pie Number of slices to send: Send
Could anyone please tell me why the below import statements are illegal?

+Pie Number of slices to send: Send
Have you read what are static imports, their syntax and significance? Or are you directly attempting to solve questions to clear some exam?
+Pie Number of slices to send: Send
just read out the stuff for static imports from the last chapter of K&B if you have. (as mansukhdeep said) then try to solve an example.
have a look at this also url- Static Import

Static imports are only used for classes and interface and not for any package directly like "import static java.lang"
And Integer is not a static class. So you cant write "import static java.lang.Integer".
It should refer to a static field of Integer class such as "import static import static java.lang.Integer.MAX_VALUE;"

thanks
+Pie Number of slices to send: Send
I am reading the K&B book. I got a little confused the syntax. I read the concept again and again and I got it now. Thanks
+Pie Number of slices to send: Send
You are always welcome. Self-learning is actually the best. You will now remember this for sure. Which K&B book are you learning Java from?
+Pie Number of slices to send: Send
 

Tarun Mohandas wrote:I got it now. Thanks



your welcome.. i suggest you to use your own class in static imports..that will b helpful. ie "import static myclass.PI"
+Pie Number of slices to send: Send
 

Tarun Mohandas wrote:I got it now. Thanks



some naming convention correction.. "import static MyClass.PI"
+Pie Number of slices to send: Send
 

Ishan Pandya wrote: . . . i suggest you to use your own class in static imports..that will b helpful. ie "import static myclass.PI"

For reasons explained here, that will not work. You must include the package name.
+Pie Number of slices to send: Send
 

Mansukhdeep Thind wrote:You are always welcome. Self-learning is actually the best. You will now remember this for sure. Which K&B book are you learning Java from?



I am using K&B SCJP 6. I am using a study guide and oracle website to learn the rest of the stuff in Java SE 7 for OCA.

Ishan Pandya wrote:some naming convention correction.. "import static MyClass.PI"



Thank you for the tip and also for the advise on the syntax by Ritchie
+Pie Number of slices to send: Send
 

Campbell Ritchie wrote:For reasons explained here, that will not work. You must include the package name.


I think TypeName is required which can be class itself. I don't see written that you must include a package. Is it mentioned ritchie??
+Pie Number of slices to send: Send
 

I think TypeName is required which can be class itself.


No, it says "The TypeName must be the canonical name (ยง6.7) of a class type, interface type, enum type, or annotation type.". If you look at section 6.7 it explains what a canonical name is.
+Pie Number of slices to send: Send
 

I am using K&B SCJP 6. I am using a study guide and oracle website to learn the rest of the stuff in Java SE 7 for OCA.



If you already know Java language and want to prepare yourself for the SCJP, then please go ahead and study from the current book. But if you are new to Java, read "Head First Java".
+Pie Number of slices to send: Send
 

Mansukhdeep Thind wrote:If you already know Java language and want to prepare yourself for the SCJP, then please go ahead and study from the current book. But if you are new to Java, read "Head First Java".



I know java. I am able to answer most of SCJP questions but sometimes I get stuck in certain concepts. I go through those concepts repeatedly and get it. I took an OCA mock test in some website and scored 87%. Its only some concepts I find it difficult to grasp, and I am working on it
I think she's lovely. It's this tiny ad that called her crazy:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1070 times.
Similar Threads
<%@ page language = "java" contentType = "text/html"; charset = ISO-8859-1" %> - Error from Netbean
Correct import statement? from Khalid Mughal Review Questions- 4.3
Static Imports
Static Imports Error: Need help Ranchers.
Can somebody help me understand this problem?
More...

All times above are in ranch (not your local) time.
The current ranch time is
Apr 16, 2024 01:39:17.