• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Help with Netbeans. need to use an external class in a piece of code.

 
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so for an assignment we have been given a class, named comp.
It has been given as text. i guess the idea was (if using comand prompt, to save as a .java file then compile it and as a class file in the same directory we are using, and i think it is then use an "!" when it is called, still abit hazy on that way of doing it.
however I need to do it in net beans IDE as it is all I have available at home i have saved as a java file then copied the source package into my working file so it has 2 source files...
This has obviously not worked and google is being no use.
could somebody please help me out with an guide a newbie could understand?
Thank you very much all
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

No, if you have NetBeans working at home, you will also have the standard JVM working. NetBeans doesn't come with its own runtime, but uses the Java® code already installed on your computer. You shou‍ld be able to use Java® from the command line if you can compile something with NetBeans. You may have to set a System PATH and JAVA_HOME. Please run the following commands at the command line and see what the outputs are:-

where java
java -version
where javac
javac -version
echo %JAVA_HOME%
echo %PATH%

What is that about bang signs (!)? I don't remember ever using a bang sign at the command prompt. Something has given you misinformation. Maybe you shou‍ld remind yourself about how to run your first program.
 
Stan Austin
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using NetBeans IDE 8.1 im pretty sure it has its own runtime environment as it is all compiled and run within the self contained program.
also the bang sign isnt in the command line it is within the program such as !Std.In or !Std.out, when those ".class" files are stored in the same directory.
an i tried to do your where java stuff
I has a location and version for java
but javac could not be found

C:\WINDOWS\system32>where java
C:\ProgramData\Oracle\Java\javapath\java.exe

C:\WINDOWS\system32>java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)

C:\WINDOWS\system32>where javac
INFO: Could not find files for the given pattern(s).

C:\WINDOWS\system32>javac -version
'javac' is not recognized as an internal or external command,
operable program or batch file.

C:\WINDOWS\system32>echo %JAVA_HOME%
%JAVA_HOME%

C:\WINDOWS\system32>echo %PATH%
C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\ATI Technologies\ATI.ACE\Core-Static;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files (x86)\Microsoft ASP.NET\ASP.NET Web Pages\v1.0\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files (x86)\Windows Kits\8.1\Windows Performance Toolkit\;C:\Program Files (x86)\Windows Live\Shared;C:\Program Files\Intel\WiFi\bin\;C:\Program Files\Common Files\Intel\WirelessCommon\;C:\Program Files (x86)\AMD\ATI.ACE\Core-Static;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x86;C:\Program Files (x86)\Intel\OpenCL SDK\2.0\bin\x64;C:\Users\shott_000\AppData\Local\Microsoft\WindowsApps

 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you have the code for a java program (as a text file) and you want to put it into your Netbeans IDE?
I am presuming the code is some sort of library for you to use when doing the assignment.

My suggestion would be to just use Netbeans for it - forget the command line.

- Create a new Java class in Netbeans, the same way you always do
- Copy/paste the code from the text file provided into the Netbeans IDE.

Netbeans should then compile it and make it available to you.
 
Stan Austin
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stefan Evans wrote:So you have the code for a java program (as a text file) and you want to put it into your Netbeans IDE?
I am presuming the code is some sort of library for you to use when doing the assignment.

My suggestion would be to just use Netbeans for it - forget the command line.

- Create a new Java class in Netbeans, the same way you always do
- Copy/paste the code from the text file provided into the Netbeans IDE.

Netbeans should then compile it and make it available to you.



Yes so i am trying to just use NetBeans as i have no idea how to write in NetBeans, and run in command line.
and so i have pasted it into NetBeans, and created my program it runs etc. however... this program was given to us and we need to call function that are held within it... and maybe some of the main (not too sure yet as i cant get it configured) in a separate program, the issue is i cant call the other program, even if i put it in the same folder etc. i did attempt to put the code in the same program but then had two mains and all  sorts of other issues.

long story short, need to write a program in NetBeans that calls a given program I can only paste in NetBeans...
 
Stefan Evans
Bartender
Posts: 1845
10
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So lets assume
Comp.java is the library provided
myHomework.java is the class you are writing.

The project should look something like:



One project with two classes side by side (presumably in the same package if you are using packages

Within the MyHomework depending on what the Comp class has in it it might look like this:

If Comp has static methods:


or maybe like this if you need to build an instance, and call methods on it.


At this point, I think I'm going to have to ask for a code example.
What does the provided code look like? l
What does your code look like?
 
Stan Austin
Ranch Hand
Posts: 50
1
Netbeans IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much Stefan, this was very helpful and had solved my problem.
it was as simple as copying the Comp.java file to the source package inside its own Comp package.
Removing it from its own package and putting it inside the myHomework package as shown in your example was all it took.
as always when i ask for help on this forum i feel slightly foolish but very relieved.
Thanks again
 
Stefan Evans
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, if you don't feel like that, then you haven't learned anything :-)
Glad to hear it is working for you.


Just a quick followup to ensure you don't make your assignment null and void.
It would be better if you used Comp.java exactly as provided.   Did you have to change anything to put it with your class (or did the ever helpful IDE change something for you? )

You can quite easily access classes in other packages - as long as your own class is in a package.
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Stan Austin wrote:I'm using NetBeans IDE 8.1 im pretty sure it has its own runtime environment as it is all compiled and run within the self contained program.

It doesn't. when you download the package, the JDK is part of that package, so using that package to install NetBeans also installs the JDK. You can of course install NetBeans Eclipse or IntelliJ independently.


also the bang sign isnt in the command line it is within the program such as !Std.In or !Std.out, when those ".class" files are stored in the same directory.

There is no such thing as Std.In or Std.out in the standard Java® installation; those are terms similar to those used for C/C++ coding. In Java®, the standard input stream is called System.in and the standard output stream is called System.out.
If you are using bang signs there, the bang sign is pronouced “not”, and means logical negation. You cannot simply use !Std.in, but you can use something like if (!Std.in.hasNextInt()) ... which means you are testing whether whatever is behind Std.in has a next int available. Maybe you have been provided with a class which uses a Scanner to read things from System.in. If so, that is a good idea. Maybe that is the class you are supposed to compile.
Obviously, if you don't have a next int at Std.in, you will have to take some action to get rid of the current input and get an int instead. Since I don't know anything about the Std.in object, I can't say any more about that at present.


an i tried to do your where java stuff
I has a location and version for java
but javac could not be found

That is exactly the information you needed. If you go through the first part of the Java® Tutorials, you will find that error message in the “Common Problems” section. It is caused by not updating the PATH system environment variable when you installed Java®. If you go through the first program link I gave you yesterday, you will find information about setting the PATH and JAVA_HOME variables. I believe you need JAVA_HOME for NetBeans. You might have already configured NetBeans with a correct JAVA_HOME, in which case NetBeans might work and the javac instruction not work at the command line. You would want something like C:\Program Files\Java\jdk1.8.0_111 for JAVA_HOME and add %JAVA_HOME%\bin; at the beginning of the current PATH. You may need to enclose the JAVA_HOME text in "quote" marks.
Don't work inside a Windows® system folder. Try the following command from the default location when you open your command prompt:-Then you can go to your java folder every time you open a command prompt with line 2 of that instruction.

I am going to change the code tags to quote tags because your PATH is too long to read in one line.
 
If you believe you can tell me what to think, I believe I can tell you where to go. Go read this tiny ad!
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic