Solved

java classes

Posted on 2012-03-14
5
267 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
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 212
Oracle SQL syntax check  without executing 6 75
Java string replace 11 54
swing controls 2 16
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…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

856 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