我在接受采访时被问到为什么String是不可变的
我这样回答:
当我们在java中创建一个字符串时,
String s1="hello";就会在字符串池(hello)中创建一个对象,而s1将指向hello.如果我们再这样做,String s2="hello";那么将不会创建另一个对象但s2将指向,hello因为JVM将首先检查如果字符串池中存在相同的对象. 如果不存在则只创建一个新对象,否则不创建.
现在,如果假设Java允许串可变那么如果我们改变S1到hello world那么S2价值也将hello world因此Java字符串是不可改变的.
如果我的答案是对还是错,请问任何人可以告诉我吗?
我在接受采访时被问到使用for循环使用迭代器的优点是什么?使用for循环迭代器的优点是什么?
任何人都可以回答这个问题,以便将来如果我面临类似的问题那么我可以回答这个问题
我要求在Web服务调用中将一些值从移动设备传递到服务器,因此我打算以JSON格式传递所有值,如下所示
{
"nameservice": [
{
"id": 7413,
"name": "ask"
},
{
"id": 7414,
"name": "josn"
},
{
"id": 7415,
"name": "john"
},
{
"id": 7418,
"name": "R&R"
}
]
}
Run Code Online (Sandbox Code Playgroud)
以下是我的服务电话
@RequestMapping("/saveName")
@ResponseBody
public String saveName(String acc)
{jsonObject = new JSONObject();
try
{
);
System.out.println(acc);
jsonObject.accumulate("result", "saved ");
}
catch(Exception e)
{
e.printStackTrace();jsonObject.accumulate("result", "Error Occured ");
}
return jsonObject.toString();
}
Run Code Online (Sandbox Code Playgroud)
我试图通过这种方式调用上述服务
localhost:8080/service/saveName?acc={ "nameservice": [ { "id": 7413, "name": "ask" }, { "id": 7414, "name": "josn" }, { "id": 7415, "name": …Run Code Online (Sandbox Code Playgroud) public class test {
test(double[] a)
{
System.out.println("in double");
}
test(Object a)
{
System.out.println("in object");
}
public static void main(String args[])
{
new test(null);
}
}
Run Code Online (Sandbox Code Playgroud)
在上面的代码中,我传递null了构造函数参数.由于null可以是任何东西,上面的代码编译罚款.当我运行代码时,我希望它在对象中打印,但它以double形式打印
这背后的原因是什么?
注意链接的问题可能不重复,因为此问题与原始数据类型与对象相关
我在Threads.上看了一个小例子.为了创建Threads,我们可以通过实现Runnable接口或者通过扩展Thread来做两种方式.我用第一种方式
package test;
public class test implements Runnable{
public static void main(String args[])
{
test t=new test();
t.run();Thread th=Thread.currentThread();
th.start();
}
@Override
public void run() {
// TODO Auto-generated method stub
System.out.println("hi");
}
}
Run Code Online (Sandbox Code Playgroud)
我的疑问是,当我们呼吁th.start();则run()是called.I想知道how.I认为内部有start()可能是在提醒run()让我看着Thread类的文档中
以下是start()Thread类中的声明
public synchronized void start() {
/**
* This method is not invoked for the main method thread or "system"
* group threads created/set up by the VM. Any new functionality added
* …Run Code Online (Sandbox Code Playgroud) 我有一个rtf文件,其中有一些带有项目符号的文本,如下面的屏幕截图所示
我想提取数据和子弹,但是当我在控制台中打印时,我得到了垃圾值.如何从控制台打印完全相同的内容.我尝试的方式如下
public static void main(String[] args) throws IOException, BadLocationException {
RTFEditorKit rtf = new RTFEditorKit();
Document doc = rtf.createDefaultDocument();
FileInputStream fis = new FileInputStream("C:\\Users\\Guest\\Desktop\\abc.rtf");
InputStreamReader i =new InputStreamReader(fis,"UTF-8");
rtf.read(i,doc,0);
System.out.println(doc.getText(0,doc.getLength()));
}
Run Code Online (Sandbox Code Playgroud)
控制台输出:
我认为垃圾值是由于控制台不支持chareset所以我试图生成一个pdf文件,但在pdf中我也得到相同的垃圾值.这是pdf代码
Paragraph de=new Paragraph();
Phrase pde=new Phrase();
pde.add(new Chunk(getText("C:\\Users\\Guest\\Desktop\\abc.rtf"),smallNormal_11));
de.add(pde);
de.getFont().setStyle(BaseFont.IDENTITY_H);
document.add(de);
public static String getText() throws IOException, BadLocationException {
RTFEditorKit rtf = new RTFEditorKit();
Document doc = rtf.createDefaultDocument();
FileInputStream fis = new FileInputStream("C:\\Users\\Guest\\Desktop\\abc.rtf");
InputStreamReader i =new InputStreamReader(fis,"UTF-8");
rtf.read(i,doc,0);
String output=doc.getText(0,doc.getLength());
return output;
}
Run Code Online (Sandbox Code Playgroud) 根据Java三元运算符expression ? statement1 : statement2,如果expression为true则statement1执行,如果expression为false则statement2执行.
但是当我跑步时:
// some unnecessary codes not displaying
char y = 'y';
int i = 0;
System.out.print(false ? i : y);
Run Code Online (Sandbox Code Playgroud)
我期待它打印,y但它的打印121,为什么?
编辑
根据manouti的答案,编译器解释为int,但如果是这样,那么为什么我看到死代码i?
如果我这样做,System.out.print(false ? 0 : x);那么我得到了y,那么为什么在这种情况下编译器不会解释为int?
我最近参与了一个新项目,完全不知道使用的是哪个框架。 很长一段时间后,我才知道使用 spring,因为我看到了一些导入,例如
import org.springframework.beans.factory.annotation.Configurable;
Run Code Online (Sandbox Code Playgroud)
并且我确定使用了 spring。现在我完全不知道是使用 hibernate 还是使用 jpa。当我问我的同事时,有些人告诉我使用 jpa,有些人告诉 hibernate 这意味着他们也很困惑。任何机构都可以请对此有所了解。我怎么知道使用了 jpa 或 hibernate。
应该专门为 jpa 或 hibernate 导入哪些包。请提供任何提示
我有兴趣学习tibco.我在youtube上找到了一些很好的视频,但所有这些只是教程.没有视频回答为什么tibco在组织中使用以及它对它有用.我在webservices中看到了一些教程,是的我们可以使用java做同样的事情.
我基本上来自java背景,并且在webservices方面有很好的经验.我在tibco看到了一些关于Web服务的教程,他们正在使用soap palletes.
不仅对于Web服务我也看过jdbc pallettes的教程.在java中我们也有jdbc.so在我的脑海中出现了很多问题,其中一个问题是为什么tibco?如果java可以做哪些是免费的那么为什么要购买tibco和做同样的工作.
一般情况下,任何人都可以告诉我为什么使用tibco以及它对组织有何帮助?
我刚接触这个工具
tibco文件说
Mapper活动将新的流程变量添加到流程定义中.此变量可以是简单数据类型,TIBCO ActiveEnterprise架构,XML架构或复杂结构.
所以我的问题是tibco mapper只做这个简单的函数.我们也可以在流程定义中创建流程变量(通过右键单击流程定义).我在google中查找它但没有明确解释为什么要使用此活动而且我也有尝试在youtube上,也只有一个视频,它没有清楚解释.我正在寻找一个例子如何在大型组织中使用和一个实时的例子.谢谢你提前
我从icomoom下载了一些图标,但图标背景颜色是黑色和白色.我想给自己的颜色.可以告诉我怎么办?
当我下载图标时,我得到了以下style.css
@font-face {
font-family: 'icomoon';
src:url('fonts/icomoon.eot?-haa506');
src:url('fonts/icomoon.eot?#iefix-haa506') format('embedded-opentype'),
url('fonts/icomoon.woff?-haa506') format('woff'),
url('fonts/icomoon.ttf?-haa506') format('truetype'),
url('fonts/icomoon.svg?-haa506#icomoon') format('svg');
font-weight: normal;
font-style: normal;
}
[class^="icon-"], [class*=" icon-"] {
font-family: 'icomoon';
speak: none;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1;
/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.icon-home:before {
content: "\e600";
}
.icon-images:before {
content: "\e601";
}
.icon-pawn:before {
content: "\e602";
}
Run Code Online (Sandbox Code Playgroud)