import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
public class ManualClear {
public static void main(String[] args) {
FileInputStream fileInputStream = null;
try {
fileInputStream = new FileInputStream("./src/ManualClear.java");
} catch (FileNotFoundException e) {
System.out.println(e.getMessage());
e.printStackTrace();
return;
}
try {
byte[] bbuf = new byte[1024];
int hasRead = 0;
try {
while ((hasRead = fileInputStream.read(bbuf)) > 0) {
System.out.println(new String(bbuf, 0, hasRead));
}
} catch (IOException e) {
e.printStackTrace();
}
} finally {
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
import java.util.Arrays;
import java.util.EmptyStackException;
class Stack{
private Object[] elements;
private int size;
private static final int DEFAULT_INITAL_CAPACITY = 16;
public Stack() {
elements = new Object[DEFAULT_INITAL_CAPACITY];
}
public void push(Object e){
ensureCapacity();
elements[size++] = e;
}
public Object pop() {
if (size == 0) {
throw new EmptyStackException();
}
return elements[--size];
}
private void ensureCapacity() {
if (elements.length == size) {
elements = Arrays.copyOf(elements, 2 * size + 1);
}
}
}
public class StackDemo {
public static void main(String[] args) {
Stack stack = new Stack();
for (int i = 0; i < 10000; i++) {
stack.push(new Object());
}
for(int i = 0; i < 10000; i++) {
stack.pop();
}
}
}
class Book {
boolean checkout = false;
public Book(boolean checkout) {
this.checkout = checkout;
}
public void checkin(){
checkout = false;
}
@Override
protected void finalize() throws Throwable {
if (checkout) {
System.out.println("Error: check out");
}
}
}
public class FinalizeCheckObjectUse {
public static void main(String[] args) {
new Book(true);
System.gc();
}
}
class Parent{
@Override
protected void finalize() throws Throwable {
System.out.println(getClass().getName() + " finalize start");
}
}
class Son extends Parent{
@Override
protected void finalize() throws Throwable {
System.out.println(getClass().getName() + " finalize start");
}
}
public class SuperFinalizeLost {
public static void main(String[] args) {
new Son();
System.gc();
}
}
class Parent{
@Override
protected void finalize() throws Throwable {
System.out.println(getClass().getName() + " finalize start");
}
}
class Son extends Parent{
@Override
protected void finalize() throws Throwable {
System.out.println(getClass().getName() + " finalize start");
int i = 5 / 0;
super.finalize();
}
}
public class SuperFinalizeLost {
public static void main(String[] args) {
new Son();
System.gc();
}
}
class Parent2{
private final Object finalizeGuardian = new Object() {
protected void finalize() throws Throwable {
System.out.println("在此执行父类终结方法中的逻辑");
};
};
}
class Son2 extends Parent2{
@Override
protected void finalize() throws Throwable {
System.out.println(getClass().getName() + " finalize start");
int i = 5 / 0;
super.finalize();
}
}
public class FinalizeGuardian {
public static void main(String[] args) {
new Son2();
System.gc();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有