In-depth notes covering Object Oriented Programming in Java especially. The three pillars of OOP (Encapsulation, Abstraction, Polymorphism), how the JVM works, bytecode, public and private methods, classes, objects, constructors and their relationships. Basics of fields vs methods, case and UML dia...
Eclipse Shortcuts: https://www.digitalocean.com/community/tutorials/eclipse-
shortcuts
Windows 11 Shortcuts:
https://support.microsoft.com/en-us/windows/windows-keyboard-shortcuts-
3d444b08-3a00-abd6-67da-ecfc07e86b98
1) What is Object-Oriented Programming? Object-oriented programming (OOP) is a
programming paradigm based on the concept of
"objects", which can contain data and code: data
in the form of fields (often known as attributes or
properties), and code, in the form of procedures
(often known as methods).
2) What is Encapsulation and Abstraction? Encapsulation and Abstraction - to achieve those
two principles private, public and protected fields
are used.
3) What is Class Hierarchy? A term that is linked closely to Inheritance, here
we have subclasses or so-called child classes in the
hierarchy that inherit key components of the
parent class.
4) What is Polymorphism? Similar to inheritance but takes a step further; it
enables an object of a class to take different forms;
in other words, the child class object can take the
form or the functionality of its parent class as
well as use the defined methods to extend that
functionality and perform additional tasks.
,5) How does Java run and how is it Java applications are designed to operate on any
different from other languages? platform that has a Java Virtual Machine (JVM)
installed;
think of the JVM as a software platform to run
Java programs on.
In theory, a programmer can write a
single application in Java, and it will execute
similarly on any piece of hardware with an
installed JVM. That makes Java a write-once-
run-everywhere language, meaning that it is
platform independent.
6) How does Java work? To be platform independent, means that Java
cannot be translated directly to machine
language, therefore it introduces an intermediate
language called bytecode or *.class. The Java
source code is translated into bytecode via the
compiler, and the JVM on each device can then
determine the best way in which to execute the
bytecode instructions.
7) How is source code set up in Java? In the Java programming language, all source
code is first written in plain text files ending with
the .java extension.
A Java source code file can contain one or more
Java classes, however only one of them can be
defined as public. The name of the public class
and the filename of the source code file must
match,
8) What is Bytecode? Those source files (.java) are then compiled
into .class files by the javac compiler. A .class file
does not contain code that is native to your
, processor; but instead the machine language of
the JVM. The .class files are called bytecode.
In other words, bytecode is really a form of
intermediate language rather than a true
machine code. This means that the process of
turning Java source code into bytecode is not
really a type of compilation in the sense that a C
or C++ programmer would understand it.
During compilation if any errors are found, then
the compilation process ends. Once the errors are
fixed (removed, modified or corrected), then the
program goes through the compilation process
once again. If no errors occur, the bytecode file
(.class) is created and handed over to the Java
Virtual Machine (JVM) for interpretation.
9) What is a Java Virtual Machine? What JVM is a virtual machine used in Java
is JIT? programming platform to execute or run Java
programs. It is an engine that allocates memory
space and converts Java bytecode into machine
language, making Java platform-independent.
JIT stands for ‘Just-in-time’ compilation and it is
part of JVM responsible for executing the
compilation to native machine code.
Java is both compiled and interpreted.
10) How do you format blocks of code in The class definition must go within a pair of curly
Java? braces, { and }. Within the class you can have one
or more methods, selection statements or
repetition statements that also need curly braces,
forming nested braces: { {} {} } Whitespace and
indentation etc. is for human readability and has
no syntactic significance in Java.
Excess whitespace or ’wrong’ indentation will
have no negative effect on the compiler!
, 11) What is the difference between Public Public methods/ variables are accessible to all
and Private? classes whereas the private ones are not.
Public fields and methods are externally visible
– Public fields (external fields)
- Public methods (external methods)
»Private fields and methods are internally visible
- Private fields (internal fields)
- Private methods (internal methods)
»Internal fields are safe from external changes
»Internal methods are implementation detail
- Provide common functionality used through the
class
- Not exposed as part of the interface (or contract)
of the class
12) What is the Main Method? Main method – This is the entry/execution
starting point of a java program. In other words,
that is the first thing that runs.
13) What is a class? A class is a blueprint, template, or prototype. A
class consists of attributes (which become
fields/variables and later on define the state of the
object) and behaviours (which are executed by
methods and later on may affect the state of the
object).
A class encapsulates:
- Attributes: fields
(also known as instance variables or properties)
- Behaviour: methods
The benefits of buying summaries with Stuvia:
Guaranteed quality through customer reviews
Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.
Quick and easy check-out
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
Focus on what matters
Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!
Frequently asked questions
What do I get when I buy this document?
You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.
Satisfaction guarantee: how does it work?
Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.
Who am I buying these notes from?
Stuvia is a marketplace, so you are not buying this document from us, but from seller williamdaniel. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $5.84. You're not tied to anything after your purchase.