我读过上一篇文章.任何人都可以说CharSequence
和String 之间的确切区别是什么,除了String
实现的事实CharSequence
和那String
是一个字符序列?例如:
CharSequence obj = "hello";
String str = "hello";
System.out.println("output is : " + obj + " " + str);
Run Code Online (Sandbox Code Playgroud)
当"hello"分配给obj
和再次分配时会发生什么str
?
我正在尝试检查程序的性能.我在这篇文章中提到了OS级系统信息.当Runtime.availableProcessors()
执行时,我得到的答案4.我读了availableProcessors()但它告诉该方法返回处理器数
我使用的是Windows 7核心i5 4gp.
我正在尝试构建一个聊天应用程序.我有一个代码将数据从客户端发送到服务器.当一个或多个客户端登录时(当客户端程序运行一次或多次时).server将不接受除首次连接之外的其余连接.请帮我解决这个问题,这是我的代码:
public class Server
{
//Creating non blocking socket
public void non_Socket() throws Exception {
ServerSocketChannel ssChannel = ServerSocketChannel.open();
int port = 80;
int i=0;
ssChannel.socket().bind(new InetSocketAddress(port));
ssChannel.configureBlocking(false);
while(true)
{
SocketChannel sc = ssChannel.accept();`
if (sc == null)
{
System.out.println("Socket channel is null");
Thread.sleep(5000);
}
else
{
System.out.println("Socket channel is not null");
System.out.println("Received an incoming connection from " +
sc.socket().getRemoteSocketAddress());
new PrintRequest(sc,i).start();
i++;
}
}
}
public static void main(String [] abc) throws Exception
{
new Server().non_Socket();
}
}
class …
Run Code Online (Sandbox Code Playgroud) public class MemoryLeakExample {
public static void main(String[] args) {
while (true) {
System.gc();
}
}
}
Run Code Online (Sandbox Code Playgroud)
如何在这个程序中泄漏内存?通过NETBEANS分析器进行监控时,内存逐渐增加.指导我如果错了,任何帮助表示赞赏. 在5分钟之前USED HEAP SIZE是:2257416之后:2258360
谢谢.
我得到一个"javax.net.ssl.SSLException:收到致命警报:bad_record_mac"用于https连接.每次请求都不会发生这种情况 - 如果我在10次内发送相同的请求,我只会收到一次或两次此错误.
我有以下代码来验证证书:
TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) {
}
public void checkServerTrusted(X509Certificate[] certs, String authType) {
}
} };
try {
SSLContext sslContext = null;
try {
sslContext = SSLContext.getInstance("SSLv3");
} catch (NoSuchAlgorithmException e3) {
logException(Arrays.toString(e3.getStackTrace()));
}
sslContext.init(null, trustAllCerts, new java.security.SecureRandom());
SSLSocketFactory factory = sslContext.getSocketFactory();
HttpsURLConnection.setDefaultSSLSocketFactory(factory);
} catch (KeyManagementException e) {
logException(Arrays.toString(e.getStackTrace()));
}
// Create all-trusting host name verifier
HostnameVerifier allHostsValid …
Run Code Online (Sandbox Code Playgroud) ..我根据单元格的值着色了一列,但我想在gxt网格中为整行(表示包含行的单元格)着色帮助我这里是我的单元格着色代码(我想为行而不是单元格着色)
/*------------Coloring Area------------*/
GridCellRenderer<BeanModelType> ColoredGrid = new GridCellRenderer<BeanModelType>() {
@Override
public Object render(BeanModelType model,
String property, ColumnData config,
int rowIndex, int colIndex,
ListStore<BeanModelType> store,
Grid<BeanModelType> grid) {
String valueOfCell = model.get(property);
String style = valueOfCell.equals("Book") ? "GREEN":
valueOfCell.equals("Ersr") ? "red":
valueOfCell.equals("Pen") ? "yellow":
valueOfCell.equals("comp") ? "blue": "";
//Config is the cell and we are setting style here
config.style ="background-color:"+style;
return valueOfCell;
}
};
System.out.println("COLORRRRR "+cleanColoredGrid.toString());
column.setRenderer(ColoredGrid);
/*-------------Coloring Area Ends-------*/
configs.add(column);
Run Code Online (Sandbox Code Playgroud) 我尝试了一个断言示例
它在commandprompt中工作正常.我使用以下命令运行代码.
java -ea AssertionExample
但是在netBeans中运行时没有显示Exception示例描述断言在运行时启用时将起作用所以我们添加ea
.
我们如何在netbeans中启用断言?
我们可以为不同的 ldpi 场景创建不同的布局 XML 文件吗?
现在文件layout-ldpi
夹中放置了一个文件。我想为以下模拟器大小创建两个布局 XML 文件
3.3 WQVGA (240x400 ldpi)
3.4 WQVGA (240x432 ldpi)
Run Code Online (Sandbox Code Playgroud)
我们可以制作文件夹之类的吗
layout-ldpi 3.3
layout-ldpi 3.4
并将不同的 XML 放在两个文件夹中是否可能?
请帮我
非常新的NIO我正在建立一个聊天应用程序我在所有客户端都有连接,但在从客户端读取内容时我得到了java.nio.channels.IllegalBlockingModeException
.请帮我这里是发生异常的代码.同时达到while (rbc.read(b) != -1)
的PrintRequest class
异常occures
public class PrintRequest extends Thread
{
public PrintRequest(SocketChannel sc,int i)throws Exception
{
System.out.println("going to enter the try block of PrintRequest");
try
{
System.out.println("Am in the try block of PrintRequest");
ReadableByteChannel rbc = Channels.newChannel(sc.socket().getInputStream());
System.out.println("checking in PrintRequest 0001");
WritableByteChannel wbc = Channels.newChannel(System.out);
System.out.println("checking in PrintRequest 0010");
ByteBuffer b = ByteBuffer.allocateDirect(1024); // read 1024 bytes
// int numBytesRead = sc.read(b);
System.out.println("checking in PrintRequest 0011");
while (rbc.read(b) != -1)
{
System.out.println("Am in …
Run Code Online (Sandbox Code Playgroud) 现在我的服务器从客户端读取所有消息.现在它是一种单向沟通.我想通过服务器向客户端发送消息.现在服务器在密钥是READABLE时读取消息状态它没有转向可写状态我只想知道密钥何时变为可写.
我创建了一个类,它提供了一个包含系统性能作为输出的文本文件.我想将它作为可执行的 Jar 运行.但是当我运行Jar时,我想将堆增加到1 GB.
如果我们运行这个程序,我可以这样运行:
java -Xms1200m -Xmx1300m Sample
Run Code Online (Sandbox Code Playgroud)
但是如何使用可执行的 Jar 增加堆空间?当我点击jar时,它必须以1 GB的堆空间执行.
我只是想知道:如果两个PC都在同一个局域网上,我们可以使用批处理文件从另一台PC上关闭它吗?
java ×10
nio ×3
networking ×2
windows ×2
android ×1
assertions ×1
batch-file ×1
charsequence ×1
executable ×1
grid ×1
gxt ×1
https ×1
inheritance ×1
jar ×1
lan ×1
memory ×1
memory-leaks ×1
netbeans ×1
oop ×1
performance ×1
runtime ×1
shutdown ×1
sockets ×1
ssl ×1
string ×1