javacompiler

Javac missing optimization for effective final

百般思念 提交于 2021-02-19 01:36:30
问题 Fact: javac is programmed to detect if a variable is final or if it can be treated as effectively final . Proof: This code illustrates this. public static void finalCheck() { String str1 = "hello"; Runnable r = () -> { str1 = "hello"; }; } This fails to compile because compiler is able to detect String reference str1 is being re-assigned in function. Now Situation 1: Javac does great optimization for final String instances by avoiding to create StringBuilder and related operations. Proof This

Running a compiled java .class file from within java code and capturing output

荒凉一梦 提交于 2021-02-11 08:36:54
问题 I'm trying to write a java program with an interface that allows the user to create .java file and compile and run it (essentially a very simplistic IDE). I'm using java swing for the gui and have so far been able to compile a .java file from within the interface into a .class file. I've been researching how to run a .class file from within java code but have found a wide range of answers which I haven't been able to get working. Here is the relevant code for compilation: File javaFile = new

Running a compiled java .class file from within java code and capturing output

 ̄綄美尐妖づ 提交于 2021-02-11 08:36:13
问题 I'm trying to write a java program with an interface that allows the user to create .java file and compile and run it (essentially a very simplistic IDE). I'm using java swing for the gui and have so far been able to compile a .java file from within the interface into a .class file. I've been researching how to run a .class file from within java code but have found a wide range of answers which I haven't been able to get working. Here is the relevant code for compilation: File javaFile = new

Compile java class in runtime with dependencies to nested jar

守給你的承諾、 提交于 2021-02-08 06:55:45
问题 In a spring-boot app I'm doing the following in runtime: Generating a java class Compiling it Accessing some static fields of the compiled class using reflection. I've based my code on this post and got a problem compiling my generated class in runtime. When running in the IDE compilation works just fine but when runing from a spring-boot jar compilation fails saying symbols are missing or some package does not exist. The class I'm compiling has dependencies to other classes that reside in a

How to use JavaCompiler from tools.jar without JDK

帅比萌擦擦* 提交于 2021-01-28 08:52:15
问题 I am trying to create an application that can compile a provided .java file during runtime. I understand that there is a programmatical compiler available within the tools.jar of the JDK. However, I cannot guarantee that the user of the application has JDK. I have attempted to package tools.jar within the application and reference it as a library. This seems to work within the Eclipse IDE when I have tools.jar added into the Bootstrap Entries of the classpath. When exporting the application

Java for-loop optimization

北战南征 提交于 2019-12-28 06:49:29
问题 I made some runtime tests with java for loops and recognized a strange behaviour. For my code I need wrapper objects for primitive types like int, double and so on, to simulate io and output parameters, but thats not the point. Just watch my code. How can objects with field access be faster then primitive types? for loop with prtimitive type: public static void main(String[] args) { double max = 1000; for (int j = 1; j < 8; j++) { double i; max = max * 10; long start = System.nanoTime(); for

How to get list of class files generated by JavaCompiler compilationTask?

北城以北 提交于 2019-12-24 10:59:13
问题 I am trying to compile java code dynamically using javaCompiler. Code works gr8 however I need to get the list of class files created by CompilationTask. Here is source code: JavaCompiler compiler = ToolProvider.getSystemJavaCompiler (); DiagnosticCollector<JavaFileObject> diagnostics = new DiagnosticCollector<JavaFileObject>(); StandardJavaFileManager fileManager = compiler.getStandardFileManager (diagnostics,null,null); //compile unit Iterable<? extends JavaFileObject> compilationUnits

Compile and Run java program in linux with path to the .java file and path to external jars

痞子三分冷 提交于 2019-12-23 03:37:18
问题 Yesterday I solved a problem with an answer here on stackoverflow. But I ended up with another problem, I will try to be clear: I have a project folder in the /home/demo/Desktop/xlsToCsv/ directory where inside of it is the java file "xlsToCsv.java" and another directory with the external jars that I need in /home/demo/Desktop/xlsToCsv/jars . Now I need to compile and run my program. Yesterday I ran a command that assumed that I was already inside of /home/demo/Desktop/xlsToCsv/ , and the

Error: when I replace compile with implementation in gradle(dependency)

╄→尐↘猪︶ㄣ 提交于 2019-12-22 08:49:28
问题 I update my Android Studio from 3.0.1 to 3.1.0 But after the update when I build my project it shows 2 warning : 1. Replace compile with implementation (and compile support will be ended at end of 2018) 2. Replace testCompile with testImplementaion (and testCompile support will be ended at end of 2018) So, finally do these changes but after that, it shows some error : build.gradle(Module:app) apply plugin: 'com.android.application' android { compileSdkVersion 27 defaultConfig { applicationId