This week's giveaway is in the JDBC forum.
We're giving away four copies of Java Database Connections & Transactions (e-book only) and have Marco Behler on-line!
See this thread for details.
Win a copy of Java Database Connections & Transactions (e-book only) this week in the JDBC forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Knute Snortum
  • Paul Clapham
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Frits Walraven
Bartenders:
  • Ganesh Patekar
  • Tim Holloway
  • salvin francis

include class in other file?  RSS feed

 
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
import
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In c++ we would #include "somefile.h" to get the classes in somefile.h included in the current program.

What is the Java equivalent? I couldn't find the answer in a tutorial I have been working through.
[ May 06, 2005: Message edited by: Chris Weathers ]
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No,

import SomeClass;
 
Chris Weathers
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Doh! Thanks... so import "somefile.java"?
 
Chris Weathers
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does SomeClass have to be compiled first?
 
James Carman
Ranch Hand
Posts: 580
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes.
 
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...although if it isn't, the java compiler will compile it for you. (Provided it can find the .java file in the right place; this is one of the driving reasons that packages and directory structures must match....)
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe you guys are wrong. import is not the c++ equivalent of #include, it is the c++ equivalent of using.

In c++ include tells the compiler where to look for a file containing functions, classes, enumerations, variables and such. In other words we need to include in order to use. java's import however is not necessary to use classes and stuff from a file. It only avoids the need for us to have to type the fully qualified name. What c++ programmers call polluting the namespace.

So the very important question remains. How to include a file, class or package in your Java project. How to make Java compiler aware of it.
 
Bartender
Posts: 2287
95
Eclipse IDE Google Web Toolkit Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi dan, welcome to code ranch, I hope you realize that you responded to a thread that's 14 year old. I am not sure if all the original posters are still active on code ranch.
 
Marshal
Posts: 64496
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But imports haven't changed in those fourteen years. More details n the Java® Language Specification.

Welcome again
 
dan forden
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is suspicious that your 14 year old thread is providing inaccurate information.
 
Campbell Ritchie
Marshal
Posts: 64496
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, imports without a package name were prohibited more than 14 years ago. I don't know what happened back in 2005.
 
Why is the word "abbreviation" so long? And this ad is so short?
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!