例如,我们有下一堆:Struts,Spring,Hibernate.你能帮我理解每个元素所起的作用吗?
我知道这Hibernate对数据库的所有人负责.
但是,什么样的作用Struts,并Spring在这种情况下?
谢谢.
好吧,我真的很陌生,我甚至不确定我问的是正确的问题,但我想创建一个具有一些regualr值的对象,如字符串和整数等.但另外我想要一个属性是一个像这样的字符串数组:
int hp =100;
int level =1;
int exp=0;
String[] items = {"hpPot","blank","blank","blank","blank"};
return new player(level, exp, hp, name, items[] );
}
Run Code Online (Sandbox Code Playgroud)
这不起作用,至少我想确切知道原因.
谢谢.
这是装饰模式的一个例子.
public class Computer {
public String Description(){
return "Computer";
}
}
public abstract class Decorator extends Computer{
public abstract String description();
}
public class Monitor extends Decorator{
Computer computer;
public Monitor(Computer c){
computer = c;
}
public String description() {
return computer.Description() + " and Monitor";
}
}
public class main {
public static void main(String args[]){
Computer c = new Computer();
Monitor m = new Monitor(c);
System.out.println(m.description());
}
}
Run Code Online (Sandbox Code Playgroud)
调用超类的超级方法是否相同?比如当监视器从计算机继承然后调用监视器类中的Description方法内的计算机类中的super.Description()?
第一次发布在这里.
我正在编写一个Java程序,它接受一个输入文本文件,读取内容,然后将它们打印到屏幕上,并创建一个包含内容的输出文件.我已经设置了必要的编写器,但是当我尝试使用BufferedReader readername = new BufferedReader(new FileReader(inFile));它时,会在标题中给出错误.
是什么导致它的想法?
这是代码.
public class FileReader
{
public static void main(String[] args) throws IOException
{
try
{
File inFile = new File("inputText.txt");
BufferedReader reader = new BufferedReader(new FileReader(inFile));
String line = null;
BufferedWriter writer = new BufferedWriter(new FileWriter("Contents.txt"));
while ((line=reader.readLine()) != null)
{
writer.write(line);
System.out.println("File 'Contents.txt' successfully written");
System.out.println(line);
}
}
catch (IOException e)
{
System.out.println(e);
}
}
}
Run Code Online (Sandbox Code Playgroud) 假设用户输入一个int 123214
我已设法分开数字,但我如何将数字乘以1和其他.
我想要 1*2*3*2*1*4
我将所有单个数字放入一个数组,但我不能将它们乘以我想要的一个和另一个.
向我转发了一项要求,将动态 RTF 文档转换为 PDF,在转换之前填充 RTF 中的所有属性。
遵循此博客文章中的确切示例,我NullPointerException在运行应用程序时遇到了一个。
注意:我知道 iText 上的 RTF 文档支持已被放弃,但它已被客户端使用。
确切的堆栈跟踪:
Exception in thread "main" java.lang.NullPointerException
at com.lowagie.text.rtf.parser.destinations.RtfDestinationFontTable.importSystemFonts(RtfDestinationFontTable.java:571)
at com.lowagie.text.rtf.parser.destinations.RtfDestinationFontTable.init(RtfDestinationFontTable.java:206)
at com.lowagie.text.rtf.parser.destinations.RtfDestinationFontTable.setParser(RtfDestinationFontTable.java:190)
at com.lowagie.text.rtf.parser.destinations.RtfDestinationMgr.addDestination(RtfDestinationMgr.java:184)
at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordHandler.<init>(RtfCtrlWordHandler.java:175)
at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordMap.<init>(RtfCtrlWordMap.java:607)
at com.lowagie.text.rtf.parser.ctrlwords.RtfCtrlWordMgr.<init>(RtfCtrlWordMgr.java:93)
at com.lowagie.text.rtf.parser.RtfParser.init(RtfParser.java:655)
at com.lowagie.text.rtf.parser.RtfParser.convertRtfDocument(RtfParser.java:551)
at za.co.sindi.utils.Prints.printToPDFWithIText(Prints.java:114)
at za.co.sindi.utils.Prints.main(Prints.java:150)
Run Code Online (Sandbox Code Playgroud)
源码示例:
public static void printToPDFWithIText() {
InputStream input = null;
OutputStream output = null;
Document document = null;
try {
input = new BufferedInputStream(new FileInputStream(new File("C:/testPDF.rtf")));
output = new BufferedOutputStream(new FileOutputStream(new File("C:/testPDF_" + …Run Code Online (Sandbox Code Playgroud) 目前我正在使用以下数据结构:
MyObject[] arr = new MyObject[100]
Run Code Online (Sandbox Code Playgroud)
现在Array中的大多数字段实际上都是null(比方说97%)
据我所知,JVM为每个字段预留了一个实例所需的内存,MyObject因此即使从未真正使用过,也会保留大量内存.
有没有办法节省记忆?就像只MyObject按需分配空间一样?有一个更好的数据结构,然后只是一个简单的数组?(需要既高效又快速)
属性getTextContent()和getValue()属性之间有区别吗?
在以下情况下,它会将相同的内容打印到控制台中。我已经发现getNodeValue()并且getValue是相同的(根据http://docs.oracle.com/javase/7/docs/api/org/w3c/dom/Node.html#getNodeValue())。
XML:
<Request w="4.2">
Run Code Online (Sandbox Code Playgroud)
代码:
getString("Request", rootElement);
Run Code Online (Sandbox Code Playgroud)
和
void printAtt(String tagName, Element element) {
NodeList list = element.getElementsByTagName(tagName);
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
Element nodeElement = (Element) node;
Attr attribute = nodeElement.getAttributeNode("w");
System.out.println("ATTR NAME: " + attribute.getName());
System.out.println("ATTR TEXT CONTENT: " + attribute.getTextContent());
System.out.println("ATTR VALUE: " + attribute.getValue());
System.out.println("ATTR NODE VALUE: " + attribute.getNodeValue());
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:
ATTR NAME: w …Run Code Online (Sandbox Code Playgroud) 前段时间,在我的工作中,我需要保护一些课程,以防止其他人阅读代码.为此,我创建了一个EncryptedClassLoader,它加载了以前加密的类,并且还可以加载普通(未加密)类.以这种方式工作有点复杂,并且也进行测试(编译,然后加密,然后解密).
是否有任何免费框架可以做我需要的,并且易于处理?我的意思是,不仅混淆,而且还加密文件,所以没有人可以读取或调试这部分代码.我可以很容易地更改加密密钥(在我的应用程序中,它是硬编码的).
提前致谢.
我熟悉使用.NET/PHP创建和使用Web服务,但不熟悉Java Servlet.
它们只相当于使用.NET创建Web服务吗?
java ×10
arrays ×2
.net ×1
attributes ×1
classloader ×1
encryption ×1
filereader ×1
hibernate ×1
itext ×1
jvm ×1
memory ×1
object ×1
pdf ×1
php ×1
protection ×1
rtf ×1
servlets ×1
spring ×1
string ×1
struts ×1
variables ×1
web-services ×1
xml ×1