您的位置 首页 java

解析eclipse和idea运行java程序的过程

1 idea篇

1.1 生成. class文件 的时机

按下了 ctrl+shift++F10或者shift+f10 有内容变动时 才会生成class文件,若已经存在同名的class文件,会被这个最新生成的class文件给覆盖掉

1.2 错误示范测试

1.2.1 操作流程

a. 找到class文件

a.1 右键—>Open in—–> File path 双击它

a.2 在弹出的面板处选择src并双击它

a.3 在打开的 文件目录 ,找到out目录并进入它

a.4 找到out目录里面中你所需要的class文件

选择文件所在的包,双击进入它

找到对应的class文件

b. 删除class文件

b.1 删除class文件前

b.2 删除class文件后

c 按下shift+f10(代码没有变更,会去找class文件)

1.2.1 错误信息提示

注意:是代码没有变更的时候,会去寻找class文件,若代码变更了,按下shift+f10会生成新的class文件,然后程序正常运行

1.3 正确示范测试

1.3.1 内容

每次运行程序时, 要去变动内容 (输出语句多加上一个空格),然后shift+alt+f10,会生成class文件并执行它

1.3.2 按下shift+ctrl+F10之前

1.3.3 按下shift+ctrl+F10之后

去out目录下看发现已经生产了对应的class文件

1.3.4 示例代码

 <pre class="prettyprint hljs java" style=" padding : 0.5em; font-family: Menlo, Monaco, Consolas, " Courier  New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block;  margin : 0px 0px 1.5em; font-size: 14px;  line-height : 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px;  text-decoration -style: initial; text-decoration-color: initial;">,package Work;
public class  Test05  { 
    public   static    void   main(String[] args)  { 
        System.out.println("加油吧!追风少年们!!!");
    }
}</pre>
  

1.3.5 运行结果截图

2 eclipse

2.1 生成.class文件的时机

​ 按下ctrl+s就会生成.class文件

2.2 错误示范测试

2.2.1 操作流程

a. 找到class文件的位置

a.1 右键—>File—–>Properties 双击它

a.2 点击右侧按钮,定位到Test.java文件的位置

a.3 找到需要删除的class文件

b. 删除class文件

b.1 删除class文件前

b.2 删除class文件后

c 按下运行绿色键

2.2.1 错误信息提示

2.3 正确示范测试

2.3.1 内容

每次运行程序时, 要去变动内容 (输出语句多加上一个空格),然后ctrl+s,会生成class文件

然后按下run运行键值就可以正常去运行了。

2.3.2 更改内容按下ctrl+s前

2.3.3 按下ctrl+s之后

此时 bin 目录下也生成了对应的class文件

2.3.4 示例代码

 <pre class="prettyprint hljs cs" style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, "Courier New", monospace; color: rgb(68, 68, 68); border-radius: 4px; display: block; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; overflow-wrap: break-word; white-space: pre; background-color: rgb(246, 246, 246); border: none; overflow-x: auto; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration-style: initial; text-decoration-color: initial;">public class Test { 
    public  static  void  main(String[] args)  { 
        System.out.println("幸福是靠奋斗出出来的!!!努力学习");
    }
}</pre>
  

2.3.5 运行结果截图

3.1 idea只有在 内容出现变更 按下ctrl+shift+f10 (或shift+f10)时才会生成class文件,并不是说自动保存的时候会给你生成class文件.自动保存的作用是保存文件信息,防止因为电脑没电或者死机丢失文件信息(类似于word里面的自动保存的功能)

3.2 eclipse 只要出现内容变化 (最终可以无变化,先增加一个空格,后减少一个空格), 会显示图标 * ,这个时候我们只要ctr+s就会自动生成class文件了(若之前有,就会覆盖)

文章来源:智云一二三科技

文章标题:解析eclipse和idea运行java程序的过程

文章地址:https://www.zhihuclub.com/200071.shtml

关于作者: 智云科技

热门文章

网站地图