我正在集思广益一个应用程序,在这个应用程序中,每秒可能有两个不同来源的中断(单独的中断),每个中断都运行一个函数,只需在计数中添加一个数字.我需要我void loop()用这些数据进行简单的分析.我想知道在主循环运行时中断是否异步运行,或者它们是否在处理过程中停止了主循环?
我的主循环确实要求millis()函数正常工作,我知道在Arduino引用的中断中是不可能的,如果中断同步运行,我将不得不查看其他解决方案.
我如何计算一个项目ArrayList?
ArrayList list1= new ArrayList();
list1.add("a");
list1.add("b");
list1.add("c");
list1.add("d");
list1.add("e");
...........
result.setMessage(list1.size()); // = 5
...........
Run Code Online (Sandbox Code Playgroud)
这是行不通的.错误在哪里?
我们可以使用传递引用或通过引用调用在Java中交换两个数字吗?最近,当我遇到用Java交换两个数字时,我写道
class Swap{
int a,b;
void getNos(){
System.out.println("input nos");
a = scan.nextInt();
b = scan.nextInt(); // where scan is object of scanner class
}
void swap(){
int temp;
temp = this.a;
this.a = thisb;
this.b = this.a;
}
}
Run Code Online (Sandbox Code Playgroud)
在main方法中我调用上面提到的方法并取两个整数a,b然后使用第二个方法我交换两个数字,但相对于对象本身....
该程序或逻辑是否通过引用传递?这是正确的解决方案吗?
我一直在努力解决这个问题,我似乎无法修复它.我已经尝试过不同的方法(Runtime.exec(),ProcessBuiler),但似乎都没有.
这是我的问题.我有一台永远在线的笔记本电脑.这台笔记本电脑运行一个java工具连接到arduino通过USB打开和关闭房子里的灯.我自己创建了这个程序,因此我也在做一些定期的维护工作.最近我添加了一个按钮,从我的html界面重启程序(如果我有更新,或者由于某些其他原因我可能需要重新启动程序或我决定在不久的将来实现自动更新).
这背后的想法是从第一个实例启动应用程序的第二个实例,然后从System.exit(0)启动第一个实例.
由于某种原因,我无法启动应用程序的第二个实例.这是一些代码.
public void shutdown(boolean restart) {
if (this.serial != null) {
this.serial.disconnect();
}
if (restart) {
System.out.println(this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
String startupCommand = "java -jar \"" + this.getClass().getProtectionDomain().getCodeSource().getLocation().getPath().replace("%20", " ") + "\"";
ProcessBuilder builder = new ProcessBuilder();
// String[] command = new String[1];
// command[0] = "-jar \"" + (System.getProperty("user.dir") + "/Home_Automation_Executor.jar") + "\"";
try {
// //System.out.println("Restarting Home Automation with command: " + command[0]);
// System.out.println("Restarting Home Automation with command: " + startupCommand);
// Runtime.getRuntime().exec("bash");
// Process proc = …Run Code Online (Sandbox Code Playgroud) 实施Java安全管理器会导致性能下降吗?
如何从2011年10月15日1:52:34 PM获得毫秒数
我可以从当前时间获得毫秒数.
Date date = new Date();
long currentTime = date.getTime();
System.out.println("Current time in long: " + currentTime);
Run Code Online (Sandbox Code Playgroud) 按照惯例,Java中的静态方法只能访问静态字段或其他静态方法.但是,以下简单的代码段似乎违反了约定.让我们考虑Java中的以下简单代码片段.
class Super
{
protected static int x;
protected static int y;
public Super(int x, int y)
{
Super.x=x;
Super.y=y;
}
public static int sum()
{
return(x+y);
}
}
final class Sub extends Super
{
public static int temp=100;
public Sub(int x, int y)
{
super(x, y);
}
public void concreateMethod()
{
System.out.println("\nInstance variable x = "+x);
System.out.println("Instance variable y = "+y);
}
}
final public class Main
{
public static void main(String[] args)
{
Sub s=new Sub(10, 5);
System.out.println("\nAssociating …Run Code Online (Sandbox Code Playgroud) 我知道StringBuffer和之间的技术差异StringBuilder.
但如果我半年左右不使用它们,我只会忘记哪一个是同步的,哪一个不同步.我总是查找JavaDoc的第一句话.
那么:是否有某种容易记住的助记符来区分它们?如何你还记得有什么区别?
我目前正在开发一个项目(数据库实现),涉及一个名为ElementType内部枚举的枚举类TypeType.在里面ElementType有一个HashMap<TypeType, ArrayList<ElementType>>映射所有的ElementType相应的TypeType值.
值TypeType是
[TEXT, NUMERIC_EXACT, NUMERIC_APPROX, OTHER]
Run Code Online (Sandbox Code Playgroud)
ElementType(和它们对应的TypeType)的值是
[CHARACTER(TEXT),
CHAR(TEXT),
DECIMAL(NUMBER_EXACT),
DEC(NUMBER_EXACT),
NUMERIC(NUMERIC_EXACT),
INTEGER(NUMERIC_EXACT),
INT(NUMERIC_EXACT),
SMALLINT(NUMERIC_EXACT),
FLAT(NUMERIC_APPROX),
REAL(NUMERIC_EXACT),
DOUBLE_PRECISION(NUMERIC_APPROX),
DOUBLE(NUMERIC_APPROX),
DATE(OTHER),
TIME(OTHER),
VARCHAR(OTHER),
LONG_VARCHAR(OTHER)]
在一个static {}地区,我有这个代码:
for(ElementType eType : values()) {
TypeType t = eType.getTYPE();
if(typeMapping.get(t) != null)
typeMapping.get(t).add(eType);
else
typeMapping.put(t, new ArrayList<ElementType>() {add(eType);});
}
Run Code Online (Sandbox Code Playgroud)
eType在for循环中的所有提及都在Eclipse中用下划线标记为红色.
第一个给出了错误eType cannot be resolved.
第二个给出eType cannot be resolved to a variable …
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
try {
ndef.addDataType("*/*"); /* Handles all MIME based dispatches.
You should specify only the ones that you need. */
}
catch (MalformedMimeTypeException e) {
throw new RuntimeException("fail", e);
}
intentFiltersArray = new IntentFilter[] {ndef, };
Run Code Online (Sandbox Code Playgroud)
所以在这里intentFiltersArray[0] = ndef.怎么样intentFiltersArray[1]?在上面的代码中有什么,后面的ndef意思?
同样,它有另一个代码示例
techListsArray = new String[][] { new String[] { NfcF.class.getName() } };
Run Code Online (Sandbox Code Playgroud)
怎么techListsArray[][]在这里初始化?我猜techListsArray[0][0]=NfcF.class.getName()(应该不NfcF应该这样?)但其他元素呢?或者它只有一个元素?
java ×8
android ×2
arduino ×1
asynchronous ×1
embedded ×1
enums ×1
inheritance ×1
methods ×1
performance ×1
process ×1
security ×1
static ×1
stringbuffer ×1
swap ×1