老师创建出来的Q1里面乱码了
老师这个System.out.println(oldlu);显示打印是true.而不是oldlu,因为此时这个oldlu 已经转换成了boolean类型的 是吧?
这个是单例不是定义原型,单列不是一串。是不是打错字了
这个length是从哪来的?
老师,您好。为什么我的创建 “c:/b.txt”不成功呢?哪里出了问题?
package com.itbaizhan; import java.io.File; import java.io.IOException; public class TestFile1 { public static void main(String[] args) throws Exception { System.out.println(System.getProperty("user.dir")); File f = new File("a.txt"); f.createNewFile(); File f2 = new File("c:/b.txt"); f2.createNewFile(); } }
老师,您好。
我这个“user.dir”是红线,原因出在哪里?
package com.itbaizhan; import java.io.File; import java.io.IOException; public class TestFile1 { public static void main(String[] args) throws Exception { System.out.println(System.getProperties("user.dir")); File f = new File("a.txt"); f.createNewFile(); File f2 = new File("c:/b.txt"); f2.createNewFile(); } }
为什么我执行的结果是负的?
package com.itbaizhan; public class TestString2 { public static void main(String[] args) { String str8 = ""; long num1 = Runtime.getRuntime().freeMemory();//获取系统剩余内存空间 long time1 = System.currentTimeMillis();//获取系统的当前时间 for(int i=0;i<5000;i++){ str8 = str8+i;//相当于产生了5000的对象 } long num2 = Runtime.getRuntime().freeMemory(); long time2 = System.currentTimeMillis(); System.out.println("String占用内存:"+(num1-num2)); System.out.println("String占用时间:"+(time2-time1)); /**使用StringBuilder进行字符串的拼接*/ StringBuilder sb1 = new StringBuilder(""); long num3 = Runtime.getRuntime().freeMemory(); long time3 = System.currentTimeMillis(); for(int i=0;i<5000;i++){ sb1.append(i); } long num4 = Runtime.getRuntime().freeMemory(); long time4 = System.currentTimeMillis(); System.out.println("StringBuilder占用内存:"+(num3-num4)); System.out.println("SttingBuilder占用时间:"+(time4-time3)); } }
sb.append("1").append("2").append("3"); 这句不太理解,这句执行的结果是是什么样的?谢谢老师!
package com.itbaizhan; public class TestString { public static void main(String[] args) { String s1 = new String("abcdef"); String s2 = s1.substring(2,4); System.out.println(Integer.toHexString(s1.hashCode())); System.out.println(Integer.toHexString(s2.hashCode())); String str1 = "hello"+"java";//相当于str1 = "hello java"; //编译器做了优化,直接在编译的时候将字符串进行拼接 String str2 = "hellojava"; System.out.println(str1==str2);//true String str3 = "hello"; String str4 = "java"; //编译的时候不知道变量中存储的是什么,所以没有办法在编译的时候优化 String str5 = str3+str4; System.out.println(str5); System.out.println(str2==str5);//false String str = "abc"; StringBuilder sb = new StringBuilder("abc"); StringBuffer sb2 = new StringBuffer("abc"); /**StringBuilder*/ StringBuilder sb3 = new StringBuilder(); for(int i=0;i<7;i++){ sb.append((char)('a'+i)); } System.out.println(sb.toString());//转换成String输出 sb.append("1").append("2").append("3"); } }
package com.itbaizhan; import java.beans.PersistenceDelegate; import java.time.Period; //测试自定义异常 class Person { private String name; private int age; public void setName(String name) { this.name = name; } public void setAge(int age) throws IllengalAgeException { if (age < 0) { throw new IllengalAgeException("人的年龄不应该为负数!"); } this.age = age; } public String toString() { return "name is" + name + "and age is" + age; } public class TestMyException { public static void main(String[] args) { Person p = new Person(); p.setName("lsx"); try { p.setAge(10); } catch (IllengalAgeException e) { e.printStackTrace(); } System.out.println(p); } } }
按照代码来弄,但是static 报错,请问是什么问题呀?
public static void main(String[] args) throws IOException { File f = new File("d:/b.txt"); f.createNewFile(); System.out.println("File是否存在:"+f.exists()); System.out.println("File是否是目录:"+f.isDirectory()); System.out.println("File是否是文件:"+f.isFile()); System.out.println("File的最后修改时间:"+new Date(f.lastModified()));//File的最后修改时间:Thu Oct 06 21:05:42 CST 2022 System.out.println("File的最后修改时间:"+f.lastModified());//File的最后修改时间:1665061542807 System.out.println("File的大小:"+f.length()); System.out.println("File的文件名:"+f.getName()); System.out.println("File的目录路径:"+f.getAbsolutePath());
老师,我对那个new Date(f.lastModified())和f.lastModified()这两行代码不太明白,运行的结果我也注释 在后面了,但是我该怎么理解呢,如果让我去写file的最后修改时间,我也只会写成file.lastModified(),不会去new一个,我不太理解new这个是什么意思。 我并没有写new Date的一个日期定义规范,为什么它会输出规范的日期呢? 我可不可以理解为new Date...是按照object里已经定义好的new Date()方法规范呢?
怎么没有笔记了啊,打完有错都不能对代码了
老师,这个capacity扩容是自动进行的吗?没有调用就自动扩容了吗
老师这个static 为什么有红线?最下面的括号有红线,看不出哪里有错误呢?
package com.itbaizhan; //测试自定义异常 class Person{ private String name; private int age; public void setName(String name){this.name = name;} public void setAge(int age)throws IllegalAgeException{ if(age<0){ throw new IllegalAgeException("人的年龄不应该为负数") ; } this.age = age ; } public String toString(){return "name is"+name+"and age is"+age; } public class TestMyException { public static void main(String[] args) { Person p = new Person(); p.setName("gaoqi"); try { p.setAge(100); } catch (IllegalAgeException e) { e.printStackTrace(); } System.out.println(p); } }
老师,这句话如何理解?是调用pop方法并将它的返回值,赋给mt吗?
非常抱歉给您带来不好的体验!为了更深入的了解您的学习情况以及遇到的问题,您可以直接拨打投诉热线:
我们将在第一时间处理好您的问题!
关于
课程分类
百战程序员微信公众号
百战程序员微信小程序
©2014-2025百战汇智(北京)科技有限公司 All Rights Reserved 北京亦庄经济开发区科创十四街 赛蒂国际工业园网站维护:百战汇智(北京)科技有限公司 京公网安备 11011402011233号 京ICP备18060230号-3 营业执照 经营许可证:京B2-20212637