我混淆了JAX-RS之间的区别(好吧,也许应该使用Jersey进行比较,因为JAX-RS只是规范)和Spring for Restful服务.我试图在网上搜索更多信息,它变得更加混乱.我的公司正在使用Spring MVC来开发Restful API
令人困惑的部分是,JAX-RS代表用于RESTful Web服务的Java API,在Spring中我也使用java来开发RESTful Web服务,所以我实际上并没有得到差异.Spring是否遵循JAX-RS规范?
据我所知,直到现在:
我正在尝试将一行文本分成多个部分.文本的每个元素都以句点分隔.我正在使用string.split("."); 将文本拆分为一个字符串数组,但没有到达任何地方.
以下是代码示例:
String fileName = "testing.one.two";
String[] fileNameSplit = fileName.split(".");
System.out.println(fileNameSplit[0]);
Run Code Online (Sandbox Code Playgroud)
有趣的是,当我尝试":"而不是"."时,它有效吗?我怎样才能让它工作一段时间?
我有原始阵列
public static void main (String[] arg) {
int[] array = {1,5,6,8,4,2}
for (int i = 0; i < array.length; i++) {
System.out.print("List 1 = " + array[i] + ",");
}
swap(array);
for (int i = 0; i < array.length; i++) {
System.out.print("List 2 = "+array[i] + ",");
}
}
private static int swap (int[] list){
Arrays.sort(list);
}
Run Code Online (Sandbox Code Playgroud)
输出是
List 1 = 1,5,6,8,4,2
List 2 = 1,2,4,5,6,8
Run Code Online (Sandbox Code Playgroud)
我想要的答案是
List 1 = 1,5,6,8,4,2
List 2 = 1,5,6,8,4,2
Run Code Online (Sandbox Code Playgroud)
甚至在分拣后.我该怎么做?
我正在编写一个执行矩阵运算的程序,我正在试图弄清楚在无效维度的情况下我应该使用什么样的代码.是否存在一些已经存在的异常类型,我的操作可以接受; 或者我应该实现自己的异常类型?我知道几乎任何异常类型都可以实现我想要的,但问题是确保异常实际上描述了导致它的问题.
我正在尝试使用我的JSF页面中的Primefaces Dialog组件显示警报.我可以显示对话框,但问题在于此对话框的透明度/不透明度.我通过设置覆盖了对话框的样式属性opacity: 1.0
,但它没有用.我想放弃对话框的透明度.我怎样才能以简单的方式实现这一目标?
我的JSF页面:
<f:view xmlns="http://www.w3.org/1999/xhtml"
....
renderKitId="PRIMEFACES_MOBILE">
....
<pm:page title="Mobile Reports">
<pm:view id="reports" swatch="b">
<h:form>
<pm:content>
<div>
<h:form>
....
<p:dialog id="myDialog"
header="ERROR"
widgetVar="dlg"
modal="true"
style="opacity: 1.0;"
appendToBody="true">
<p:commandButton id="decline" value="Couldn't display the report!"
onclick="dlg.hide()" type="button" />
</p:dialog>
....
<p:commandButton id="contractInfo" action="ContractInfo.xhtml"
value="Contract Information" style="width:100%;"
onerror="dlg.show();">
</p:commandButton>
....
</h:form>
</div>
</pm:content>
</h:form>
</pm:view>
</pm:page>
</f:view>
Run Code Online (Sandbox Code Playgroud)
输出:
GPRS显示在JSF页面中,它不是对话框的一部分.但是,由于对话框是透明的,因此它是可见的.
注意: 我正在使用primefaces-mobile-0.9.3.jar
签出新分支后,我想通过Atlassian SourceTree(版本1.4.0.0)停止跟踪.classpath等文件.我创建了一个自定义操作,其详细信息如下:
然后,从"工作副本更改"面板中,我选择了一个文件,右键单击它并尝试执行"假定未更改"自定义命令.但是,我得到了这个完全"吝啬"的错误消息:
我在上面的错误消息中复制了完整命令,并尝试从命令行执行它:
有趣的是,它奏效了.
有人可以通过右键单击并从菜单中选择,告诉我为什么这个自定义操作无法在第一个位置工作?
我试图从Java中的字符串中找到所有三个字母的子串.
例如,从字符串"example string"我应该得到"exa","xam","amp","mpl","ple","str","tri","rin","ing".
我尝试使用Java正则表达式"([a-zA-Z]){3}"但我只得到"exa","mpl","str","ing".
有人可以告诉我一个正则表达式或方法来纠正这个问题.
哪个fizzbuzz实现效率更高?
public static void fizzBuzz1(int n)
{
boolean fizzed, buzzed;
for(int i = 1; i <= n; i++)
{
fizzed = buzzed = false;
if(i % 3 == 0)
fizzed = true;
if(i % 5 == 0)
buzzed = true;
if(fizzed && buzzed)
System.out.println("FizzBuzz");
else if(fizzed)
System.out.println("Fizz");
else if(buzzed)
System.out.println("Buzz");
else
System.out.println(i);
}
}
public static void fizzBuzz2(int n)
{
for(int i = 1; i <= n; i++)
{
if(i % 3 == 0 && i % 5 …
Run Code Online (Sandbox Code Playgroud) 我正在使用swing worker来验证文件,我希望将startLine和endLine发送到validate类,因为我不想每次都验证整个文件.第一次当现有文件是openend时,我想将startLine发送为0,将endLine作为endLine = editorTextArea.getLineCount() - 1;发送.之后我应该能够每秒钟将startLine和endLine发送给我.我如何实现这一目标?
验证课程:
class Validate implements Runnable {
private JTextArea editorTextArea;
private JTextArea errorTextArea;
private int startLine;
private int endLine;
public Validate(JTextArea editor, JTextArea error, startLine, endLine) {
this.editorTextArea = editor;
this.errorTextArea = error;
this.startLine = startLine;
this.endLine = endLine;
}
@Override
public void run() {
SwingWorker worker = new SwingWorker<Void, Void>() {
@Override
protected Void doInBackground() throws Exception {
//CODE TO VALIDATE
return null;
}
@Override
protected void done() {
//CODE TO DISPLAY THE RESULT …
Run Code Online (Sandbox Code Playgroud) 当我练习参加OCJP考试时,我发现我想要练习的问题通常都是技巧问题,试图欺骗我回答错误.这个例子来自Bathes/Sierra的书,一个典型的技巧问题是:
现在我想知道你是否可以告诉我,真实考试中的问题是否经常是这样的技巧问题,或者实际考试是否有另一种风格,或者这是否接近我的期望?
你能解释一下这行代码中发生了什么吗?特别是什么args[0].tocharArray
?
char[] password = args[0].toCharArray();
Run Code Online (Sandbox Code Playgroud) 我已经尝试了一段时间来弄清楚如何找到随机数组的最大值.这是我正在调试的代码:截至目前,我得到的是数组中的一个值,但它不是最大值.
public static void main(String[] args) {
System.out.println(intOfMaxInRange(randomIntArray(10), 1,30));
}
public static int random(int low, int high){
int x=(int)(Math.random()*high+low);
return x;
}
public static int[] randomArray(int n){
int[] a = new int[n];
for (int i = 0; i<a.length; i++) {
a[i] = randomInt (1,30);
}
return a;
}
public static int intOfMax( int[] array){
int max=array[0];
for(int i=1;i<array.length;i++){
if (array[i] > max) {
}
}
return max;
}
Run Code Online (Sandbox Code Playgroud) 我很确定我在这里错过了一些非常简单的东西,但我找不到它!
这是我GamePanel
班的宣言:
private class GamePanel extends JPanel implements KeyListener {
Run Code Online (Sandbox Code Playgroud)
在它的构造函数是:
addKeyListener(this);
Run Code Online (Sandbox Code Playgroud)
同样在构造函数中:
new Thread(new Runnable() {
@Override
public void run() {
while (true) {
index ++;
index = index >= 15 ? 0 : index;
if (aPress) {
playerX --;
}
if (dPress) {
playerX ++;
}
repaint();
try {
Thread.sleep(25);
} catch (InterruptedException e) {}
}
}
}).start();
Run Code Online (Sandbox Code Playgroud)
在课堂里:
@Override
public void keyPressed(KeyEvent e) {
System.out.println("Key pressed!");
if (e.getKeyCode() == KeyEvent.VK_A) {
aPress = true;
} …
Run Code Online (Sandbox Code Playgroud) java ×10
arrays ×2
regex ×2
swing ×2
coding-style ×1
debugging ×1
dialog ×1
eclipse ×1
exception ×1
fizzbuzz ×1
git ×1
jax-rs ×1
jersey ×1
jsf ×1
jsf-2 ×1
keylistener ×1
loops ×1
mobile ×1
ocpjp ×1
optimization ×1
performance ×1
primefaces ×1
scjp ×1
sorting ×1
spring-mvc ×1
string ×1
swingworker ×1
windows ×1