Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

bendem/java.py

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

75 Commits

Repository files navigation

java.py

java.py is a python script allowing you to execute java code quickly without opening an IDE or typing all the boilerplate code:

$ java.py 'Stream.of(1, 2, 3, 4).map(Integer::toBinaryString)'
 >> (java.util.stream.ReferencePipeline3ドル) ["1", "10", "11", "100"]

The result of the last instruction is displayed:

$ java.py 'Scanner s = new Scanner(System.in); s.nextLine()' <<< 'hello world!'
 >> (String) hello world!

The collection/array formatting allows you to quickly identify contained types:

$ java.py "new Object[]{1, \"a\", null, 'a'}"
 >> (Object[]) [1, "a", null, 'a']
 $ java.py 'Set<String> s = new HashSet<>(); s.add("hello"); s.add("world!"); s'
 >> (java.util.HashSet) ["hello", "world!"]

Missing an import? You can add content at the start of the generated file with -i:

$ java.py -i java.time.Instant 'Instant.now()'
 >> (java.time.Instant) 2016年02月29日T12:44:54.870Z

Want a pretty output? Use the -p flag:

$ java.py -p 'Random r = new Random(); Stream.generate(r::nextInt).limit(5)'
 >> (java.util.stream.SliceOps1ドル) [1716066362,
 >> 403370638,
 >> 653951165,
 >> -2063181131,
 >> -862370509]

Curious about the generated bytecode for some code? Use the -b flag:

$ java.py -b 'String a = "a", b = a + "b"'
 >> Compiled from "Paul.java"
 >> public class Paul {
 >> public static void main(java.lang.String[]) throws java.lang.Exception;
 >> Code:
 >> 0: ldc #2 // String a
 >> 2: astore_1
 >> 3: new #3 // class java/lang/StringBuilder
 >> 6: dup
 >> 7: invokespecial #4 // Method java/lang/StringBuilder."<init>":()V
 >> 10: aload_1
 >> 11: invokevirtual #5 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
 >> 14: ldc #6 // String b
 >> 16: invokevirtual #5 // Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
 >> 19: invokevirtual #7 // Method java/lang/StringBuilder.toString:()Ljava/lang/String;
 >> 22: astore_2
 >> 23: return
 >> }

Requirements

Requires java 8 and python 3 to work.

About

Trying out java snippets quickly

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

AltStyle によって変換されたページ (->オリジナル) /