java执行代码 java 执行

java如何把复制的代码运行

1、新建一个记事本,后缀名是.java,在里面写一段java的代码。

创新互联专注为客户提供全方位的互联网综合服务,包含不限于成都网站设计、成都网站制作、唐县网络推广、微信小程序、唐县网络营销、唐县企业策划、唐县品牌公关、搜索引擎seo、人物专访、企业宣传片、企业代运营等,从售前售中售后,我们都将竭诚为您服务,您的肯定,是我们最大的嘉奖;创新互联为所有大学生创业者提供唐县建站搭建服务,24小时服务热线:18982081108,官方网址:www.cdcxhl.com

2、把写好的java文件放进D盘,就是第一步给出的那个class文件。

3、打开dos界面,开始-运行-cmd-这个是命令行模式,选择D盘。

4、在命令提示符中输入javac文件名.java,输入javacjava.java回车,等待编译。接下来是java环境变量设置的问题。

5、下载一个jdk执行默认安装。

6、配置环境:右击电脑点属性,进去点高级就能看到环境变量。点进去就能设置系统变量。

java 这段代码要怎么执行

public class Student

{

private String strName = ""; // 学生姓名

private String strNumber = ""; // 学号

private String strSex = ""; // 性别

private String strBirthday = ""; // 出生年月

private String strSpeciality = ""; // 专业

private String strAddress = ""; // 地址

public Student(String name, String number)

{

this.strName = name;

this.strNumber = number;

}

public String getStudentName()

{

return this.strName;

}

public void setStudentSex(String sex)

{

this.strSex = sex;

}

public String getStudentSex()

{

return this.strSex;

}

public String getStudentBirthday()

{

return this.strBirthday;

}

public void setStudentBirthday(String birthday)

{

this.strBirthday = birthday;

}

public String getStudentSpeciality()

{

return this.strSpeciality;

}

public void setStudentSpeciality(String speciality)

{

this.strSpeciality = speciality;

}

public String getStudentAddress()

{

return this.strAddress;

}

public void setStudentAddress(String address)

{

this.strAddress = address;

}

public String toString()

{

String information = "学生姓名=" + this.strName + ", 学号=" + this.strNumber;

if (!this.strSex.equals(""))

information += ", 性别=" + this.strSex;

if (!this.strBirthday.equals(""))

information += ", 出生年月=" + this.strBirthday;

if (!this.strSpeciality.equals(""))

information += ", 专业=" + this.strSpeciality;

if (!this.strAddress.equals(""))

information += ", 籍贯=" + this.strAddress;

return information;

}

// 你要加一个main方法,且上面都要加上this,你跟你之前的代码对比一下,就知道了

public static void main(String[] args)

{

Student student = new Student("admin", "001");

System.out.println(student.toString());

}

}

java代码执行顺序是怎样的

java代码执行顺序一般按照以下规则:

1.

从上往下,从左往右。

2.

如果是在

if

表达式中,且有多个表达式,中间是(并去)关联的,那么,第一个不符合,那么右边的表达式都不会去比或计算了。同理,如果是多个表达式,但用

||(或者)

关联的,那么第一个表达式符号条件的话,就直接进入if

了,右边的表达式就不会再去计算了。

java中怎么执行字符串中的代码

在javascript中eval()可以实现字符串转代码,java中需要使用动态编译。

把获得的字符串写入一个临时文件中,然后编译它,在调用其中的函数。

我们把要转换的字符串构造一个完整的类:如果方法是有返回值的.则:

public object eval(string str){

//生成java文件

string s = "class temp{";

s += "object rt(){"

s += "myclass mc = new myclass();"

s += " return mc."+str+"();";

s += "}"

s +="}";

file f = new file("temp.java");

printwriter pw = new printwriter(new filewriter(f));

pw.println(s);

pw.close();

//动态编译

com.sun.tools.javac.main javac = new com.sun.tools.javac.main();

string[] cpargs = new string[] {"-d", "所在目录","temp.java"};

int status = javac.compile(cpargs);

if(status!=0){

system.out.println("没有成功编译源文件!");

return null;

}

//调用temp的rt方法返回结果:

myclassloader mc = new myclassloader();

class clasz = mc.loadclass("test.class",true);

method rt = clasz.getmethod("rt", new class[]{ string[].class });

return rt.invoke(null, new object[] { new string[0] });

//如果方法没有返回就直接调用

}

我们可以先写好多个重载的eval,有返回值和没有返回值的.以及可以传递参数的.

这样我们就可以用字符串转换为java的语句来执行.

JAVA代码怎么运行

首先你的电脑上面必须安装java jdk ,默认安装就好, jdk分32位和64位,要下和你电脑系统一致的

然后配置java环境变量,网上有方法,容易找

然后下载eclipse软件,官网就有,上面两步完成的话eclipse解压就能用。eclipse位数也要和电脑系统一致

在eclipse中新建java代码,复制代码进去,然后点击run运行就行。

上面就是教你如何运行java代码了

当前题目:java执行代码 java 执行
标题来源:https://www.cdcxhl.com/article14/hhiide.html

成都网站建设公司_创新互联,为您提供ChatGPTApp开发小程序开发电子商务外贸网站建设

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联

成都定制网站建设