# Introducing Java¶

Written by WX on 2017-04-12

## What is Java¶

In IntroCS, you’ve learned Scheme and Netlogo, both of which are procedural programming languages (meaning everything you’re coding is a procedure trying to accomplish a certain task). Java is different from these languages in that the main building blocks are objects instead of functions/procedures. Each object is made up of fields (properties, what the object has) and methods (actions, what the object can do).

## JVM and Java Bytecode¶

Java is platform-independent, meaning it works on pretty much any platform (e.g. Linux, Windows, Mac OS, etc.). To achieve this, the Java source code you write is first compiled into Java bytecode by the Java compiler. The resulting .class file can then be ran on any platform if the Java Virtual Machine (JVM) is installed on that computer.

## Writing and Compiling Java Source Files¶

All your Java source files should end with .java. These files can be created by any text editor, but you should avoid the usage of word processors such as LibreOffice Writer, Pages or Microsoft Word (avoid them in general for programming, they’re not meant for this). To run your .java files, they must be compiled into .class files with the following command:

$javac filename.java  ## Running Java Files¶ After compiling your .java files to produce .class files, you can run your Java program with the following command: $ java filename


Note

Do not include the .class extension when using this command!