Does java have an include?

JAVA

    Sponsored Links

    Next

  • 1. Is there any way to require a class to declare a variable?
    Hello everyone! This may be a bit of a dumb question, but I think this is the only way to get where I want to be. Lets say I have an abstract BottledWater class and two classes, Evion and Aquafina extending from it. public abstract class BottledWater { abstract public static final String NAME; // Compile-time error. } public class Aquafina extends BottledWater { public static final String NAME = "Aquafina"; } public class Evion extends BottledWater { public static final String NAME = "Evion"; } Currently, the abstract constant declaration in BottledWater gives a "Modifyer abstract not allowed here" compile-time error. Is there any way to require Evion and Aquafina declare their own NAME variable? I thought a public static constant would be best, since in the scenerio I'm working with, the names would always be the same, and all classes of the same type would have the same name. Thanks in advance!
  • 2. question about what a method does
    I am working on a lab for my college that tells you to take a number and reverse it and then add them and repeat until you get a palindrome number. I am horrible at Java, but I am getting close to a solution. My question is, while I was looking on the internet for ideas, I ran across the Integer.parseInt() method. I was wondering if anyone could just simply tell me what this method does. I would include my code, but it is kind of unnecessary, plus, I don't want anyone to think that I am trying to get my labs done for free! R
  • 3. Time arithmetic
    Dear all, How can I subtract two dates formatted like '01/04/03 12:02' and '01/04/03 11:38' and find their difference in minutes. Cheers!

Does java have an include?

Postby darius » Fri, 18 May 2007 08:22:16 GMT

I have files structured like this:

./foo,java       (no package name)

./mypkg/bar.java (package mypkg)

I need to use class foo inside bar.  AFAIK, I cannot use import.  Can I 
do something like

include ../foo.java

I know, this isn't The Proper Way, but I inherited this system and need 
to modify it without making a lot of changes.

thanks

Re: Does java have an include?

Postby TideRider » Fri, 18 May 2007 11:30:24 GMT



|I have files structured like this:
|
| ./foo,java       (no package name)
|
| ./mypkg/bar.java (package mypkg)
|
| I need to use class foo inside bar.  AFAIK, I cannot use import.  Can I
| do something like
|
| include ../foo.java
|
| I know, this isn't The Proper Way, but I inherited this system and need
| to modify it without making a lot of changes.
|
| thanks

There is no include directive in Java.  The import mechanism is what Java supports, and the access rules take into account the 
package structure.  If you are trying to gain access to non-public members, you are probably heading for Maintenance Hell.

-- 
TideRider



Re: Does java have an include?

Postby Bjorn Abelli » Fri, 18 May 2007 17:01:26 GMT

"darius" < XXXX@XXXXX.COM > wrote...


If you *need* to do that, there's probably some flaw in the design of the 
system...


As TideRider said, "import" is the mechanism to use in Java.

If you've "inherited" the system, you should make the necessary design 
changes in it to make it work, *and* become maintainable. To have any 
classes in such a system in a "no-name" package (the "default" package) is 
to ask for trouble.

Either you've misunderstood something about how the classes should interact, 
but then you shouldn't need to use foo in bar anyway.

Or the system design you've inherited was bad to begin with, and then you 
really should change it, whatever size of that change.

/// Bjorn A



Re: Does java have an include?

Postby Tor Iver Wilhelmsen » Thu, 24 May 2007 06:08:38 GMT

P Thu, 17 May 2007 01:22:16 +0200, skrev darius < XXXX@XXXXX.COM >:


Correct; importing from the default package was "disabled" in some Java SE  
version and later versions.

The only solutions are either to move bar.java to the default package  
(which can then see foo.java), move foo.java to a named package (allowing  
import to work), or insist on using an 1.2.x or earlier Java version.

Re: Does java have an include?

Postby Roedy Green » Wed, 30 May 2007 04:33:26 GMT

On Wed, 16 May 2007 15:22:16 -0800, darius < XXXX@XXXXX.COM > wrote,
quoted or indirectly quoted someone who said :


Packageless classes are for tiny one class experiments.  Put that
class  in a package.  Then all will work in the usual way.
Roedy Green Canadian Mind Products
The Java Glossary
 http://www.**--****.com/ 

Similar Threads:

1.Custom ANT task having an includes tag

Hi,

I'm creating a custom ANT task that is supposed to
read a set of files (all files having a .xml suffix).

Does anyone have an example where they create an
includes tag for a custom ANT task.

As in

<mytask includes="**/*.xml"/>

Thanks

2.webbot include working in Firefox but not in IE 7 (include page javascript problem)

3.webbot include working in Firefox but not in IE 7 (include page javascript problem)

4.Including an external file outside the application using JSP INCLUDE

Hi,

Is there an easy way to include static content outside the WEB
application using JSP include??, rather than opening a file input
stream and outputting to JSP??.

Assuming my war file is placed under
c:\bea\userprojects\mydomain\applications\mywar.war

and it has a jsp which need to include a static html or jsp file
located under c:\renderedJspsFromExternalApplication\file1.jsp

or

c:\renderedHtmlFromExternalApplication\file1.html

how should i be doing it?

Thanks
-SK

5.file included with jsp:include doesn't get parameters

Hi,

I have this example (jsp 2.0):

some_file.jsp:
....
<c:forEach items="${myItems}" var="foo">
           ${foo}  <!-- works fine -->
           <jsp:include page="mypage.jsp"/>
</c:forEach>

mypage.jsp:
${foo}


the expression in mypage doesn't evaluate to any value. i used c:out
and got the same results, and foo is there for sure in some_file.jsp.

i also tried to include from a tag, using pageContext.include(), same
result

i guess i can pass parameters to mypage.jsp using 'param', but i don't
want to do that, in the real case that i have (i want to pass
everything to this page, because i use this include generically in many
places, and using different pages)

i can (and prefer) to do it from a tag

thanx
ittay

6. Having Trouble with Java Script (I Think)

7. ISA2004 having problems with JAVA sites and authentication

8. Java compatibility issues (WAS: MF having issues?)



Return to JAVA

 

Who is online

Users browsing this forum: No registered users and 53 guest