Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I would like to ask you about sentence: "In Java we run classes, not programs". Is it correct? I know the build process, but it seems to me that this sentence is ambiguous
(As this is so wide-open, let's make the answer a community wiki...)
I've never heard anyone say that (and would argue that it's so vague and slightly misleading you should ignore it).
Without context, it's hard to be too specific about what it's meant to mean, but it probably relates to the fact that many of the ways that Java programs are run involve a specific class that is the starting point.
For instance, if you're running a boring old program from the command line:
java DoSomething
...that's saying to run the main method in the DoSomething class.
Similarly, in an executable jar file, the manifest in the jar says which class to run the main from.
Similarly, a servlet is identified by a specific class implementing the appropriate interface and set up in the Java EE container's configuration.
But again, it's a really odd thing to say, not least because although the entry point may be a single class, of course that class then ends up using others to get its work done.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 days ago.
Improve this question
There are ways to get the details of the run time "-XX:" parameters passed to the JVM as some java code is compiled and executed and, of course, you also get the System.{getenv(), getProperties(), ...} and input parameters passed into the running instance from your code, but what kind of strategies or applications are being used to customize a running instance?
As part of my unit tests at times I need to marshall some data before passing it into my application and/or set up many different input parameters. I went monkey and included some name-protocolled files in "user.dir", "user.home" and one step below "java.home" as well as "user.name", the start time of the running application, ... to setup the name of my log files, decide if I wanted to redirect log System.{out or err} to files or having them dump the values on the screen ... instead to having to do this programmatically. I found a question asked 13 years and 8 months ago about these kinds of things:
Current directory in java properties file
I think in java you could use the reflection API to strategize a solution to those kinds of problems. Do you know of any application taking care of such issues or strategies used to deal with them?
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
I want to mutate a function of a class that is loaded at runtime (it has a bug in it but the project is long gone so i cannot build the binary). What i want to do instead is write a piece of code which will run during the application initialization phase and mutate this function so that it works fine. And simply keep that code around until the replacement is ready.
Having no experience with bytecode modification what library could i use to modify and reload a class at runtime? Specifically i need to replace a throw instruction with a noop instruction (i did this once using hex editor but lost the binary).
Also if you know any tutorial on how to do something like that please share.
I can see many libraries for doing this but i cant know which ones are good/bad do the job...
I think use Java Attach API. Java Attach API is procedure of loading a Java agent into an already running JVM. you can understand the work of javaagents by reading the Java Instrument javadoc. AgentMain help to you.
Agentmain is invoked when an agent is started after the application is already running. Agents started with agentmain can be attached programatically using the Sun tools API (for Sun/Oracle JVMs only -- the method for introducing dynamic agents is implementation-dependent).
This tutorial is useful about java instrumentation.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I am new to programming, so please bear with me; I will try to make my question as clear as possible. Responses are greatly appreciated as I am struggling quite a bit with the following question...
As you'll likely know,
"Inheritance [in Java] allows the compiled form of classes to be modified and/or extended. If a class is available that almost satisfies your requirements, you can adjust it..." (Dos Reis, 2012)
My question:
How do you compile a .java file containing a subclass who's class that is
Only available as a .class file
Outside the current working directory
I hope this is clear, and once again apologies beforehand for lacking the expertise to phrase this question more clearly.
Pretty simple: to the java compiler, it doesn't matter if a class comes as source or compiled.
The only thing: a compiled class needs to be on the class path of the javac invocation.
Keep in mind: any class inherits from java.lang.Object. You do not have Object in your source path. It only exists as class file in some JAR coming with your JDK!
In other words: when the compiler finds source code, it uses that. If not, it will check the classpath given to it and search for a compiled version of the class you intend to use.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
As the title says, with only using Java code, so no bytecode, is it possible to crash most of the general java decompilers, let's say the ones you find by googling "java decompiler"?
I am aware that this will not stop people from building a specific decompiler that gets around the issue, but it will surely keep people away from simply decompiling files.
I was thinking along the lines of the following silly piece of code which I hope to never meet in production:
final public class X {
//... interesting stuff
#Override
public String toString() {
return toString();
}
}
This could be a possible counter measure against people wanting to print out your object, as an example.
It depends on the implementation. It might crash if they don't recognize the latest byte code instructions, and it might crash if they can't figure out what to decompile your byte code instructions to. However in my experience when decompilers cannot figure out what to decompile the byte code to they will simply dump the byte code that they can't figure out within the rest of the Java source code they have already decompiled. A suggestion to attempt to see this is to decompile programs written originally in another JVM language like Scala or Clojure.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Okay, I know there are probably a dozen ways to solve this, but I am looking for either a skeleton app or some sort of tutorial that will explain the best way to write a framework for creating Java-based command-line tools. If my program requires a lot of switches/options/etc., what's the best way to handle all of them?
How do you decide which stuff should be placed into an options/settings file, and which stuff gets put on the command line? Any sort of sample code would be great, that way I can put my time more towards the central focus of my app rather than the command-line plumbing.
I also suggest looking at JCommander (http://jcommander.org/), written by the author of TestNG. I have used it successfully in many command line applications.
How do you decide which stuff should be placed into an options/settings file, and which stuff gets put on the command line?
There's no such dilemma, many things are useful in both places. With the settings file you let the user define defaults and with the command line you let the user override them. Of course, there are cases when only one of the two makes sense, but I'd take providing both as the starting point.
The previous answer seems to cover what you want to know for writing the app. As for your question about what should go in config files and what should be command line options I would recommend this. If the option is something that is likely to have the same value most of the time put it in a config. If its something that changes frequently make it an option, but remember options SHOULD be optional, try not to create a program that someone has to type in allot of required stuff to make it do it's base function.