In my program I have a part which is called Sales Orders, it has GUIs, DAOs, property files and more and more.
I somehow want to find out all these classes and create new same functionality classes from them with a different name.
Actually it is like renaming all of them. I am using IDEA IntelliJ, but I can use some other IDEs also.
What is the fastest way to do this?
In Eclipse, you can simply select the file(s), copy them and then paste (without selecting anything else).
Eclipse will then notice that the files already exist and offer you a dialog where you can enter new names.
Alternatively, you can copy the .java files using your desktop (Explorer on Windows). IDEA will notice after a refresh and show a couple of errors (because the names of the files don't match the class names). It should then offer you quick fixes to rename the new classes to match the file name.
Related
I'm trying to understand the file structure in Netbeans.
For example: I want to create a new class. I do so by right clicking the navigation bar, and get prompted to name my new class. A warning appears with the words "It is highly recommended that you do not place Java classes in the default package"
So,
What does go in the "default package"?
What goes in the Test Packages and Test Libraries folders?
If I have some text files or some such thing for my program to read, where should they go?
I'm taking some online courses on Java, but these sort of nuances aren't covered in the classes. I want to start doing it right, right now, so I don't have to untangle all of my files later on down the road.
You should refresh your understanding by reading the tutorial.
The default package is a package that gets created for your project. It's OK to organize your files under the default package, but if your work is somewhat serious, you're going to want to place them under a named (and therefore non-default) package, like com.myorganization.myproject as per the tutorial. NetBeans will also allow you to refactor (rename) an existing package. Left click, hit F2 and supply a new name.
Test packages and libraries used to test your project go in the Test Packages and Test Libraries directories. It sounds like you're a ways off from testing with frameworks like JUnit, however, so you needn't concern yourself with those things just yet.
If you have arbitrary data files, you can really put them wherever you can find them later. If you're working with Android, for example, you'd have a /res directory just under your project root with resources like images, icons, data files, etc. You can create your own resources directory, or you can be lazy and dump them directly in the project root. Wherever you put them, you have to make sure you call them correctly using absolute or relative paths.
If you're using online courses, especially if you're paying for them, use the resources they provide, like live tutors or their forums. This kind of fundamental/tutorial help is a bit below the threshold for Stack Overflow.
I am about to transform(manipulate) a lot of classes and to allow easy debugging and transparent communication of the changes applied to the code, I want to add java source code equivalent of the manipulated class.
In order to add java code I would be able to use existing source code and manipulate it in parallel. Then I need to store it along with the class.
Visiting the class file format for JDK 8, I noticed that no attribute exists to directly embed source code. Remembering the old times it was possible to include the source code within a class file. What do I miss? (I only found the attribute for specifying a source file). Also the option in the compiler tab of Eclipse does only show options to embed file names... .
Beside seaming to store source files separately, I wonder if it is feasible to reverse engineer (decompile) the class file. If one provide information about local names and parameter names, this might even be a better option.
The ASM documentation stated out that a tool is available to even decompile byte code.
Does anyone has some insights or experiences to share on this matter?
For Example, i just have a bunch of classes sitting out there for my game. Some are drawable, nondrawable, animated sprites, and more.
I just want to know if I right-click my package and add a folder.. drop some classes into it, will it disable my program? I know in XNA it worked like that because you had to give the path. I am unsure in android.
Thanks guys and GALS
*Edit (included GALS)
No, adding folders and new classes will not affect your program (unless you're doing some processing that depends on your class hierarchy structure staying constant, which is not very common). However, if you move existing classes to different folders, you will also need to change the package statement in each source code file that you moved, as well as all references to these classes.
If you want to reorganize your class files, the refactoring capabilities in Eclipse will help you with this; you can move a class using the refactoring tools, and Eclipse will update all references automatically.
I need to ship some Java code that has an associated set of data. It's a simulator for a device, and I want to be able to include all of the data used for the simulated records in the one .JAR file. In this case, each simulated record contains four fields (calling party, called party, start of call, call duration).
What's the best way to do that? I've gone down the path of generating the data as Java statements, but IntelliJ doesn't seem particularly happy dealing with a 100,000 line Java source file!
Is there a smarter way to do this?
In the C#/.NET world I'd create the data as a separate file, embed it in the assembly as a resource, and then use reflection to pull that out at runtime and access it. I'm unsure of what the appropriate analogy is in the Java world.
FWIW, Java 1.6, shipping for Solaris.
It is perfectly OK to include static resource files in the JAR. This is commonly done with properties files. You can access the resource with the following:
Class.getResourceAsStream ("/some/pkg/resource.properties");
Where / is relative to the root of the classpath.
This article deals with the subject Smartly load your properties.
Sure, just include them in your jar and do
InputStream is = this.getClass().getClassLoader().getResourceAsStream("file.name");
If you put them under some folders, like "data" then just do
InputStream is = this.getClass().getClassLoader().getResourceAsStream("data/file.name");
I'm trying to bind in a third party app to our project but have discovered that the unix paths of their property files have been hard-coded into several classes. It is probably possible to make minimal changes to their setup, so my question is: what are the possible (and quickest) ways to achieve this? The third party app uses neither ant nor spring, but just a build script that compiles the code into a .jar that is called from the command line.
You could read the properties files as resources. Then you only have to put the directories containing these files into your classpath.
You haven't actually said what you want to achieve. Would your application determine some paths and pass them to third party app via an API? Would something in your environment (for example a command line argument) specify the location of the files?
I would first refactor their code so that I know for certain that any hard coded strings are held in one defined place. So if for example they have
readProperties("/usr/thing/propertyFileXxx.txt");
or
static final String PROPERTY_XXX = "/usr/thing/propertyFileXxx.txt";
readProperties(PROPERTY_XXX);
I would first consolidate to a single accessor for the properties
readProperties(PROPERTY_XXX_ENUM);
So now we have a well-defined single piece of code that determines where to obtain the properties of each type and a specific list of the types of properties.
Then we need some controllable way to define the set of property files to be used at run-time. I have used the idea suggested by #tangens of loading the properties as resourcees from a specific directory added to the classpath.