jpstayfocus / java-basic-and-beyond

Java/basic-and-beyond

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Java Programming

The online doc A good textbook: Introduction to Java Programming and Data Structures, Author Y. Daniel Liang

πŸ‘‰ Introduction

What is Java?

  • object oriented programming lannguage
  • create by James Gosling in 1995
  • similar to c++ but easier
  • 3 billion devices run Java programs
  • very popular

What can you build with Java

  • Mobile apps for Android (Kotlin is more common or Swift)
  • Desktop App using Java Swing, JavaFX
  • Enterprise Applications
  • Games (such as Minecraft)
  • Cloud based applications
  • Web applications

Java Usages

Compiled Vs Interpreted language

  • Difference between Compiler and Interpreter in Java
  • A compiler is a special program that processes statements written in a particular programming language and turns them into machine language or "code" that computer's processor uses.
  • The interpreter read each stateemnt of code and then converts or executes it directly

custom-upload-1683836306

Static vs Dynamic Type Checking

  • The process of verifying and enforcing the constraints of types - type checking - may occur either at compile time (static check) or at a run-time (dynamic check)
  • Static type checking is when types are checked during compilation, before the program is run. This means that any type errors will be caught early on and can be fixed before the program is deployed. Dynamic type checking, on the other hand, happens at runtime. This means that type errors can go undetected until the program is actually being used.

🚩 Environement setup (Intellij IDEA)

  • Go to the offical website of Jetbrains
  • If you are a student, you can get InteliJ IDEA free.
  • To download Intellij IDEA, go to developer tools > Pluging and services > Toolbox App
  • Then open toolbox and download IntelliJ IDEA
Screenshot 2023-12-24 at 12 00 51β€―AM

🚩 Getting Started

Screenshot 2023-12-24 at 12 13 46β€―AM Screenshot 2023-12-24 at 12 20 22β€―AM Screenshot 2023-12-24 at 12 21 22β€―AM Screenshot 2023-12-24 at 12 22 04β€―AM

First Java Program

Screenshot 2023-12-24 at 12 46 36β€―AM

Compiling and Running via Terminal

Screenshot 2023-12-24 at 12 54 33β€―AM Screenshot 2023-12-24 at 12 56 29β€―AM

View bytecode

  • read more on bytecode here
Screenshot 2023-12-25 at 5 30 00β€―PM

Public static void main

Screenshot 2023-12-25 at 5 32 20β€―PM

πŸ‘‰ The basics

The example codes for the following subjects can be found here

  • Reverse keywords

  • Comments

    • two ways to add comments
    • use "//" (single ligne comments) or "/" and "/" (Multi Line comments)
    • Comments has no effect when you run a code
  • Variables - A varibles allows us to store a value into a placeholer which we can use it later

  • Primitives Data Types Differences

    • Primitives types are used to store simple values. For instance, whole numbers, decimal values and characters:
      • boolean
      • byte
      • short
      • char
      • int
      • long
      • float (store decimal value, but bigger number and take more space in memory)
      • double
    Screenshot 2023-12-25 at 6 15 25β€―PM
  • Numeric Literals with underscore

    • Reprensent big numbers with underscore for readability
Screenshot 2023-12-25 at 6 22 15β€―PM Screenshot 2023-12-25 at 9 56 20β€―PM
  • Reference types and objects differences

IMG_0362

πŸ‘‰ Loops

code snipet can be found here

loops - constraint that allows us to repeat a block of codes

  • For loops
  • Loops and arrays
  • Enhanced For loop
  • For i vs Enhanced For loop
  • While loop
  • Do while

πŸ‘‰ 'if' Stateements

code snipet can be found here

if statement allows us to execute a block of codes based on a condition

  • if statement

  • if statement with conditions

  • Else if

  • AND logical operator

  • OR logical operator

  • logical operators recap

    • a review of the chapter logic in discrete math or discrete structure or math for computer science can help
    • a recommended course for discrete math
Screenshot 2023-12-27 at 10 14 24β€―AM
  • Switch

    Use switch to replace nested if conditions

πŸ‘‰ Packages

read more on packages here

  • How to find the location of your package
Screenshot 2023-12-27 at 2 09 01β€―PM
  • Creating packages
  1. Paclages lives under src
  2. Have a root package
Screenshot 2023-12-27 at 2 14 41β€―PM
  • Import Keywords
Screenshot 2023-12-27 at 2 28 09β€―PM
  • import with fully qualified nanme is java
Screenshot 2023-12-27 at 2 46 16β€―PM

πŸ‘‰ Access modifiers

All you need to know can be found here

πŸ‘‰ Methods

When building method:
- Access modifiers
- Optional static
- Return type
- Name
- Optional parameters
- Method Body
- Optional return value

Exammple: public static void main(String[] args) { body }
  • Naming convention for methods
    • Methods should be verbs, in mixed case with the first letter lowercase, with the first letter of each internal word capitalized
    • e.g: run(); runFast(); getBackground();

πŸ‘‰ Beyond the basics

  • Understand public static void main

    Screenshot 2024-01-02 at 8 40 01β€―AM
  • Type inferance with var

    • It allows to define a variable using var and without specifying the type of it
    public class Main {
    // private var brand = "jpstayfocus" (var cant work)
    public static void main(String[] args) {
        // Type inference with var keyword (works for every datatype,
        // but can be used only for local variables)
    
        /*
        String name = "Jamila";
        String[] names = {"Jamila", "Joseph"};
        int age = 22;
        boolean isAdult = false;
        double balance = 1_000_000.33;
        */
    
        var name = "Jamila";
        var names = new String[]{"Jamila", "Joseph"};
        var age = 22;
        var isAdult = false;
        var balance = 1_000_000.33;
    }
    }
    
    
  • Break keyword and loops

  • Continue keyword

  • Final keyword

    • allows to create constants, prevent inheritance, and method overriding
  • Implicit and Explicit type casting

πŸ‘‰ Strings

πŸ‘‰ Dates

Code on Dates can be found here

πŸ‘‰ Big decimal

  • Problem with double (precision)
  • Big decimal
  • Big decimal methods

Exception in java

Screenshot 2024-01-07 at 11 30 33β€―AM

Working with files

  • Creating Files
  • Writing to Files
  • Reading from files
  • Try with Ressources

About

Java/basic-and-beyond


Languages

Language:Java 100.0%