This question already has an answer here:
Deciphering variable information while debugging Java
(1 answer)
Closed 4 years ago.
When using Intellij's debugger, the variables in scope are displayed using a 4 digit identifier, marked in red in the following screenshot.
This identifier seems to be calculated based on the object's identity.
What exact code is used to get the 4 digit number for a given object instance?
I don't think you should rely on that id being calculated in any special way. It's internal to IDEA (or JVM) and I don't think it holds any relevance except to track objects during execution.
However, I find it useful to name objects during debug. I believe the shortcut is F11 (click once on the object in debug window first) and just give it a name that is meaningful for you during debugging. That object will always hold that name during the current session of debugging.
Related
This question already has an answer here:
Deciphering variable information while debugging Java
(1 answer)
Closed 6 months ago.
The "#" seems to be everywhere when I debug. They are always preceded by some instance/variable name and followed by a (usually three digits) number. What does it mean? I have an image below
Taken from https://medium.com/#andrey_cheptsov/intellij-idea-pro-tips-6da48acafdb7 .
#730 means the 730th object created since the application started.
It is not the hashcode. Length of this can be more or less than 3 digits.
It's totally depends upon which IDE you are using, may eclipse will give something else instead of #730 and in different format also, so it is the way of intellij to maintaining the debugging.
This is Intellij debugger's way of displaying a "unique identifier" for an object. It consists of the short classname and a unique number. The unique number seems to be generated using a simple counter, so the "meaning" of 729 in Owner#729 is (presumably) "this is the 729th object that the debugger has allocated an identifier for". However, you probably shouldn't rely on that.
There is no overt relationship between these numbers and Java identity hashcode values, though I expect Intellij maintains a mapping behind the scenes.
The Owner#5f9d02cb in the screenshot is reminiscent of the result of Object::toString ... when it hasn't been overridden. If that it is what it is, then the 5f9d02cb will be the object's identity hashcode.
I am implementing a simple MIPS simulator using java. My problem is in the fetching instruction step where I should take one instruction and convert it to 32-bit binary code to be able to determine that the first 6 bits are the opcode and the next 5 are the rs(source register) and so on.
At first I thought I would just make an arraylist and add the 15 instructions my program is going to support and then make another arraylist and add the 32 registers available and then when the user enters his code I loop on the entered string comparing it with my instructions and registers names in the arrays, but then I realized I don't know which characters exactly I am going to compare from the users code I mean (add $s1 $s4 $s5) will be different from (addi $t8 $zero 1) so I can't just check the substring of the first 3 characters every time with the instructions array and then check the next 3 because as you see the zero register might take a larger place and so on.
My second approach is to define the instructions by their opcodes and the registers by their binary values then convert the given instruction by the user to binary and compare it. Is there any other possible or probably easier ways to do so?
If I understand you right, your question is how to get from the user's assembler code to the machine code that is interpreted by your MIPS. This is where tokenizers come in handy. Use a StringTokenizer (http://docs.oracle.com/javase/7/docs/api/java/util/StringTokenizer.html) to convert user input into a string of byte code and feed the latter one to your MIPS exactly how you propose in your question.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Plural form of a word
Is there some existing class or library for adding "s" to a String if I pass it a number that's not 1? Basically, I have a cat. If I have 1 cat, I need the String "cat". If I have 2 cats, I need the String "cats". It's a simple thing to do myself, but after I did it, I thought there's probably already a library I could import for it. However, as you can see, I am having difficulty putting this into words to Google a name for the package, if it exists. :P It's just that I write this function all the time, I'm wondering if it exists already.
Pluralizing is probably simple enough, with the exception of the list of words like "cactus" or "tooth" that are somewhat special cases, that you don't need an entire API or you can implement yourself. If you really don't want to have a stab at it, there are things like the Inflector library that can do it for you. There are probably others, if you search for "java pluralize".
Javadocs for Inflector here: http://www.atteo.org/static/evo-inflector/apidocs/index.html
Really I'm doing just time words (seconds, minutes, hours) ...
If you have a small / fixed set of words, it is probably simpler to use a static lookup table or something like that. A general solution is too heavy-weight, IMO.
The Title is self explanatory. This was an interview question. In java, List is an interface. So it should be initialized by some collection.
I feel that this is a tricky question to confuse. Am I correct or not? How to answer this question?
Assuming you don't have a copy of the original List, and the randomizing algorithm is truly random, then no, you cannot restore the original List.
The explanation is far more important on this type of question than the answer. To be able to explain it fully, you need to describe it using the mathematical definitions of Function and Map (not the Java class definitions).
A Function is a Map of Elements in one Domain to another Domain. In our example, the first domain is the "order" in the first list, and the second domain is the "order" in the second list. Any way that can get from the first domain to the second domain, where each element in the first domain only goes to one of the elements in the second domain is a Function.
What they want is to know if there is an Inverse Function, or a corresponding function that can "back map" the elements from the second domain to the elements in the first domain. Some functions (squaring a number, or F(x) = x*x ) cannot be reversed because one element in the second domain might map back to multiple (or none) elements in the first domain. In the squaring a number example
F(x) = x * x
F(3) = 9 or ( 3 -> 9)
F(12) = 144 or ( 12 -> 144)
F(-11) = 121 or (-11 -> 121)
F(-3) = 9 or ( -3 -> 9)
attempting the inverse function, we need a function where
9 maps to 3
144 maps to 12
121 maps to -11
9 maps to -3
Since 9 must map to 3 and -3, and a Map must have only one destination for every origin, constructing an inverse function of x*x is not possible; that's why mathematicians fudge with the square root operator and say (plus or minus).
Going back to our randomized list. If you know that the map is truly random, then you know that the output value is truly independent of the input value. Thus if you attempted to create the inverse function, you would run into the delimma. Knowledge that the function is random tells you that the input cannot be calculated from the output, so even though you "know" the function, you cannot make any assumptions about the input even if you have the output.
Unless, it is pseudo-random (just appears to be random) and you can gather enough information to reverse the now-not-truly random function.
If you have not kept some external order information (this includes things like JVM trickery with ghost copies), and the items are not implicitly ordered, you cannot recover the original ordering.
When information is lost, it is lost. If the structure of the list is the only place recording the order you want, and you disturb that order, it's gone for good.
There's a user's view, and there's internals. There's the question as understood and the question as can be interpreted.
The user's view is that list items are blocks of memory, and that the pointer to the next item is a set of (4?8? they keep changing the numbers:) bytes inside this memory. So when the list is randomized and the pointer to the next item is changed, that area of memory is overriden and can't be recovered.
The question as understood is that you are given a list after it had been randomized.
Internals - I'm not a Java or an OS guy, but you should look into situations where the manner in which the process is executed differs from the naive view: Maybe Java randomizes lists by copying all the cells, so the old list is still kept in memory somewhere? Maybe it keeps backup values of pointers? Maybe the pointers are kept at an external table, separate from the list, and can be reconstructed? Maybe. Internals.
Understanding - Who says you haven't got an access to the list before it was randomized? You could have just printed it out! Or maybe you have a trace of the execution? Or who said you're using Java's built it list? Maybe you are using your own version controlled list? Or maybe you're using your own reversable-randomize method?
Edwin Buck's answer is great but it all depends what the interviewer was looking for.
The following list contains 1 correct word called "disastrous" and other incorrect words which sound like the correct word?
A. disastrus
B. disasstrous
C. desastrous
D. desastrus
E. disastrous
F. disasstrous
Is it possible to automate generation of wrong choices given a correct word, through some kind of java dictionary API?
No, there is nothing related in java API. You can make a simple algorithm which will do the job.
Just make up some rules about letters permutations and doubling and add generated words to the Set until you get enough words.
There are a number of algorithms for matching words by sound - 'soundex' is the one that springs to mind, but I remember uncovering a few when I did some research on this a couple of years ago. I expect the problem you would find is that they take a word and return a value that represents how the word sounds so you can see if two spellings sound similar (so the words in the question should generate similar values); but I expect doing the reverse, i.e. taking the value and generating similar sounding spellings, would be quite hard.