可能重复:
为什么(-1 >>> 32)= -1?
无符号右移运算符在最左边插入0.所以,当我这样做
System.out.println(Integer.toBinaryString(-1>>>30))
Run Code Online (Sandbox Code Playgroud)
11
Run Code Online (Sandbox Code Playgroud)
因此,它在最左边的位中插入0.
System.out.println(Integer.toBinaryString(-1>>>32))
Run Code Online (Sandbox Code Playgroud)
11111111111111111111111111111111
Run Code Online (Sandbox Code Playgroud)
不应该是0吗?
我不想拥有hibernate.cfg.xml文件.相反,我想通过我的代码进行所有配置,如下所示.
private static final SessionFactory factory;
private static final Properties properties;
static
{
properties = new Properties();
properties.setProperty("hibernate.connection.driver_class", "com.mysql.jdbc.Driver");
properties.setProperty("hibernate.connection.url", "jdbc:mysql://localhost:3306/books");
properties.setProperty("hibernate.connection.username", "jhtp7");
properties.setProperty("hibernate.connection.password", "password");
properties.setProperty("hibernate.show_sql", "com.mysql.jdbc.Driver");
properties.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect");
factory = new Configuration().setProperties(properties).configure().
buildSessionFactory();
}
Run Code Online (Sandbox Code Playgroud)
我尝试过上述方法.但我面临的问题是,hibernate抛出一个异常说" ./hibernate.cfg.xml file missing
".
保留hibernate.cfg.xml
文件真的是强制性的吗?
提前致谢
使用案例: - 如果用户正在滚动内部div,则一旦达到内部div,它就不应滚动外部div.
如果内部div已经到达结尾,则以下代码可以正常工作.即,在内部div到达结束之后触发touchstart/touchmove事件.
但是如果我不提起触摸并继续滚动,并且如果在此过程中内部div的末端已到达,则它开始滚动外部div.
$('body').find('.scrollableDiv').on(
{
'touchstart' : function(e) {
touchStartEvent = e;
},
'touchmove' : function(e) {
e.stopImmediatePropagation();
$this = $(this);
if ((e.originalEvent.touches[0].pageY > touchStartEvent.originalEvent.touches[0].pageY && this.scrollTop == 0) ||
(e.originalEvent.touches[0].pageY < touchStartEvent.originalEvent.touches[0].pageY && this.scrollTop + this.offsetHeight >= this.scrollHeight)){
e.preventDefault();
}
},
});
Run Code Online (Sandbox Code Playgroud)
一旦达到内部div的结尾,我该如何停止滚动?我试图在Android设备上的浏览器上实现这一点.有人可以在这方面帮助我吗?
注意:用户甚至应该能够滚动外部div.
提前致谢.
我在Java中定义字符串常量的看法是,当在多个地方使用相同的字符串时,应该定义一个字符串常量.这有助于减少拼写错误,减少将来更改字符串的工作量等.
但是如何在一个地方使用字符串.即使在这种情况下我们应该声明字符串常量.
例如.记录一些计数器(随机例子).
CounterLogger.addCounter("Method.Requested" , 1)
Run Code Online (Sandbox Code Playgroud)
我想启用一些 String 类型字段的自定义 jackson 反序列化器。反序列化器还需要注入一个基于 guice 的依赖 bean。示例代码如下:
public class CustomDeserializer extends StdDeserializer<String> {
private SomeDependecy dependency;
public StringDeserializer() {
this(null);
}
public StringDeserializer(Class<?> vc) {
super(vc);
}
@Override
public String deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
return dependency.perform(p.getValueAsString());
}
}
Run Code Online (Sandbox Code Playgroud)
我无法注册基于 Class 类型的模块,因为它是通用的(String.class、Complex Datatype(但并非每个模块都需要自定义反序列化器))。有没有办法在不使用静态方法的情况下实现上述目标?
PS:我确实搜索了网络,但如果不使用 statics 就找不到更干净的解决方案。使用一些静态方法来获取上下文和 bean 的所有建议。
我是perl的新手.
我试图使用连接与数组引用,但它不起作用.
这是我的代码.
my $arr = {
'items' => ('home', 'chair', 'table')
};
my $output = join(',', $arr->{'items'});
print $output;
Run Code Online (Sandbox Code Playgroud)
这是印刷
table
Run Code Online (Sandbox Code Playgroud)
代替
home,chair,table
Run Code Online (Sandbox Code Playgroud)
有人可以在这方面帮助我吗?
给定一串长度为'n'的字符串.如何获得长度为r的所有子序列(r <= n).我正在考虑使用动态编程来实现它,但无法提出一个好的解决方案.我想要一个伪代码.
例如.给定字符串"abc"并且r = 2.
输出:ab ba ac ca bc cb
提前致谢
我目前有一个应用程序,可以向很多URL发出HTTP post请求.某些连接失败,出现以下异常.
Exception in thread "main" javax.net.ssl.SSLProtocolException: handshake alert: unrecognized_name at sun.security.ssl.ClientHandshaker.handshakeAlert(ClientHandshaker.java:1410) at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:2004) at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1113) at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1363) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1391) at sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:1375) at sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:563) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) at sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153) at com.amazon.cba.iopn.test.MainTest.connectWithFallbackIfRequired(MainTest.java:246) at com.amazon.cba.iopn.test.MainTest.createHttpConnection(MainTest.java:201) at com.amazon.cba.iopn.test.MainTest.processLine(MainTest.java:105) at com.amazon.cba.iopn.test.MainTest.main(MainTest.java:99)
我从网上读到其他文章后发现,这是服务器配置的问题.响应中的服务器抛出一个警告,Java将其视为异常.解决方法是将jsse.enableSNIExtension设置为" false ".
PS:我们尝试通过HTTPS连接的所有网址.因此,将有证书验证.
以下是我正在运行的一段代码.
@Test
public void testMyMehotd() {
String expected = "2012-09-12T20:13:47.796327Z";
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSSSS'Z'");
//df.setTimeZone(TimeZone.getTimeZone("UTC"));
Date d = null;
try {
d = df.parse(expected);
} catch (ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return;
}
String actual = df.format(d);
System.out.println(expected);
System.out.println(actual);
}
Run Code Online (Sandbox Code Playgroud)
但输出与我的预期不同.
expected : 2012-09-12T20:13:47.796327Z
actual : 2012-09-12T20:27:03.000327Z
Run Code Online (Sandbox Code Playgroud)
有人能告诉我这个的原因以及解决方案是什么.
提前致谢.
有什么区别
myArr1 => \@existingarray
Run Code Online (Sandbox Code Playgroud)
和
myArr2 => [
@existingarray
]
Run Code Online (Sandbox Code Playgroud)
我将分配给@existingarray
哈希映射中的元素.
我的意思是内部发生了什么.是第一个,它指向同一个数组,对于第二个数组,它创建一个新的数组,其中包含元素@existingarray
提前致谢
public class Example {
public static void main(String args[]){
Parent p = new Child();
p.m2();
}
}
class Parent{
void m1(){
System.out.println("Parent : m1");
m2();
}
void m2(){
System.out.println("Parent : m2");
}
}
class Child extends Parent{
void m1(){
super.m1();
System.out.println("Child : m1");
}
void m2(){
System.out.println("Child : m2");
m1();
}
}
Run Code Online (Sandbox Code Playgroud)
此代码导致java.lang.StackOverflowError,因为当调用Parent类的m1()方法时,它调用m2()方法,这是child的m2()方法,因此导致StackOverflowError.
什么应该在Parents m1()方法中更改,以便它调用Parent的m2()方法而不是Child的m2()方法?
在以下程序中.
public class SerialExample {
public static void main(String args[]) throws Exception{
ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("out.txt"));
Car c = new Car(20);
os.writeObject(c);
c.setSpeed(30);
os.writeObject(c);
os.close();
ObjectInputStream in = new ObjectInputStream(new FileInputStream("out.txt"));
Car d = (Car)in.readObject();
Car e = (Car)in.readObject();
System.out.println(d.getSpeed() + " " + e.getSpeed());
in.close();
}
}
class Car implements Serializable{
private int speed;
Car(){
speed = 1;
}
Car(int speed){
this.speed = speed;
}
public int getSpeed(){
return speed;
}
public void setSpeed(int speed){
this.speed = …
Run Code Online (Sandbox Code Playgroud)