100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
Lecture notes PRINCIPLES AND APPLICATIONS OF PROGRAMMING (JAVA) (IS52028A) £9.39
Add to cart

Lecture notes

Lecture notes PRINCIPLES AND APPLICATIONS OF PROGRAMMING (JAVA) (IS52028A)

 14 views  1 purchase

Full second-year notes for Principles and Applications of Programming JAVA

Preview 4 out of 38  pages

  • September 21, 2021
  • 38
  • 2020/2021
  • Lecture notes
  • Edward anstead
  • All classes
All documents for this subject (1)
avatar-seller
milsmilli28
MACHINE CODE
Instructions the computer ASSEMBLER
thinks in, the instructions are Easier programming language
sent to the CPU to understand



OBJECT ORIENTED LANGUAGES
(C++, Java, c#, Swift)
Still high level languages, their subset of it. HIGH LEVEL
They allow us to write more complicated LANGUAGES
programs in a more manageable and (Fortran, Cobol, C)
understandable way. Much easier to programming


Programs written in high level languages can be
o Interpreted (Javascript, Phyton) – analyses the code as it is run
o Compiled (C, C++) – it converts the code into instruction that the machine can understand

Java’s code is compiled to ‘bytecode’ which is interpreted at runtime

BYTECODE
o Java’s code isn’t compiled to machine code but to intermediary ‘bytecode’
o Bytecode is run on the Java Virtual Machine (JVM)
o We can run on any platform with an instance of the JVM
o Java bytecode can be more secure (required frequent updates)
o Slower than native compilation

JAVA HISTORY
o Developed by Sun Microsystems (1990s) – then became Oracle in early 2000s
o Developed for embedded systems, portability was important (being able to move using the same
code
o Repurposed for the web – it was designed to be one of the languages to be used in the web
(applets – click on in a web browser and they will pop us separate applications that you could
interact with)
o Designed to be a modern internet friendly version of C++ - if you get your code online you can
download it and it’ll run safely
o It’s the language of the Android operating system, now phased out by Kotlin (still based on Java)

Two programs that make up the JVM
o JRE (Java Runtime Environment) – where you run Java applications. Includes the JVM
o JDK (Java Development Kit) – specific to develop Java applications. Includes the JRE and the Java
compiler

Java and Javascript
o Have no technical relationship to one another, totally separate languages
o They’re both influenced by C and share syntactic style
o Naming similarity was a business choice
o They were both destined for online use
o Javascript is technically the propriety name of ECMAScript

, PACKAGE
IntelliJ will add this for us.
As long as all classes have the same package your
program will work as you expect.
Packages are useful to divide code up when you have a
big program.
You can omit the package keyword and name on all
your classes.
CLASS DECLARATION
Classes are the basic building blocks of Java programmes.
A class in Java is like a constructor function in Javascript. We can do so much more with a class than we can
do with a constructor function.
The class name must match the name of the file that the class is in. The file name is HelloWorld.java, so the
class name is HelloWorld.
In Java you should start class name with a capital letter.
public is an access modifier and its default – all parts of our program can access our class.
Class is enclosed by {}.
MAIN METHOD
All Java programs must have a main method in one class.
public static void main method tells Java where to start the program, what should be executed
first and it kicks off the rest of the program. Everything else comes from this method.
public means that any part of this program can access this method.
static means that this method can be accessed without creating a new instance of the class, without
creating a new abject.
void means that it doesn’t return anything.
String[] args it’s an argument and it’s type of an array of strings.
PRINTLN()
System.out.println will print some information out of the console. The println method belongs to
the out object that belongs to the system class.
String must start and end with double quotes “ .. “ .
All statements in Java must end with a semicolon ; .

//single line comment
/* multiple
line
comment */

VARIABLES
o What we use to store values in our program
o We have to give variables unique name/identifier
- start with a letter, _ or $
- can contain letters, numbers, _ and $
- case sensitive (myValue ≠ MyValue)
- can’t be the same as a keyword
o They have scope – in Java is block scope. If you create a variable it exists in that block and in any
child block
o They have a type

,Java is a STRONGLY TYPED language
- when we declare a variable we have to state what type it is, rather than inferring what type it is
based on the value we assign to it
- we can’t change the type of a variable once we set it
- this increases the performance of our programs and their ‘safety’
- it can decrease some of the flexibility to the programmer

PRIMITIVE TYPES
o basic types that are built into Java that we can use to create values from
o these are not object types
o other data types can be built from primitive types
o the type you set a variable to be suggests the parameters the variable can store
o in Java, primitive types are the same size regardless of the computer they are run on (≠ C/C++)




DECLARING AND INITIALISING VARIABLES
Basic Form: [type] [name];
With assignment: [type] [name] = [value];
By declaring a value as final it is a constant and can’t be changed final [type] [name] = [value];

ARITHMETIC OPERATORS
The operators have an order of precedence:
1. ( )
2. ++ and – (postfix -
3. ++ and – (prefix),
4. * / %
5. + -
Calculations are performed using this list in order, then left to right
When we wish to assign the result of a calculation back to a variable we can truncate the expression




The modulus operator % returns the reminder of a division.

, Java allows us to do postfix and prefix increment and decrement. Same result but the behaviour is
different.




x++ postfix – complete the expression then increment
++x prefix – increment then complete the expression

TYPE CONVERSION
As a strongly typed language Java will check if types are compatible when performing operations.
Numerical types in Java have a rank.
Java will automatically convert up the rank order (widening conversion)
1. double
Narrowing Widening
2. float
conversion conversion
3. long
4. int
5. short
6. byte
Narrowing conversion (down the rank order) will not be done automatically as you can lose precision of
your value.

Type casting allows us to override Java and perform conversion
in both directions. Do it by placing the cast data type in brackets
in front of the expression.

Strings
o are not primitive type in Java, they’re an object type
o they have methods and properties (length() concat() )
o can only be delimitated by double quotes
o can be concatenated using +
o can’t be compared with == in an if
o when defined must start and end with double quotes
“ .. “ . When single character, must start and end with
single quotes ‘ . ‘ .

ARRAY
o is a collection of variables represented
by the same name
o have fixed size
o have a type (primitive/object)
o have dimensions
o each element of the array had an index (an array is
zero indexed)
Declaration and initialisation
type [] identifier;
identifier = new type[size];
or
type[] identifier = new type[size];
or

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

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

Quick and easy check-out

You can quickly pay through credit card for the summaries. There is no membership needed.

Focus on what matters

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 milsmilli28. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for £9.39. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

48072 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy revision notes and other study material for 15 years now

Start selling
£9.39  1x  sold
  • (0)
Add to cart
Added