I'm using NetBeans at the moment.
My professor showed us how we can create a class without any Main method and a list of useful stuff i can use on all my projects. I tried to do the same thing at home but i can't figure out how to make it work.
I wanted to start to code and grow my own library as long as i complete exercises for the class so the inability to achieve this is grinding my gears ahah.
Basically, i create a library project called A, add my ".java" files and when i try to use the project A inside my project B i can't manage to accomplish stuff. I don't even know how to import or call my methods from the library and google is not helping me, it's frustrating.
This will clear everything up:
FilsLibrary is my project without Main method. LproEsercizi is the project in which i want to be able to use my library methods. i right click the "libraries" folder, add the project and that's it. I can't figure out how to continue. Help please
Tim Moores wrote:My advice is: forget about NetBeans for the moment. It is a complex piece of software that takes time to master. You're better off learning Java instead. Use a programmer's editor to write the code, and the command line to compile and run it.
That's not an option. Use use Netbeans in class and during exams.
Other methods you might want in a utility class might swap two elements in an array, or sort an array. The most useful utility class might be one for reading from the keyboard with a Scanner object.
1. Right click the Libraries folder of the project i want to add my utility classes to.
2. Select the option "add project" and from the list i choose the "FilsLibrary" project which is the project with my utility classes containing useful methods.
I remember our professor telling us this, and nothing else so i'm kinda blocked. Now i'd like to use the methods in "FilsLibrary" and import the file so i'm actually able to use them but i don't know how.
This is the current folder i'm working on:
And basically what i don't understand how to do is this (check the uppercase comments):
Dave Tolls wrote:
OK, at the top of your class you would import the class(es) you want to use...just as the code currently imports the Scanner class.
In the code you would then use them.
I posted in 'beginning java' because i'm a beginner. I don't know how to do that. I'm asking for help.
This is my utility class:
This is my project where i want to use the method 'sumTwoIntegers':
I have no idea what's wrong.
Junilu Lacar wrote:Maybe this will help you: https://netbeans.org/kb/73/java/project-setup.html?print=yes#projects-dependencies
Everything should work properly, i did exactly what's written in that part of the page. I seriously can't comprehend what's wrong :/
Dave Tolls wrote:What error(s) is it giving you?
i get a " '.' expected " error.
Meanwhile, in the
line i get a "Cannont find Symbol Test1" error.
Edit: The clue that the compiler gives you is when it reports "." expected in your import Test1; statement. The compiler thinks that Test1 is a package name, not a class name.
Filipe Madureira wrote:Yes! Now it's working properly! Thank you so much <3. To be honest i'm quite confused about what packages are and why i needed one, i'll look into it now.
Packages are just a higher level of organization. A package normally contains a number of related classes. Look over the standard Java Library API Documentation to see how classes are organized into different packages to get a sense of how you'd want to do it for your own programs.