Intro to Java

Java is an object-oriented programming language.

  • Java is a high-level programming language
    • more human understandable than assembly or machine code
    • The language is compiled to another language (bytecode) which is then understood by the machine (the Java Virtual Machine (JVM))
    • High-level languages allow programmers to use abstraction to write complex instructions using a single command.
  • Java programs are executed on the Java Virtual Machine (JVM).
    • Java programs are compiled to bytecode, which is a defined set of instructions that are recognized by the Java Virtual Machine.
    • This bytecode can be executed on a JVM on any operating system platform (provided that a JVM has been written for that platform.)
    • Java virtual machines handle “garbage collection” to avoid memory leaks that occur in other languages.
  • Java is strictly object-oriented, unlike Python which just happens to contain object-oriented elements
    • Object-Oriented programs are organized into objects
    • Each object has a set of attributes with values (the object’s state) and a set of methods (ways of modifying the object’s state)
Java Class Example

 

  • The top of the program contains JavaDocs which are used to describe a program, class, method, or variable
  • The comments at the bottom are in-line comments that are used to describe individual lines of code
  • Everything inside the first set of curly braces is whats known as an Object.
  • public class HelloWorld is known as the class header
    • The class name should always be capitalized
  • The code inside is known as the class body
  • The inner set of curly braces is whats known as a method
  • public static void main is the method header
    • main is a method name and should be lowercase
  • (String[] args) are the parameters of the method
    • args is an identifier and should also be lowercase
  • inside the method is known as the method body
  • Each line of executable code known as a statement must end with a semi-colon

Leave a Reply

Your email address will not be published. Required fields are marked *