Solved

java classes

Posted on 2012-03-14
5
268 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 1

Expert Comment

by:nareshvoota
ID: 37723019
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
ID: 37723025
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
ID: 37723177
What version of net beans are you using?
0
 

Author Comment

by:jagguy
ID: 37723195
most recent 7.1
0
 
LVL 1

Accepted Solution

by:
nareshvoota earned 500 total points
ID: 37723269
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ejb wildfly example 2 72
Java Restore security prompts not working 10 129
Notify sent to other threads in Java 9 42
Eclipse with various Java releases 7 47
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…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

756 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