Questions tagged «java»

Java是一种流行的高级编程语言。如果您在使用或理解语言本身时遇到问题,请使用此标签。这个标签很少单独使用,最常与[spring],[spring-boot],[jakarta-ee],[android],[javafx],[gradle]和[maven]结合使用。

1
persistence.xml不同的事务类型属性
在persistence.xml JPA配置文件中,可以有如下一行: <persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type="JTA"> 或有时: <persistence-unit name="com.nz_war_1.0-SNAPSHOTPU" transaction-type=”RESOURCE_LOCAL”> 我的问题是: transaction-type="JTA"和之间有什么区别transaction-type=”RESOURCE_LOCAL”? 我还注意到缺少事务类型的一些persistence.xml文件。这是对的吗?

10
遍历Java中的字符串数组
我有一些组件的String数组,此数组有5个组件,有时会有所不同。我想做的是遍历该数组,并获得第一个组件和该组件旁边的组件。因此,我第一次获得组件编号1和2,第二次获得编号2和3,第三次获得3和4 ...依此类推,直到找到最后一个组件。 这是我走了多远: String[] elements = { "a", "a","a","a" }; for( int i = 0; i <= elements.length - 1; i++) { // get element number 0 and 1 and put it in a variable, // and the next time get element 1 and 2 and put this in another …

7
return关键字在Java中的void方法中做什么?
我正在查看路径查找教程,并且注意到方法return内的一条语句void(class PathTest,行126): if ((x < 0) || (y < 0) || (x >= map.getWidthInTiles()) || (y >= map.getHeightInTiles())) { return; } 我是Java的新手。谁能告诉我为什么它在那里?据我所知,return内部不允许使用void方法。
71 java  methods  return  void 

4
Eclipse内部错误“轮询新闻提要”
我在MacBook(High Sierra,Java 11)上使用Eclipse(4.9.0)时,有时会显示此错误,如果我在另一个应用程序上,则该错误会在屏幕快照中显示“堆栈”,讨厌再次回到Eclipse并每次都关闭此错误。有人可以帮我解决这个问题吗?

2
JTable,禁用用户列拖动
我声明我JTable为: data_table = new JTable(info, header) { @Override public boolean isCellEditable(int row, int column) { return false; } }; 但是我已经看到,在运行时可以用鼠标拖动列。如何禁用它?
71 java  swing  jtable 

3
如何在Java中声明常量
我们总是写: public static final int A = 0; 题: 是在类中static final声明常量的唯一方法吗? 如果我改写public final int A = 0;,是A一个常量还是一个实例字段? 什么是实例变量?实例变量和实例字段有什么区别?
71 java  constants 

9
读取UTF-8-BOM标记
我正在通过FileReader读取文件-该文件已经过UTF-8解码(使用BOM),现在的问题是:我读取了文件并输出了字符串,但可悲的是BOM表标记也被输出了。为什么会这样? fr = new FileReader(file); br = new BufferedReader(fr); String tmp = null; while ((tmp = br.readLine()) != null) { String text; text = new String(tmp.getBytes(), "UTF-8"); content += text + System.getProperty("line.separator"); } 第一行后输出 ?<style>
71 java  file  encoding 

4
应该使用AssertNull或AssertNotNull
这是一个非常愚蠢的问题,但这是我第一次进行单元测试,因此:假设我有一个对象变量(如obj),并且如果此obj为Null,我希望单元测试失败。所以对于断言,我应该说AssertNull还是AssertNotNull吗?我很困惑他们的名字。
71 java  junit 

7
如何让2个JVM互相交谈
我有以下情况: 我有2个JVM进程(实际上是2个java进程单独运行,而不是2个线程)在本地计算机上运行。我们称它们ProcessA为ProcessB。 我希望他们彼此交流(交换数据)(例如,ProcessA发送消息ProcessB以执行某项操作)。 现在,我通过编写一个临时文件来解决此问题,并且这些过程会定期扫描此文件以获取消息。我认为这种解决方案不是很好。 什么是实现我想要的更好的选择?

10
使用JDBC进行批处理INSERTS的有效方法
在我的应用程序中,我需要执行很多插入操作。它是一个Java应用程序,我正在使用普通的JDBC执行查询。该数据库是Oracle。我已经启用了批处理,所以它节省了我执行查询所需要的网络延迟。但是查询作为独立的INSERT顺序执行: insert into some_table (col1, col2) values (val1, val2) insert into some_table (col1, col2) values (val3, val4) insert into some_table (col1, col2) values (val5, val6) 我想知道以下形式的INSERT是否会更有效: insert into some_table (col1, col2) values (val1, val2), (val3, val4), (val5, val6) 即将多个INSERT折叠成一个。 还有其他使批处理INSERT更快的技巧吗?
71 java  sql  performance  jdbc 

1
使用Spring MVC返回生成的pdf
我正在使用Spring MVC。我必须编写一个服务,该服务将从请求主体中获取输入,将数据添加到pdf中,然后将pdf文件返回到浏览器。pdf文档是使用itextpdf生成的。如何使用Spring MVC做到这一点。我试过使用这个 @RequestMapping(value="/getpdf", method=RequestMethod.POST) public Document getPDF(HttpServletRequest request , HttpServletResponse response, @RequestBody String json) throws Exception { response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment:filename=report.pdf"); OutputStream out = response.getOutputStream(); Document doc = PdfUtil.showHelp(emp); return doc; } 生成pdf的showhelp函数。我只是暂时将一些随机数据放入pdf中。 public static Document showHelp(Employee emp) throws Exception { Document document = new Document(); PdfWriter.getInstance(document, new FileOutputStream("C:/tmp/report.pdf")); document.open(); …

8
使用Java杀死进程
我想知道如何“杀死”已经启动的过程。我知道Process API,但是不确定,是否可以使用它来杀死已经运行的进程,例如firefox.exe等。如果可以使用Process API,请您指向我正确的方向?如果没有,还有哪些其他可用选项?谢谢。
71 java  process 

6
Java.lang.NoClassDefFoundError:com / fasterxml / jackson / databind / exc / InvalidDefinitionException
我已经更新了我的依赖性,就像您在评论中所说的那样,现在我有了这个: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded Tomcat at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.onRefresh(EmbeddedWebApplicationContext.java:137) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:536) ~[spring-context-5.0.0.RC2.jar:5.0.0.RC2] at org.springframework.boot.context.embedded.EmbeddedWebApplicationContext.refresh(EmbeddedWebApplicationContext.java:122) ~[spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:737) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:370) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:314) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1162) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1151) [spring-boot-1.5.3.RELEASE.jar:1.5.3.RELEASE] at com.o2xp.ats.accountManager.test.App.main(App.java:42) [classes/:na] Caused by: org.springframework.boot.context.embedded.EmbeddedServletContainerException: Unable to start embedded …
71 java  spring  maven 

5
Java常量池的目的是什么?
我目前正在尝试更深入地研究Java虚拟机的规范。我一直在在线阅读《 JVM内幕》,其中有一个我似乎无法理解的令人困惑的抽象:常量池。这是本书的摘录: 对于它加载的每种类型,Java虚拟机必须存储一个常量池。常量池是类型使用的一组有序的常量,包括文字(字符串,整数和浮点常量)以及对类型,字段和方法的符号引用。常量池中的条目由索引引用,就像数组的元素一样。因为常量池持有对类型使用的所有类型,字段和方法的符号引用,所以常量池在Java程序的动态链接中起着核心作用。 关于以上内容和CP,我有几个问题: CP是否位于.class每种类型的文件中? 作者“符号参考”是什么意思? 用简单的英语讲,恒定池的目的是什么?

8
初始化错误
我正在使用Netbeans。我用绑定做了一些事情,现在每当我启动程序时,甚至在初始化表格之前,它都会给我一个错误 线程main中的异常是在表单甚至是初始化对象之前发生的。表单甚至还不是对象。我的main()中的每一行都会引发异常。随机的东西。我一点都不明白。 这是错误。 Exception in thread "main" java.lang.ExceptionInInitializerError at obd2ner.main(obd2ner.java:26) Caused by: java.lang.ClassCastException at java.lang.Class.cast(Class.java:2990) at org.jdesktop.beansbinding.Binding.convertForward(Binding.java:1312) at org.jdesktop.beansbinding.Binding.getSourceValueForTarget(Binding.java:844) at org.jdesktop.beansbinding.Binding.refreshUnmanaged(Binding.java:1222) at org.jdesktop.beansbinding.Binding.refresh(Binding.java:1207) at org.jdesktop.beansbinding.AutoBinding.tryRefreshThenSave(AutoBinding.java:162) at org.jdesktop.beansbinding.AutoBinding.bindImpl(AutoBinding.java:199) at org.jdesktop.beansbinding.Binding.bindUnmanaged(Binding.java:959) at org.jdesktop.beansbinding.Binding.bind(Binding.java:944) at org.jdesktop.beansbinding.BindingGroup.bind(BindingGroup.java:143) at OBD2nerForm.initComponents(OBD2nerForm.java:731) at OBD2nerForm.<init>(OBD2nerForm.java:75) at Status.<clinit>(Status.java:41) ... 1 more Java Result: 1 OBD2nerForm行731是bindingGroup.bind(); 有时它会在pack()上出错; “ main”中的异常似乎并不相关,因为该异常会在程序运行时发生,并且每次我注释掉一行时,它都会跳转到下一个 public …
71 java  binding  pack 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.