假设一个项目包含几个类,每个类都有一个静态初始化块.这些块以什么顺序运行?我知道在一个类中,这些块按照它们在代码中出现的顺序运行.我已经读过它在各个类中都是一样的,但是我写的一些示例代码不同意这一点.我用过这段代码:
package pkg;
public class LoadTest {
    public static void main(String[] args) {
        System.out.println("START");
        new Child();
        System.out.println("END");
    }
}
class Parent extends Grandparent {
    // Instance init block
    {
        System.out.println("instance - parent");
    }
    // Constructor
    public Parent() {
        System.out.println("constructor - parent");
    }
    // Static init block
    static {
        System.out.println("static - parent");
    }
}
class Grandparent {
    // Static init block
    static {
        System.out.println("static - grandparent");
    }
    // Instance init block
    {
        System.out.println("instance - grandparent");
    }
    // Constructor
    public Grandparent() { …我正在考虑使用Java创建自己的网站,并试图决定使用什么框架.但是,快速搜索Java框架可以选择50多个!
我的网站只是为了我自己在开始时构建它的乐趣,但如果它变得流行,那么它具有一定的可扩展性,或者至少能够为此重新设计将是一件好事.
更受欢迎的框架之间的主要区别是什么?有没有一个显着优于其他人的情况?例如,高流量企业应用程序与低流量小型应用程序.我也想知道有些人比其他人更容易学习和使用.
是否有人对这些框架有一些经验并可以提出建议?绝对数量的选择是否可以作为早期警告,以尽可能避免基于Java的Web开发?
我想在整个网站上使用一个名为"Algerian"的字体.所以,我需要更改所有HTML标签,我不想为不同的标签编写不同的代码,例如:
button{font-family:Algerian;}
div{font-family:Algerian;}
下面写的方法也非常不鼓励:
div,button,span,strong{font-family:Algerian;}
我使用Maven 2 POM编辑器主要是直接编辑POM XML文件.有没有办法让编辑器始终在"源"选项卡中打开文件?
据我所知,以下两个代码片段都将起到同样的作用.为什么要有finally块?
代码A:
try { /* Some code */ }
catch { /* Exception handling code */ }
finally { /* Cleanup code */ }
代码B:
try { /* Some code */ }
catch { /* Exception handling code */ }
// Cleanup code
有没有办法让Eclipse的内置Java代码格式化程序忽略注释?每当我运行它,它会变成这样:
    /*
     * PSEUDOCODE
     * Read in user's string/paragraph
     * 
     * Three cases are possible
     * Case 1: foobar
     *         do case 1 things
     * Case 2: fred hacker
     *         do case 2 things
     * Case 3: cowboyneal
     *         do case 3 things
     *         
     * In all cases, do some other thing
     */
进入这个:
    /*
     * PSEUDOCODE Read in user's string/paragraph
     * 
     * Three cases are possible Case 1: foobar do case 1 things Case 2: fred
     * hacker do …我有一个名为$effectiveDate包含日期2012-03-26的变量.
我试图在这个日期增加三个月并且没有成功.
这是我尝试过的:
$effectiveDate = strtotime("+3 months", strtotime($effectiveDate));
和
$effectiveDate = strtotime(date("Y-m-d", strtotime($effectiveDate)) . "+3 months");
我究竟做错了什么?两段代码都没有用.