String path = "your/class/Main.class";
// Читаем файл как бинарник
byte[] bytes = new FileInputStream(path).readAllBytes();
//Выводим с помощью форматирования
StringBuilder str = new StringBuilder();
for (byte b : bytes) {
str.append(String.format("%02x", b));
}
Почитайте об этом, есть много статей.