Java ( Code Academy) Flashcards
The Java Virtual Machine
is which can ensure the same Java code can be run on different operating systems and platforms.
Each file has one
primary class named after the file
For example: Our class name: HelloWorld and our file name: HelloWorld.
Inside the class we had a
main() method which lists our program tasks
String[] args is a
placeholder for information we want to pass into our program.
System.out.println is
whenever we want the program to create a new line on the screen after outputting a value
System.out.println
System is a
built-in Java class that contains useful tools for our programs.
System.out.println
Out is
short for “output”
System.out.println
println is
short for “print line”
System.out.print
is different from ….println, this type f print statement outputs everything on the same line
For example:
System.out.print(“Hello “);
System.out.print(“World”);
output:
Hello World
Java is a compiled programming language meaning the code we write in a .java file is
transformed into byte code by a compiler before it is executed by the Java Virtual Machine on your computer.
A compiler is a program that translates
human-friendly programming languages into other programming languages that computers can execute.
Compilation helped us catch
an error
we can compile a .java file from
the terminal with the command javac
e.g javac Whales.java
If the file compiles successfully, this command produces an executable class
We run the executable with the command:
(java + file_name): java Whales
When terminal shows no errors, which indicates a successful compilation. Then we now have two files:
- Welcome.java, our original file with Java syntax
- Welcome.class, our compiled file with Java bytecode, ready to be executed by the Java Virtual Machine.