Solved

java classes

Posted on 2012-03-14
5
260 Views
Last Modified: 2013-11-24
I am using netbeans to program Java.

Can I add classes to a separate file and import this .

Having classes all i  the same file makes for difficult reading
0
Comment
Question by:jagguy
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:nareshvoota
Comment Utility
I hope I am understanding your question right. You can put your classes in different packages.

For example,
Aclass.java file

package com.yourcompany.apackage;

public class Aclass {
    public void doNothing() {}
}

Bclass.java file

package com.yourcompany.bpackage;

import com.yourcompany.apackage.Aclass;

public class Bclass {
    public static void main(String[] args) {
        Aclass a = new Aclass();
        a.doNothing();
    }
}

Hopefully this helps.
0
 

Author Comment

by:jagguy
Comment Utility
yes that is what I want.
IN netbeans how do I do this as their is no add file/class to the project
0
 
LVL 1

Expert Comment

by:nareshvoota
Comment Utility
What version of net beans are you using?
0
 

Author Comment

by:jagguy
Comment Utility
most recent 7.1
0
 
LVL 1

Accepted Solution

by:
nareshvoota earned 500 total points
Comment Utility
I am attaching an example of how to creating projects, creating packages and creating classes.

To create classes or packages, right click on the project and hit new --> packages.

I used netbeans 7.1 IDE
1.createproject.png
2.testpackage.png
3.writeclassesindifferentfiles.png
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now