Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

public class Main {
    /** Checks whether a class with the given name exists. */
    public static boolean hasClass(final String className) {
        return hasClass(className, null);
    }

    /** Checks whether a class with the given name exists. */
    public static boolean hasClass(final String className, final ClassLoader classLoader) {
        try {
            if (classLoader == null)
                Class.forName(className);
            else
                classLoader.loadClass(className);
            return true;
        } catch (final ClassNotFoundException e) {
            return false;
        }
    }

    /** Loads the class with the given name, or null if it cannot be loaded. */
    public static Class<?> loadClass(final String className) {
        return loadClass(className, null);
    }

    /** Loads the class with the given name, or null if it cannot be loaded. */
    public static Class<?> loadClass(final String className, final ClassLoader classLoader) {
        try {
            if (classLoader == null)
                return Class.forName(className);
            return classLoader.loadClass(className);
        } catch (final ClassNotFoundException e) {
            return null;
        }
    }
}