Skip to content

rominalodolo/JAVA1

Repository files navigation

JAVA Class work and projects

ECMAScript is the scripting language that forms the basis of JavaScript. ECMAScript standardized by the ECMA International standards organization in the ECMA-262 and ECMA-402 specifications. - mnd web docs

Checking for java on my computer: 1

Netbeans

Creating a new project newproject

Create a new package: packagenew

Create a class then you can create a main class with psvm ctrl space ctrlspace

Main method has a green play button:

mainmethod_playbutton

sout ctrl space

cntrlspace

To run your file - right click

rightclick

run

Compliing the java file in terminal: New file at terminal. cjava file name.java

newterminalatfolderlesson1

Now that it's a readable file java filename.java

readablefile

Quiz: quizanswer

ln means New line in println newline_LN

this will print on the same line print_sameline

Quiz: quiz2

Initializing and Assigning Numeric Values: intvsdouble

Increment and Decrement Operatos

incrementdecrement

Lesson 6 lesson6 publicclasstoprivate private

insertcodegettersandsetters Getterand Settercode

popupandselect

gettersandsetterscode

mainClasssettingFields employee

1 insertingconstructer

popupconstructer constructercode mainclassNewcodeConstructor

How to make a space \n space n otes

generate

Syntax for Object Instances and Instantiation: <class name> variable = new <class name>()

  • Decalre the reference.
  • Instantiate the object by using the new keyword and the class constructor method.
  • Assign the object to the reference.

Heap data structure A heap is a special data structure in Java. A heap is a tree-based data structure and can be classified as a complete binary tree. All the nodes of the heap are arranged in a specific order. Read More

Storing Arrays of Object references in memory arrays run

Debug the Soccer App

debug

variables debugging

Running the for loop: runningtheforloop outpuy

End the debug by pressing the green button enddebug

The String Class: exampleStringClass

example2

Promotion vs Casting Promotion is converting a small primative data types to larger data types and Casting is like demoting the data type from larger to smaller.

Static methods vs Variables

  • A static variable is shared by all objects in a class.
    • Can't access instance methods or fields.
    • boolean, int, double, System & Math classes are all static examples.
  • An instance variable is unique to an individual object.
    • can access static methods of fields.

Class Math having static variables READ MORE Functionality of the Math Class: - Exponential - Logarithmic - Trigonometric - Random - Access to common mathematical constants, such as the value of PI Math.PI Java class library: System & Math class - contain only static methods and variables. therefore you don't need to create a new object every time your program does a math problem.

Looking up in the JDK docs: SEARCH: java.lang.Boolean Info

SEARCH: java.lang.Integer Info

SEARCH: java.lang.Double Info

Explaining Parameters vs Arguments: WorkerVsCaller

Method Overloading:

  • Same name
  • Different signatures
    • number of parameters
    • types of parameters
    • order of parameters
  • may have different/ similar functionality
  • widely used in the foundation classes JAVA METHOD OVERLOADING: A class can contain multiple methods that have the same name but different arguments.

overload vs overriding part1 overload vs overriding part2 Data-2

More on the difference of Override vs Overload

More Examples

Explination video

Access Controls:

  • Allows you to hide fields and methods from other classes
  • You can determine how internal data gets modified
  • You can keep implementation separate from the public interface

public Accessible by anyone private Accessible only within the class

Encapsulation:

  • Hiding object fields
    • Safer access through getter and setter methods
  • Mandates programming to the interface
    • A method can change the data type to match the field
    • A class can be changed as long as interface remains the same
  • (OO) Encapsulation encourages good OBJECT-ORIENTATED design.

Void type methods can have return statements but they can't return any values.

Operators: If you compare two objects together - DON'T use operators rather use methods. Because of the way it is stored in memory - rather use equals method than ==

Operators Operators Operators (2) Operators (3)

Switch Constucts: When to use

  • Equality (not a range)
  • a single value
  • against fixed known values at compile time

Inheritence:

  • different to the main class
    • extends
    • super
  • overriding
    • Same signature
    • Different name
    • @Override is an annotation which can't access private

Subclass vs superclass

Polymorphism: - casting only from super to sub - instance of works with sub to super

Abstract class

  • can't be instanciated
  • no code block

Override toString method of the object class Class String: java.lang.String READ MORE Class Object: java.lang.Object READ MORE

Array List: Class ArrayList: java.util.ArrayList READ MORE Class List: java.awt.List READ MORE

Lambda Expression:

Exceptions: java.lang.ArrayIndexOutOfBoundsException - attempt to access a nonexistent array index

`java.lang.ClassCastException`
- attempt to cast on object to an illegal type 

`java.lang.NullPointerException`
-  attempt to use an object reference that has not been instantiated 

You can also create exeptions - An exception is just a class public class MyException extends Exception {}

Exceptions Methods: methods READ MORE

Types of Throwable classes Exceptions are subclasses of Throwable. There are three main types of throwable:

  • Error
    • Unchecked
    • Usually unrecoverable external exernal error
  • RuntimeException
    • Unchecked
    • Usually caused by a programing mistake
  • Exception
    • A recoverable error
    • Checked (must be cuaght or thrown)

Propagation of exceptions: "a process in which the exception is being dropped from to the top to the bottom of the stack. If not caught once, the exception again drops down to the previous method and so on until it gets caught or until it reach the very bottom of the call stack." READ MORE Data

JAVAFX

"JavaFX is an open source, next generation client application platform for desktop, mobile and embedded systems built on Java. It is a collaborative effort by many individuals and companies with the goal of producing a modern, efficient, and fully featured toolkit for developing rich client applications." Official JavaFX

  • Allows you to use CSS.
  • Visual effects: You can add a wide variety of visual effects to your user interface elements, including shadows, reflections, blurs, lighting, and perspective effects.
  • Animation: You can specify animation effects that apply transitions gradually over time.
  • 3-D objects: You can draw three-dimensional objects such as cubes, cylinders, spheres, and more complex shapes.
  • Touch interface: JavaFX can handle touchscreen devices, such as smartphones and tablet computers with ease.

Getting started: How to install

JavaFX Docs

JavaFX and NetBeans 11.2 More on downloads Where to download your files from Open JDK

When trying to use Netbeans for the JavaFx projects (in Chapter 6 of the Dummies book) I came across many issues that I couldn't fix. I'm still unsure of why it isn't working. However, I had the 2022 version of INTELLIJ but that ended up giving me issues aswell until I deleted the program safely off my Mac laptop then reinstalled it as a 2021 version. The issues were with the module and the local path but everything seemed as it should work. I did find out how to add the dependencies to the project in INTELLIJ. I am using Java 11 SDK - Because the dependancies have been unbunded I have to make sure I am adding them to the global libraries in INTELLIJ. To do this, Right click on the project folder and go to module settings to global library.

modulesetting When you have set the path for your JavaFX dependencies then you can edit configurations.

GlobalLibrary editconfig

To edit configurations click Run and scroll to Edit Configurations... Next click the ADD + button and choose Application Then add the project name to the Name: secion. Use the com.example.. for the main class and you can choose Apply/OK. settingconfing

Then Run your program to see if it works. A pop up Hello! box should pop up as seen in the image below. RunProgram

To edit the program in scene builder right click on the fxml file in the src folder scenebuilderfxml

Download Scene Builder Here

To set up Scene Builder In INTELLIJ: Go to IntelliJ IDEA then Preferences a box should appear as seen in the image below. preferences Next, Select Languages & Frameworks Click on JavaFX javafx Then set the path for scene builder by going into your applications - finding scene builder and selecting it for your path. You do not need to find the executable file as seen in the image below, all you need to choose is the appication itself. executable Like this: app Then you can run your FXML file in scene builder and it should open up like this (see below): working

Method Chaining is the practice of calling different methods in a single line instead of calling other methods with the same object reference separately. Under this procedure, we have to write the object reference once and then call the methods by separating them with a (dot.).

Last edit April 2022