`
默默的小熊
  • 浏览: 227492 次
社区版块
存档分类
最新评论
文章列表
import java.io.FileDescriptor; import java.io.InputStream; import java.nio.channels.FileChannel; public class FileInputStream extends InputStream { private FileDescriptor fd; private FileChannel channel = null; private Object closeLock = new Object(); private volatile boolean cl ...
import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; public class writeText { public static void main(String[] args) { // 学了数据输入了,那么学下数据输出吧 try { FileOutputStream output = new FileOutputStream("output.txt"); //好了现在我的程序中有一大 ...
    创建Java线程有两种方法: //子类化Thread public class TestThread extends Thread{ public void run(){ System.out.println("Test Thread."); } public static void main(String[] args) { Thread t = new TestThread(); t.start(); } } //方法二:提供Runnable对象 public class TestRunnable ...
public class Test { public static void main(String[] args) { int start = -131; int end = 131; for (int i = start; i < end; i++) if ((byte) i != i) System.out.println("原数:" + i + "\t转化后:" + (byte) i); } }     程序运行结果如下: 原数:-131 转化后:125 原数:-13 ...
    在Java程序中,通常会使用IO的输入输出,这里的输入输出是相对你的程序而言的。比如你写一个程序要读取一个文本文件,这里有两个对象,你的程序,还有就是文本文件。你的程序需要数据,那么用的应该是输入流(InputStream).   public class ReadText { public static void main(String[] args){ try { FileInputStream input = new FileInputStream("test.txt"); /*对于我接下来的程序,我要读取数据,但我完全不需要考 ...
    通过单步调试,对找出程序的bug,了解程序的运行过程是很有帮助的。在eclipse环境中,调试Java程序只需3步:     1:设置断点           在58行,就有一个断点标记。可以通过双击行数前的空白增加或去除断点。       2:执行 dubug as Java application     执行后出来Java调试界面...       3:调试命令     F5:单步执行程序,遇到方法时进入。    F6:单步执行程序,遇到方法时跳过。    F7:单步执行程序,从当前方法跳出。    
    在编写Java类或接口时,要考虑使用哪种修饰符,有public和和包级私有修饰符号,经验表明,应该使类的可访问能力最小化。看下面的例子: /** * 栈的接口 * */ public interface MyStack { /** * 获取栈中数据的个数 * ...
    Java中提供了高精度算数的类,BigInteger和BigDecimal类。这两个类类似于int和double,能像他们一样进行加减乘除操作,只是运算速度会慢点,但是却能换来高精度。     double在运算时,常常会有舍入误差(浮点数运算结果不是精确解),比如下面的例子:   public class TestDouble { public static void main(String[] args) { //浮点数乘法 double a = 0.3333333333333333; System.out.println(3 * a); ...
    Java中的静态变量、方法使用static关键字修饰,先来看一个简单的例子:   public class Student { private static int stuNum = 0;//静态变量 private int stuId; private String stuName; public Student(String stuName) { this.stuName = stuName; this.stuId = Student.stuNum++; } public int getStuId() { re ...
    接口是类似于类的一种引用类型,但是它只能包含常量和方法签名,常量被隐式地声明为public,static,final,而方法被隐式声明为public。接口不能被实例化,一个类可以实现多个接口。       接口的创建:   public interface MyInterface { public static final String helloWorld = "HELLO_WORLD"; public void myPrint(); }     接口的实现:   public class MyInterfaceImp imp ...
Global site tag (gtag.js) - Google Analytics