কম্পিউটার টিউটোরিয়াল

জাভা ৯-এ JShell কীভাবে ডিবাগ করবেন?

JShell একটি REPL টুল যা স্নিপেট কোড রান করার অনুমতি দেয় ক্লাসে রাখা ছাড়া। এই টুল জাভাতে ডিক্লেরেশন, স্টেটমেন্ট এবং এক্সপ্রেশন ইভ্যালুয়েট করার পথ প্রদান করে এবং কোডের কিছু অংশ টেস্ট করার জন্য main() মেথড তৈরি করার প্রয়োজন নেই।

"/debug" কমান্ড ব্যবহার করে JShell টুল ইমপ্লিমেন্টেশনের ডিবাগিং ইনফরমেশন ডিসপ্লে করা যায়। একবার "/debug" কমান্ড টাইপ করলে ডিবাগিং মোড অন হয়। ডিবাগ মোড অন করার পর কিছু টাইপ করলে (সিম্পল অ্যাডিশন বা স্ট্রিং), নিচের মত আউটপুট আসে।

উদাহরণ ১: 5+3 ডিবাগ মোডে

jshell> /debug
| Debugging on
jshell> 5+3
Compiling: 5+3
Kind: EXPRESSION_STATEMENT -- 5 + 3;
compileAndLoad [Unit($1)]
++setCompilationInfo()
Snippet:VariableKey($1)#11-5+3
package REPL;
import java.io.*;import java.math.*;import java.net.*;import java.nio.file.*;import java.util.*;
import java.util.concurrent.*;import java.util.function.*;import java.util.prefs.*;
import java.util.regex.*;import java.util.stream.*;
class $JShell$11 {
    public static int $1;
    public static Object do_it$() throws Throwable {
        return $1 = 5+3;
    }
}
-- diags: []
setStatus()
Snippet:VariableKey($1)#11-5+3 - status: VALID
compileAndLoad ins = [Unit($1)]
-- legit = [Unit($1)]
Compiler generating class REPL.$JShell$11
compileAndLoad [Unit($1)]
-- deps: []
success: true
recordCompilation: Snippet:VariableKey($1)#11-5+3 -- status VALID, unresolved []
$1 ==> 8

উদাহরণ ২: স্ট্রিং অ্যাসাইনমেন্ট ডিবাগ মোডে

jshell> /debug
| Debugging on
jshell> String s = "Adithya"
Compiling: String s = "Adithya";
Kind: VARIABLE -- String s = "Adithya"
compileAndLoad [Unit(s)]
++setCompilationInfo()
Snippet:VariableKey(s)#12-String s = "Adithya";
package REPL;
import java.io.*;import java.math.*;import java.net.*;import java.nio.file.*;import java.util.*;
import java.util.concurrent.*;import java.util.function.*;import java.util.prefs.*;
import java.util.regex.*;import java.util.stream.*;import static REPL.$JShell$11.$1;
class $JShell$12 {
    public static String s;
    public static Object do_it$() throws Throwable {
        String s_ = "Adithya";
        return s = s_;
    }
}
-- diags: []
setStatus()
Snippet:VariableKey(s)#12-String s = "Adithya"; - status: VALID
compileAndLoad ins = [Unit(s)]
-- legit = [Unit(s)]
Compiler generating class REPL.$JShell$12
compileAndLoad [Unit(s)]
-- deps: []
success: true
recordCompilation: Snippet:VariableKey(s)#12-String s = "Adithya"; -- status VALID, unresolved []
s ==> "Adithya"

ডিবাগিং মোড "অফ" করতে হলে একবার আর "/debug" কমান্ড টাইপ করতে হয় একই সেশনে।

jshell> /debug
| Debugging off
  1. জাভা ৯-এর JShell-এ প্যাকেজ ইম্পোর্ট

  2. জাভা ৯-এ JShell-এ সিস্টেম প্রপার্টি পাওয়ার পদ্ধতি

  3. জাভা ৯-এ JavaFX ব্যবহার করে JShell ইমপ্লিমেন্ট করার পদ্ধতি

  4. জাভা ৯-এ JShell কী?