0

Why does quartz or any java code require a .class file ? What is so special about the .class file that a regular api cannot provide ?

Code -

 JobDetail job = JobBuilder.newJob(HelloJob.class)
        .withIdentity("dummyJobName", "group1").build();

source - http://www.mkyong.com/java/quartz-2-scheduler-tutorial/

Apple Grinder
  • 3,573
  • 7
  • 22
  • 35

1 Answers1

2

All Java code is compiled into .class files, so that shouldn't be surprising.

But I think you're referring to the Foo.class syntax, which has nothing to do with .class files. It's simply a way to define a literal value of type Class<T>, much like you can use double quotes to define literal values of type String.

Daniel Pryden
  • 59,486
  • 16
  • 97
  • 135
  • Daniel - Thanks. I saw the api for the class called "Class". Why do we need this class? Why does the above code need Hello.class ? Why can't it use an Object of type HelloJob instead ? – Apple Grinder Mar 10 '13 at 05:33
  • There's a difference between a *class* and an *instance* of that class, or, more formally, between a *type* and a *value* of that type. When you're doing *metaprogramming* you often need to refer to types, not values (or higher-order concepts like *kinds* and *typeclasses* which Java doesn't have). See also the answers to [this StackOverflow question](http://stackoverflow.com/questions/4453349/what-is-class-objectjava-lang-class-in-java). – Daniel Pryden Mar 10 '13 at 05:41
  • Thanks again. Makes perfect sense now. – Apple Grinder Mar 10 '13 at 05:51