Java Class Files filename$1.class... etc Question [duplicate] - java

This question already has answers here:
What is the $1 in class file names?
(6 answers)
Closed 8 years ago.
After successfully creating some applets, I embedded them in a webpage and discovered that ALL the class files must be included. Leave one out and it won't work.
After several iterations of an Applet, there are several class files:
filename.class
filename$1.class
filename$2.class, etc.
I tried using only the filename.class, tried just the last one, tried the first and last... but, as I said, all the class files must be included for the webpage.
Question(s):
1) The filename$n.class (n=some number) files seem to be created at the whim of Eclipse - is there an explanation of this (I searched w/o success)?
2) Even though the class files are only ~4kb, How do I do a cleanup such as to blow away all the filename$n.class files and still be able to embed in a webpage?
Any recommendations?
Thanks

These classes are created from anonymous classes created in your applet - most likely event listeners and such.
They would be created (maybe with other names) by other compilers, too.
If you really want to avoid them, program without anonymous (and other inner) classes. But this results often in an ugly style, so this is not recommended.
If you don't want to upload all the individual class files to the server (and then the browsers having to fetch them all individually), think about putting them all in one jar file, and referencing this in your applet-tag.

Related

Split a zip file into multiple files files using java [duplicate]

This question already has answers here:
How to break a file into pieces using Java?
(2 answers)
Closed 11 months ago.
Hello I need to split a zip file into multiple samaller files,
ex. file.zip is splitted into files with fixed size less than 640MB and format nameOfZip.zip.001
I am currently looking for some kind of a java library that would be able to do this. If there is no such, advice would be very helpful too.
Zip, the format, can do this. You can then unzip the batch of files with plain jane unzip on the command line (or with tools like p7zip and such, or you can just doubleclick the zip on a mac, etcetera).
Unfortunately, the baked in zip support in java can't make split zips. But, Lingala / Zip4j can do it.
Add that library to your list of dependencies and use its API (forget about java.io.ZipOutputStream, or the Zip FileSystem - anything that starts with java.* can't do this.
Alternatively it is trivial to write code in java to just split any file. You'd need to write java code as well to put them back together, or you need to know a few things about your OS to do this (e.g. cat a.bin b.bin >c.bin on posix OSes will put a.bin and b.bin back together). This isn't difficult at all, just your basic file and outputstream support can trivially put it together in less than a page's worth of java code. No libraries exist, and probably never will - that is a very simple task that isn't common enough to make a library for.
So, if that's what you're looking for, go ahead and write it yourself. All you need is the javadoc of java.nio.file.Paths and java.nio.file.Files.

Refer to class outside jar/war file

Is it possible that we keep our jar/war file running and one class file in the same directory which can be referred from jar/war? The requirement is I want to keep some common code in single file which can be referred by multiple running jars/wars and I don't have to re-deploy application if I can successfully just change the class file.
I would go for this question here: How should I load Jars dynamically at runtime?
And them try the answers from jodonnell, chris and allain-lalonde depending on how do you want to access these class files, if by URL or by file path, and if you want to use JAR files or CLASS files.
In any case you should try and see it for yourself if it fits your needs and is acceptable by your employer standards. At certain point, we need to think out of the box. Don't worry if one or other user dislikes this or that approach. This community if meant for ask and receive answers on how to do it, and not to not do it.

How to access class' javadoc programmatically? [duplicate]

This question already has answers here:
How to get a JavaDoc of a method at run time?
(5 answers)
Closed 7 years ago.
I would like to display some text before service class run. This text could be HTML, generated from class' javadoc. Is it possible to access/generate it from class itself?
Now with Java 8 you have a whole interface to play with comments and documentation. Check this package com.sun.source.doctree
You need access to the source code files to be able to read comments. If you don't have access (which is most likely the case if you want to read the comments at runtime) you will have to use another solution, like providing the text as a string or resource file.
It's possible to get comments using the Java Compiler API. See: How to access comments from the java compiler tree api generated ast?. The problem here is you still need to know where the source code files are located on the system, if they are even there at all.
Another solution is to use an annotation processor. It has the advantage that it provides you with an abstract representation of the source code without the need to manually read files. You would need to identify the class you want to read the comments from and then use Element.getDocComment.

Why cant we modify R.java? [duplicate]

This question already has answers here:
R.java can't be modified
(2 answers)
Closed 9 years ago.
I have read in several places that we shouldn't modify R.java. My question is why shouldn't we modify R.java?. What is so important about those Ids that they should not be modified?
R.java is an auto generated file contains all your resources used in project. If you want to change R.java you can't.
You have to add or delete resources, then it will be modified according to your resources present in project.
This is basic thing in Android. You have to read Android Developers documents, then you will get good knowledge about it.
Courtesy :R.java can't be modified
This is a generated file. It contains all references to your ids you defined in your xml files, to your drawables, strings, etc. Therefore it makes no sense to modify this file!
This also means that all your changes will be gone when the file is generated the next time (e.g. when you add an id)

Write to hidden files in Java [duplicate]

This question already has answers here:
Modify a hidden file in Java
(2 answers)
Closed 10 years ago.
I have a problem with my hidden files in Java. I would like to write to a hidden txt file but it always says "access denied".
My suggestion would be to make the file visible, write into it and then make it hidden again.
But how can i make a hidden file visible?
I previously said: The problem is not that the file is hidden. The problem is that your program doesn't have write access for the file. Making it "unhidden" is unlikely to help.
It seems that it is more complicated than that for Windows. Certainly it is worth trying to "unhide" the file before modifying it.
Anyway, if you are using Java 7, the way to read and write Windows-specific file attributes is to use the java.nio.file.Files API, and specifically the getFileAttributeView(...) method. For older versions you will either need to use an external utility (see #Achintya Jha's Answer) or use a JNI / JNA wrapper to call a Windows native API.
If you are using Linux, change Windows-specific to POSIX and/or Linux specific. (Note that a lot of this stuff to do with file attributes and permissions is intrinsically OS specific.)
Finally, if the problem is that the program doesn't have write access to the file, there is a fair chance that there is nothing that it can do to get write access.

Categories

Resources