Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.class vs .java

Tags:

java

class

applet

What's the difference between a .class file and a .java file? I am trying to get my applet to work but currently I can only run it in Eclipse, I can't yet embed in HTML. Thanks

**Edit: How to compile with JVM then?

like image 671
Devoted Avatar asked Jun 18 '09 21:06

Devoted


People also ask

Is .class a Java file?

A CLASS file is a compiled . JAVA file created by the Java compiler. It contains bytecode, which is binary program code that is executable when run by a Java Virtual Machine (JVM). CLASS files are commonly bundled into .

What does .class file contain Java?

What's in a class file? The Java class file contains everything a JVM needs to know about one Java class or interface. In their order of appearance in the class file, the major components are: magic, version, constant pool, access flags, this class, super class, interfaces, fields, methods, and attributes.

What does .class mean in Java?

What Does Class Mean? A class — in the context of Java — is a template used to create objects and to define object data types and methods. Classes are categories, and objects are items within each category. All class objects should have the basic class properties.


2 Answers

  • .class -> compiled (for JVM)
  • .java -> source (for humans)
like image 42
dfa Avatar answered Sep 18 '22 17:09

dfa


A .class file is a compiled .java file.

.java is all text and is human readable.
.class is binary (usually).

You compile a java file into a class file by going to the command line, navigating to the .java file, and running

javac "c:\the\path\to\your\file\yourFileName.java" 

You must have a java SDK installed on your computer (get it from Oracle), and make sure the javac.exe file is locatable in your computer's PATH environment variable.

Also, check out Java's Lesson 1: Compiling & Running a Simple Program

If any of this is unclear, please comment on this response and I can help out :)

like image 177
Brian Avatar answered Sep 19 '22 17:09

Brian