Java中的第一个程序 [英] First program in Java

查看:103
本文介绍了Java中的第一个程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在ubuntu 12.04上安装了Netbeans 7
我试图编写我的第一个Java应用程序,这是我的代码

i have Netbeans 7 over ubuntu 12.04
i tried to write my first java application and this is my code

package first_pro;
import java.io.*;

/**
 *
 * @author amir
 */
public class First_pro
{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException
    {
        byte [] name=new byte[100];
        String thename="";
       System.out.println("Enter your name:");
       System.in.read(name);
       for(int i=0;i<100;i++)
       {
           if(name[i]==10)
           {
               break;
           }
           else
           {
               thename+=(char)name[i];
           }
           
       }
       if(thename.equals("amir"))
       {
           System.out.print("the enter name is right it is "+thename+"\n");
           
       }
       else
       {
           System.out.print("the enter name is wrong it is "+thename+"\n");
       }
    }
}



我创建了jar文件

当我尝试双击它时(我默认使用open jdk java runtime 6使其运行)

什么都没发生

当我尝试打开jdk 7时也没有任何反应

我使用终端运行jdk,并且运行良好

我如何通过双击使用openjdk运行我的jar文件?



i created the jar file

when i tried to double click on it(i made it to run by default using open jdk java runtime 6)

nothing happened

when i tried open jdk 7 also nothing happen

i run the jdk using terminal and it run good

how can i run my jar file using openjdk by double click it ?

推荐答案

由于它的方式,我认为双击不适用于Java类希望读取目标文件的路径名.您的类需要使用以下格式的命令从类文件位置上方的目录中执行:
I don''t think double-click works well with Java classes owing to the way it expects to read the pathname to the object file. Your class needs to be executed from the directory above the location of the class file with a command of the form:
java first_pro.First_pro


如果最终对象是jar文件,则必须为


If the final object is a jar file then it needs to be

java -jar <name of jar file>


这篇关于Java中的第一个程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆