Getting started with Java

Getting started with Java

Types of Languages : Procedural , Functional , Object Oriented

·

3 min read

  1. Procedural: A specific series of well-structured steps and procedures to complete a task or program.

    • It contains a systematic order of statements functions and commands to complete a task.
  2. Functional language: writing a program in pure functions i.e it never modifies the variable but it creates the new ones as an output.

    • Used in situations where you have to perform lots of different operations on the same set of data.
  3. Object-oriented language: revolves around objects.

    • developed to make it easier to develop, reuse and maintain software.

STATIC vs DYNAMIC languages

Static:

  1. Perform type checking at the compile time.

when you write a program for example, you write your source code and then the computer will convert it to machine-readable code and then the computer reads that program, this conversion is called compilation. During this conversion programming language should know what is the type of your variable(it may be string, integer or float whatever) but it should know the type at compilation time.

so here in the statically typed language, type checking is done at compile time.

ex: int a = 10; // you have specified the type at the compilation time only.

  1. Errors will show at compile time.

    example: int a = "joseph" // this is not possible, so it will also give an error at the compilation time.

  2. Declare the datatype before you use it.

  3. More control.

Dynamic:

  1. Performs type checking at run-time.
  • Run-time(once the program is converted into machine code and the program is running that is what runtime is.)

suppose you dont specify the type of "a" at the compile time , it will not give an error in the compile type as it is dynamically typed.

exmaple: a= 10// no error but if statically typed it will give an error.

  1. Error might not show till the program is run.

  2. No need to declare the data type of variables.

  3. Saves time in writing code but will give error in the runtime.

Memory Management (we will discuss more about memory management later)

  1. Stack memory

  2. Heap memory

a = 10 ([a] is the refrence variable and [10] is the object)

how they are stored: a is stored in the stack and 10(value of the object) is stored in the heap.

  • [a] is pointing towards the object[address] in the heap.

some important points:

  • more than one reference variable can point towards the same object.

    like: suppose your brother's name is Anil, and Anil is also the son of your mother and these anil, son and brother are the same person[object here] and Anil , son and brother are a reference of the objcect[person], so when you call your son, anil or your brother you are calling the same [person].

  • If any one of these reference variable change the object, the original object is going to be changed and it is going to be changed for all because reference variables are pointing toward the original object.

    like: if Anil got a haircut then (your brother and your mother's son will also get a haircut) because every one of them is the same person.

"Java has pass-by reference value."

"objects with no reference variable will be removed by garbage collection."

Did you find this article valuable?

Support Idealead by becoming a sponsor. Any amount is appreciated!