我试图在命令提示符下执行一个简单的 java 程序(“HelloWorld”),而不使用设置路径选项或设置系统变量。假设 java 程序在D:\My_Programs 中 ,java 可执行文件在C:\Program Files\Java\jdk1.6.0_24\bin 中。这是我为编译所做的: C:\Program Files\Java\jdk1.6.0_24\bin>javac D:\My_Programs\HelloWorld.java它正在创建一个 .class 文件,但相同的执行策略会创建一个异常: C: \Program Files\Java\jdk1.6.0_24\bin>java D:\My_Programs\HelloWorld
Exception in thread "main" java.lang.NoClassDefFoundError: D:\My_Programs\HelloW
orld
Caused by: java.lang.ClassNotFoundException: D:\My_Programs\HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: D:\My_Programs\HelloWorld. Program will exit.
Run Code Online (Sandbox Code Playgroud)
有人可以建议如何执行此文件。在此先感谢您的帮助。
编码:
class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用Codeigniter进行项目,我通常会调用一系列模型(比如说控制器A - > modelA - > modelB - > modelC).我希望php在它调用exit()命令时遇到一些异常时停止执行.现在,如果exit()在modelB中调用该命令,它是否会仅停止执行modelB的脚本并继续执行modelA的其余部分?或者它会停止整个执行流程.
我真的不知道如何把这个问题放在这里.这个问题看起来很混乱.如果我需要修改问题,请告诉我.
(在任何人说什么之前是的,这是家庭作业,但我已经把它打开并且已经把它拿回来了,我只是想明白这个用于测试.)
问题是计算代码片段的执行时间和大O. 我可以计算出大的O,但我不知道如何确定执行时间.好吧基本上我不明白的是如何计算执行时间
for(i=0; i < n; i++){
SomeJavaStatment;
for(j=0; j < 2 * n; J+= 2){
SomeJavaStatment;
SomeJavaStatment;
}
}
Run Code Online (Sandbox Code Playgroud)
正确答案是Big O(n ^ 2)我说得对,但我不知道执行时间是什么,正确的答案是4n ^ 2 + 5n + 2.
如果有人能解释我将如何得到答案,我将不胜感激.
对Slim Framework php有疑问.
在我的应用程序中,如果条件不匹配,我想停止应用程序执行.
根据Slim文档,有一个暂停功能.但这似乎并没有起作用.即使在调用Halt之后,应用程序也会连续执行.
伪代码:
if ( $valid ) {
// Do something
} else {
$app->halt(500, "not valid");
}
// Other code here.
$app->run();
Run Code Online (Sandbox Code Playgroud)
我期待的是,我们称之为Halt函数,"其他代码"不应该执行.但似乎并非如此.
有任何想法吗?
据我所知,x++基本上是一种说法x = x + 1.到目前为止,这么清楚.在前端Javascript中,我偶尔会看到++x- 我似乎记得从jsPerf测试中我再也找不到了(一个Google如何++有效?)这在某个特定版本的IE中以某种方式获得了小的性能优势,并让它去那.
但是我最近遇到了一些在执行顺序(JS代码)中出现奇怪怪癖的东西:
var x = 1;
console.log(x++); // 1 (?!)
console.log(x); // 2
Run Code Online (Sandbox Code Playgroud)
...而
var x = 1;
console.log(++x); // 2 (what I would've expected)
console.log(x); // 2
Run Code Online (Sandbox Code Playgroud)
我无法理解这一点.当操作和赋值在括号内时,我们如何返回未修改的变量,因此在console.log调用之前应该执行所有权限,更不用说执行和返回了?
javascript operators execution variable-assignment order-of-execution
我的朋友是一位经验丰富的开发人员(但不熟悉.NET),他问我实际执行ASP.NET代码隐藏代码的位置; 在服务器上或客户端上.我的假设是它在客户端上执行,因此编译为JavaScript,因为代码隐藏文件中的方法将响应客户端事件,例如选择下拉列表,这不会导致回发.
我真正想要的是更加深入地了解代码隐藏文件中的代码相对于应用程序的其余部分的执行方式/位置.
这是演示我的观点的代码(java):
public static int getSize(List<String> list)
{
System.out.println("begin");
try
{
System.out.println("get list size");
return list.size();
}
catch (Exception e)
{
System.err.println("exception");
}
finally
{
System.out.println("finally");
return -1;
}
}
public static void main(String[] args)
{
List<String> list = null;
int size = getSize(list);
System.out.println("list size: " + size);
}
Run Code Online (Sandbox Code Playgroud)
我期望输出:
begin
get list size
exception
finally
list size: -1
Run Code Online (Sandbox Code Playgroud)
相反,我得到其他东西和上面的那个...就像异常可以在获取列表大小之前和异常之后显示...
例如
Run Code Online (Sandbox Code Playgroud)begin exception get list size finally list size: -1
和
Run Code Online (Sandbox Code Playgroud)begin get list size finally exception list size: -1 …
看看我的代码,它作为一只乌龟运行缓慢,我在第四代i7下运行它...而且显示结果真的很慢.有没有人有一个想法?或者这应该是一个非常缓慢的执行!?
PS:脚本的目的是找到相同方向的四个相邻数字的最大乘积,实际上在这个代码中我只是寻找上一个
#include <stdio.h>
#include <math.h>
int main(){
int A[20][20] = {
{8,02,22,97,38,15,00,40,00,75,04,05,07,78,52,12,50,77,91,8},
{49,49,99,40,17,81,18,57,60,87,17,40,98,43,69,48,04,56,62,00},
{81,49,31,73,55,79,14,29,93,71,40,67,53,88,30,03,49,13,36,65},
{52,70,95,23,04,60,11,42,69,24,68,56,01,32,56,71,37,02,36,91},
{22,31,16,71,51,67,63,89,41,92,36,54,22,40,40,28,66,33,13,80},
{24,47,32,60,99,03,45,02,44,75,33,53,78,36,84,20,35,17,12,50},
{32,98,81,28,64,23,67,10,26,38,40,67,59,54,70,66,18,38,64,70},
{67,26,20,68,02,62,12,20,95,63,94,39,63,8,40,91,66,49,94,21},
{24,55,58,05,66,73,99,26,97,17,78,78,96,83,14,88,34,89,63,72},
{21,36,23,9,75,00,76,44,20,45,35,14,00,61,33,97,34,31,33,95},
{78,17,53,28,22,75,31,67,15,94,03,80,04,62,16,14,9,53,56,92},
{16,39,05,42,96,35,31,47,55,58,88,24,00,17,54,24,36,29,85,57},
{86,56,00,48,35,71,89,07,05,44,44,37,44,60,21,58,51,54,17,58},
{19,80,81,68,05,94,47,69,28,73,92,13,86,52,17,77,04,89,55,40},
{04,52,8,83,97,35,99,16,07,97,57,32,16,26,26,79,33,27,98,66},
{88,36,68,87,57,62,20,72,03,46,33,67,46,55,12,32,63,93,53,69},
{04,42,16,73,38,25,39,11,24,94,72,18,8,46,29,32,40,62,76,36},
{20,69,36,41,72,30,23,88,34,62,99,69,82,67,59,85,74,04,36,16},
{20,73,35,29,78,31,90,01,74,31,49,71,48,86,81,16,23,57,05,54},
{01,70,54,71,83,51,54,69,16,92,33,48,61,43,52,01,89,19,67,48}};
int x = 0 ,y = 0, radar_x = 0,radar_y = 0,maior = 0,produto = 1;
while(x<=19){
while(y<=19){
printf("%d %d \n",x,y);
// verredura pra cima
if(x - 3 >= 0){
radar_x = x-3;
while(radar_x >= x-3){
produto*=A[x][y];
radar_x ++ ;
}
}
if(produto > maior)
maior = produto; …Run Code Online (Sandbox Code Playgroud) 当继承和类型转换混合时,我有点困惑.我想了解java编译器在继承中选择正确的方法和变量时遵循的规则.
我读过类似的东西
变量在编译时绑定,并且方法在运行时绑定.
第二个来自stackoverflow(@John Skeet)
根据方法目标和参数表达式的编译时类型,在编译时确定重载分辨率(调用方法签名)
该方法签名(覆盖)的实现基于执行时目标对象的实际类型.
但问题在于它们是特定情况的解释,并且在考虑其他因素(例如异常处理)时不会给出一般过程.
这可能是不好的做法,但假设方法和变量都被覆盖(隐藏在static变量的情况下).
现在,如果java编译器必须在编译时选择需要调用哪个方法/变量,那么它将采用什么算法?类似地,在运行时,java编译器将使用什么算法(基于正在使用其引用的对象的实际类型)?
我正在试图弄清楚如何计算部分程序的执行时间,但是当我使用下面的代码时,我得到的所有代码都是0.我知道这不可能是正确的.代码我正在递归地实现大量int的mergesort.如何在几毫秒内获得执行程序所需的时间?
//opening input file and storing contents into array
index = inputFileFunction(inputArray);
clock_t time = clock();//start the clock
//this is what needs to be timed
newRecursive.mergeSort(inputArray, 0, index - 1);
//getting the difference
time = clock() - time;
double ms = double(time) / CLOCKS_PER_SEC * 1000;
std::cout << "\nTime took to execute: " << std::setprecision(9) << ms << std::endl;
Run Code Online (Sandbox Code Playgroud) execution ×10
java ×4
compilation ×2
javascript ×2
php ×2
algorithm ×1
analysis ×1
asp.net ×1
big-o ×1
c ×1
c++ ×1
code-behind ×1
codeigniter ×1
exit ×1
frameworks ×1
halt ×1
inheritance ×1
operators ×1
overriding ×1
performance ×1
slim ×1
time ×1