Question:
Question About Packages in Java Programming. Specifically the 'org.myorg' Package?
Kurtis
2011-06-15 06:55:02 UTC
I'm learning how to write Hadoop MapReduce jobs in Java. To help me learn I've been looking online for tutorials and every tutorial site I find has sample code that requires the importing of a package from "org.myorg". The first line of code in every bit of sample code is "package org.myorg;". I keep getting an error because I don't have that package. Where can I download it?

Example Tutorial:
http://hadoop.apache.org/common/docs/r0.17.2/mapred_tutorial.html

Thanks!
Three answers:
Vaibhav
2011-06-15 08:34:05 UTC
the above answer is right

with his example your package is in training directory

one more thing to compile the program using command prompt you need to switch current directory to training then issue command

javac org.myorg.WorldCount.java

and in same way run the compiled file
R.F.
2011-06-15 08:03:20 UTC
The package statement at the top of the the java program is not an import statement.



It indicates the relative directory path, or "package" that the current program is in.



So the Java class name in the example on that page is "WordCount".

That means the Java source program file name has to be "WordCount.java"



The "package org.myorg;" statement at the top of the program means the Java class is located in this directory:

org/myorg



And your program file is here:

org/myorg/WordCount.java



So when you recreate this program, it has to be in that directory.

This is a relative directory.

That means the "org" root path can be located anywhere within your java path.



For example, if you are writing your java programs in:

C:\Java\training

You could put the package path in:

C:\Java\training\org\myorg



The other thing is "org.myorg" or "org/myorg" is a path you create. It doesn't have to be those words. Just make sure the relative directory path and the package name matches.
?
2016-02-29 06:38:56 UTC
Remove statement "package book" in the second prgm... create a Folder naming "cert".. for ex.. I have created a folder "cert" in E:\ Then save the file Sludge.java in E:\cert\Sludge.java then compile the Sludge.java i.e: E:\>cert\javac Sludge.java then save the file goo.java in E:\> then compile and run the goo.java as E:\>javac goo.java E:\>java goo Your Output: Sludge Hello World!


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...