Ever wondered how the JVM debugger 'Evaluate' feature works in IDEs? Long ago I thought that the Java debug interface (JDI) actually allows you to specify the expression and get back its value.

However, this is not quite possible: there's no Java language compiler inside the JVM. When the process is paused JDI allows you to read or write any variables and fields or even execute an existing method with given arguments. But nothing like addition or multiplication.
On the other hand, #IntelliJIDEA debugger allows you to evaluate even statements! You can write there `for`, `if`, `while`, `switch` - whatever. You can even declare local variables. So how this works?
The answer is simple: IDEA debugger has a built-in interpreter for Java! If you access an existing variable or a field, call a method or instantiate an object, it queries JDI. Otherwise, IDE itself does all the calculations.
The amusing thing is that debugger authors didn't bother to make it as strict as Java itself, so the language inside the interpreter is a much more permissive version of Java. For example, you don't need to initialize variables there! Default values like 0 are used automatically.
Of course, final variables could be changed. Why artificial limitations?
Another thing: most of the casts are not necessary. This interpreted Java more resembles dynamically typed languages like JavaScript. Duck-typing works: if there's a method, we can call it. Even if the highlighter complains.
Switch statements and expressions are more permissive there: you can switch over any type. Also, no default is necessary for switch expressions. If it's not visited, the evaluation will be successful.
In addition to use any type, you can use any expressions as case labels, not just constants! The first matching branch will be executed.
Finally, even if your project still uses Java 6 JDK, it doesn't stop you from using new language features. For example, 'var' declarations and patterns in instanceof work perfectly, because they are interpreted by IDE, not by your JDK. Just ignore error messages!

More from Tech

You May Also Like

॥ॐ॥
अस्य श्री गायत्री ध्यान श्लोक:
(gAyatri dhyAna shlOka)
• This shloka to meditate personified form of वेदमाता गायत्री was given by Bhagwaan Brahma to Sage yAgnavalkya (याज्ञवल्क्य).

• 14th shloka of गायत्री कवचम् which is taken from वशिष्ठ संहिता, goes as follows..


• मुक्ता-विद्रुम-हेम-नील धवलच्छायैर्मुखस्त्रीक्षणै:।
muktA vidruma hEma nIla dhavalachhAyaiH mukhaistrlkShaNaiH.

• युक्तामिन्दुकला-निबद्धमुकुटां तत्वार्थवर्णात्मिकाम्॥
yuktAmindukalA nibaddha makutAm tatvArtha varNAtmikam.

• गायत्रीं वरदाभयाङ्कुश कशां शुभ्रं कपालं गदाम्।
gAyatrIm vardAbhayANkusha kashAm shubhram kapAlam gadAm.

• शंखं चक्रमथारविन्दयुगलं हस्तैर्वहन्ती भजै॥
shankham chakramathArvinda yugalam hastairvahantIm bhajE.

This shloka describes the form of वेदमाता गायत्री.

• It says, "She has five faces which shine with the colours of a Pearl 'मुक्ता', Coral 'विद्रुम', Gold 'हेम्', Sapphire 'नील्', & a Diamond 'धवलम्'.

• These five faces are symbolic of the five primordial elements called पञ्चमहाभूत:' which makes up the entire existence.

• These are the elements of SPACE, FIRE, WIND, EARTH & WATER.

• All these five faces shine with three eyes 'त्रिक्षणै:'.
I’m torn on how to approach the idea of luck. I’m the first to admit that I am one of the luckiest people on the planet. To be born into a prosperous American family in 1960 with smart parents is to start life on third base. The odds against my very existence are astronomical.


I’ve always felt that the luckiest people I know had a talent for recognizing circumstances, not of their own making, that were conducive to a favorable outcome and their ability to quickly take advantage of them.

In other words, dumb luck was just that, it required no awareness on the person’s part, whereas “smart” luck involved awareness followed by action before the circumstances changed.

So, was I “lucky” to be born when I was—nothing I had any control over—and that I came of age just as huge databases and computers were advancing to the point where I could use those tools to write “What Works on Wall Street?” Absolutely.

Was I lucky to start my stock market investments near the peak of interest rates which allowed me to spend the majority of my adult life in a falling rate environment? Yup.
राम-रावण युद्ध समाप्त हो चुका था। जगत को त्रास देने वाला रावण अपने कुटुम्ब सहित नष्ट हो चुका था।श्रीराम का राज्याभिषेक हुआ और अयोध्या नरेश श्री राम के नेतृत्व में चारों दिशाओं में शन्ति थी।
अंगद को विदा करते समय राम रो पड़े थे ।हनुमान को विदा करने की शक्ति तो राम में थी ही नहीं ।


माता सीता भी हनुमान को पुत्रवत मानती थी। अत: हनुमान अयोध्या में ही रह गए ।राम दिनभर दरबार में, शासन व्यवस्था में व्यस्त रहते थे। संध्या को जब शासकीय कार्यों में छूट मिलती तो गुरु और माताओं का कुशल-मंगल पूछ अपने कक्ष में जाते थे। परंतु हनुमान जी हमेशा उनके पीछे-पीछे ही रहते थे ।


उनकी उपस्थिति में ही सारा परिवार बहुत देर तक जी भर बातें करता ।फिर भरत को ध्यान आया कि भैया-भाभी को भी एकांत मिलना चाहिए ।उर्मिला को देख भी उनके मन में हूक उठती थी कि इस पतिव्रता को भी अपने पति का सानिध्य चाहिए ।

एक दिन भरत ने हनुमान जी से कहा,"हे पवनपुत्र! सीता भाभी को राम भैया के साथ एकांत में रहने का भी अधिकार प्राप्त है ।क्या आपको उनके माथे पर सिन्दूर नहीं दिखता?इसलिए संध्या पश्चात आप राम भैया को कृप्या अकेला छोड़ दिया करें "।
ये सुनकर हनुमान आश्चर्यचकित रह गए और सीता माता के पास गए ।


माता से हनुमान ने पूछा,"माता आप अपने माथे पर सिन्दूर क्यों लगाती हैं।" यह सुनकर सीता माता बोलीं,"स्त्री अपने माथे पर सिन्दूर लगाती है तो उसके पति की आयु में वृद्धि होती है और वह स्वस्थ रहते हैं "। फिर हनुमान जी प्रभु राम के पास गए ।