-5

Why class named saved directly with .class extension without compiling is not get executed by JVM. Is there any kind of Metadata or something else is attached to .class file so then only JVM recognised as valid .class file ?

Please Help me to clarify Thanks in advance

AmitYadav
  • 9
  • 5

3 Answers3

2

A Java class file is a compiled intermediate form called bytecode. Bytecode is interpreted by the JVM and executed. It is not human readable text.

If you need that capability, I suggest you look into Groovy and Scala (both are JVM hosted languages, and both can run as scripting languages).

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249
  • ok ...JVM will not execute it but this self made .class is loaded or not by loader.... and what if I copied all the byte code to other file with same name and then give to JVM will it Execute or Not ? – AmitYadav Dec 18 '14 at 18:20
  • @AmitYadav If you have a text file it isn't a `.class` (and no the class-loader will only load valid class files). Try looking at the bytecode of an existing class; you can decompile it with `javap -v` – Elliott Frisch Dec 18 '14 at 18:22
0

.class filrs have a specific format. There's no reason why the jvm should execute anything other than this format just because it's also called .class.

Sebastian Redl
  • 69,373
  • 8
  • 123
  • 157
  • And content! And a specific content! – laune Dec 18 '14 at 18:06
  • ok ...JVM will not execute it but this self made .class is loaded or not by loader.... and what if I copied all the byte code to other file with same name and then give to JVM will it Execute or Not ? – AmitYadav Dec 18 '14 at 18:21
0

If you have a text file it isn't a .class (and no the class-loader will only load valid class files). Try looking at the bytecode of an existing class; you can decompile it with javap -v so u can see the differences between two files.....