java

Allocation of space for local variables in loops

一笑奈何 提交于 2021-02-18 07:41:32
问题 (true or false) The space for a local variable that is declared in the body of the loop is allocated whenever the loop body is executed and deallocated when the body finishes. The answer to this question is false. But why? 回答1: The statement is false because local variable space is not allocated and deallocated. It exists on the stack and is reserved when the method is entered. To see how stack space is used, write a small test program with: public static void test() { { int a = 1; long b = 2

Generic enum JPA AttributeConverter implementation

╄→гoц情女王★ 提交于 2021-02-18 07:39:28
问题 Problem I am trying to solve I am trying to implement enum mapping for Hibernate. So far I have researched available options, and both the @Enumerated(EnumType.ORDINAL) and @Enumerated(EnumType.STRING) seemed inadequate for my needs. The @Enumerated(EnumType.ORDINAL) seems to be very error-prone, as a mere reordering of enum constants can mess the mapping up, and the @Enumerated(EnumType.STRING) does not suffice too, as the database I work with is already full of values to be mapped, and

如何选定你的职业方向(深度长文)

不想你离开。 提交于 2021-02-18 07:39:24
文章转自明哥聊求职 本文旨在详解职业选择需要考虑的方方面面因素,为作者近二十年的职场经验分享,全文1.3万字,如果你面临择业或重新择业,相信这篇长文会带给你一些启发。 明哥的猎聘求职指导系列课程直播课,开启第二讲:求职前的准备工作,如果你确定了职业方向,对求职前的准备有点小迷茫,今晚六点半洗白白等你来,扫码免费听课—— 两个小孩去森林玩,不幸遭遇了大老虎,一个小孩撒腿就跑,另一个小孩拽住他:“别跑了,我们再跑也跑不过大老虎。”撒腿就跑的小孩扭头对他说:“我不需要比老虎跑得快,只要跑得比你快就行了”,说完就是一通夺路狂奔。老虎追上跑得慢的小孩就可以开餐了,跑得快的小孩会活下来。 这个故事告诉我们:努力很重要! 还是这两个熊孩子,上次老虎吃饱了,结果跑的没死,没跑的也没死,不吸取教训又去森林了,倒霉催得又碰到了大老虎。这次老虎饿三天了,一个小孩又撒腿就跑,另一个小孩拽住他说“你跑也没用”,这个小孩说“我跑得比你快就行”……没想到,没跑的小孩讲了一句话:“那可未必”。跑的小孩玩了命地跑,没跑的小孩噌噌噌爬到树顶上去了。跑的小孩终究没跑过大老虎,被老虎吃掉了。在树上的小孩没事,因为老虎爬不了那么高的树。 这个故事告诉我们:选择比努力更重要! 决定我们一生的,第一是我们的选择,第二才是我们的能力和努力。 选择对了,事半功倍;选择错了,可能事倍功半,甚至南辕北辙。只有在方向正确的前提下

How do Java Module directives impact reflection access into a module?

橙三吉。 提交于 2021-02-18 07:37:05
问题 According to https://www.oracle.com/corporate/features/understanding-java-9-modules.html, the Java Module system introduces the following directives: exports, exports ... to uses provides ... with open, opens, opens ... to What (if any) impact does each directive have on an external module accessing internal members using reflection? For example, does exports <package> allow external modules to access all public , protected , private members of the exported package using reflection? What

Correct way to Convert 16bit PCM Wave data to float

浪尽此生 提交于 2021-02-18 07:24:32
问题 I have a wave file in 16bit PCM form. I've got the raw data in a byte[] and a method for extracting samples, and I need them in float format, i.e. a float[] to do a Fourier Transform. Here's my code, does this look right? I'm working on Android so javax.sound.sampled etc. is not available. private static short getSample(byte[] buffer, int position) { return (short) (((buffer[position + 1] & 0xff) << 8) | (buffer[position] & 0xff)); } ... float[] samples = new float[samplesLength]; for (int i

What is/are the Python equivalent(s) to the Java Collections Framework?

Deadly 提交于 2021-02-18 07:22:47
问题 The Java Collections Framework is like the C++ Standard Template Library: "a unified architecture for representing and manipulating collections (objects that group multiple elements into a single unit)." http://java.sun.com/docs/books/tutorial/collections/intro/index.html 回答1: Other than the built-ins you might what to check out collections. >>> import collections >>> dir(collections) ['Callable', 'Container', 'Hashable', 'ItemsView', 'Iterable', 'Iterator', 'KeysView', 'Mapping',

JPA Criteria API. Query with sql function call which takes parameters

心不动则不痛 提交于 2021-02-18 06:53:26
问题 I'm trying to construct this query using Criteria typesafe API: select * from xxx_table xxx where CALC_DISTANCE(xxx.latitude, xxx.longitude, :lat, :lng) < :dist CALC_DISTANCE definded PL/SQL function: FUNCTION calc_distance( pLat1 NUMBER, pLon1 NUMBER, pLat2 NUMBER, pLon2 NUMBER) RETURN NUMBER CriteriaBuilder builder = JpaHandle.get().getCriteriaBuilder(); CriteriaQuery<XXX> criteria = builder.createQuery(XXX.class); Root<XXX> xxxRoot = criteria.from(XXX.class); ParameterExpression<Double>

Freemarker compress single_line without spaces

被刻印的时光 ゝ 提交于 2021-02-18 06:50:31
问题 It seems that <@compress single_line=true> is replacing line breaks with single spaces (" "), instead of just suppressing them. Example: <@compress single_line=true> "First cell" <#if something > |"Second cell" </#if> |"Third cell" </@compress> Is printing: "First cell" |"Second cell" |"Third cell" Which can't be parsed by a legacy system just because of the spaces between the pipes. Is there any way to avoid this?, perhaps a way to read every "nested" line in a macro to substitute the

JConsole remote connection to JBoss EAP

核能气质少年 提交于 2021-02-18 06:48:11
问题 I am trying to connect to a remote jboss instance running on a server. I am using the following connection URL service:jmx:remoting-jmx://90.214.64.170:9999 When i do this i get the following 2 errors in the console window After selecting insecure i am presented with this I have, prior to connecting via jconsole also gone to the bin directory of my jboss server and run ./jconsole.sh which outputs the following to the command line CLASSPATH /usr/bin/java/jdk1.8.0_11/lib/jconsole.jar:/usr/bin

How to set VM options for JLink launcher executable

流过昼夜 提交于 2021-02-18 06:41:53
问题 When using jlink , a bin/java file is generated. This executable will accept VM options by specifying options on the command line in the usual way (such as -Dsystem.property=value or -Xmx1G ). jlink also provides a --launcher option to create an executable that can be run directly, instead of having to invoke the bin/java executable with a module name. How do I make the launcher executable pre-configured to use my choice of JVM options? 回答1: You can use the add-options jlink plugin. For