Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

What's the point of a standard library

Name: Anonymous 2009-03-29 9:28

if you can write most of what's there, but more efficiently, in five minutes?

Name: Anonymous 2009-03-29 19:10

>>1
Java SE shared system class library.
10,169 Files, 754 Folders
Size 105MB
Size on Disk 127MB
javac LineCounter.java
java LineCounter
Total Lines of code: 3011022
javac LineCounter.java
java LineCounter
Total Lines of code excluding comments: 1368846

If you want to go and write a standard library that large be my guest, although I think we all know you were trolling.

Linecounter is included below for convenience, and simply counts the total source lines of code in the java class libraries (NB: all libraries including system specific ones, because it differentiates between the actual library files and random .c and .html junk etc). You will need to change "basePath" to the location of the java class files if you wish to verify this yourself. The comment excluder is extremely naive and probably makes a few mistakes but I consider it to be within a reasonable margin of error.

import java.util.*;
import java.io.*;
public class LineCounter {
    private static final String basePath = "C:\\j2se\\src\\share\\classes";
    private static final boolean filterComments = false;
    private static BufferedReader br;
    public static void main(String[] args) throws IOException {
        File root = new File(basePath);
        System.out.println("Total Lines of code: "+recursiveReadDir(root.listFiles()));
    }
    private static int recursiveReadDir(File[] files) throws IOException {
        int locCount = 0;
        for(int i=0; i<files.length; i++) {
            if(files[i].isDirectory()) {
                System.out.println(files[i]);
                locCount+=recursiveReadDir(files[i].listFiles());
            }
            else {
                locCount+=FileLOC(files[i]);
            }
        }
        return locCount;
    }
    private static int FileLOC(File location) throws IOException {
        br = new BufferedReader(new FileReader(location));
        int count = 0;
        int index = 0, index2 = 0;
        String line = "";
        boolean inComment = false;
        while((line=br.readLine())!=null) {
            if(filterComments) {
                if((index=line.indexOf("/*"))>=0) inComment = true;
                index2 = line.indexOf("*/");
                if(index2>=0 && index2>=index) inComment = false;
            }
            if(!inComment) {
                line=line.trim();
                if(filterComments) if(line.length()<=2 || line.charAt(0)=='/' && line.charAt(1)=='/') continue;
                count++;
            }
        }
        br.close();
        return count;
    }
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List