Java Basics Flashcards
The way Java works
- Source
- Compiler
- Output (Bytecode)
- Virtual Machines (JVM)
What goes in source file?
Class definition
What goes in a class?
Methods
What goes in a method?
A set of statements, and for now you can think of a method kind of like a function or procedure
Why does everything have to be in class?
Java is object-oriented, thus each object represents a set of blueprint
Do I have to put a main in every class I write?
Nope. You might use a dozens of classes, but only one main method to evoke the program
What is the difference between a class and an object?
A class is blueprint for an object.
A object is like one entry in your address book
What if I need global variables and method? How do I do that if everything has to go in a class?
There isn’t a concept of ‘global’ variables and methods in a Java OO program.
What is a Java program? What do you actually deliver?
A Java program is a pile of classes. In a Java application, one of the classes must have a main method, used to start-up the program
How is this object oriented if you can still make global functions and global data?
Everything in Java goes in a class. So the constant for pi and the method for random(), although both public and static, are defined within the Math class
Object Oriented Programming
- Flexibility
2. Extensibility
Instance Variable
The object’s state (the data), and can have unique values for each object of the type
Class
A blueprint that tells the virtual machine how to make an object of that particular type
Main
- To test your real class
2. To launch/start your Java application
Garbage-Collectible Heap
- When the object is created, Java allocates memory space on the heap according to how much that particular object needs
- When the object never in use anymore, then that object becomes eligible for garbage collection