How to access class' javadoc programmatically? [duplicate] - java

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.

Related

how to get java docs attached to my java projects? [duplicate]

This question already has answers here:
How to solve "This element has no attached source and the Javadoc could not be found in the attached Javadoc"?
(9 answers)
Closed 8 years ago.
How to get ino about the Java classes and methods. when I use the auto Assist to add a method or interface normally in Android I receive ino about them, but when I use java it seems the javadocs attached to my java proojects are not existing ad i always receive the below message
please let e know how to solve this.
Note: This element neither has attached source nor attached Javadoc and hence no Javadoc could be
found.
In the source code, place caret on the class with the missing javadoc, and press F3.
Then you will see
From here you wil lbe able to add the javadoc.
If you are in eclipse, locate the .jar in the JRE System Library under your project. Right Click -> Javadoc Location. Download the docs and specify the location of the archive.

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.

how can I download a file using Java? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How do you Programmatically Download a Webpage in Java
How to download a file using java. So for example, I want to construct a program which will take some input e.g the website download. and then download the file. Please note that I am not looking for the code or anything. I just want to be pointed in the correct direction and that's it.
If you want to download a file from a URL, have a look at java.net.URLConnection.
Have a look at this Stack Overflow question:
How do you Programmatically Download a Webpage in Java
By using HttpURLConnection (better than java.net.URLConnection IMHO)
URLConnection.getInputStream() is what you're looking for. Moving the actual bytes is a bit tedious and error-prone, so if you just want to get it done, using an existing, tested implementation like FileUtils from Apache commons IO would be the best idea.

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

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.

Categories

Resources