My journey to Java 001 — Variables, operations, methods, object and class

Install Java Development Kit in ubuntu:

IntelliJ IDEA:

1- Variables:

Java variable example:

Create a new java project
The first method, print Hello World!
public static void main(String[] args) {
int int_v = 10; // Integer numbers
double dou_v = 140.13; // floating numbers
char char_v = 'a'; // one character
String str_v = "JourneyToJAva By Islam Taha"; // string

System.out.println(int_v);
System.out.println(dou_v);
System.out.println(char_v);
System.out.println(str_v);

}

2- Operations:

double addition(double x, double y){
return x+y;
}

double subtraction(double x, double y){
return x-y;
}

double multi(double x, double y){
return x*y;
}

double divde(double x, double y){
return x/y;
}

3.1- Methods (Instance Methods):

double addition(double x, double y){
return x+y;
}
\*
type: double (that is the type of the return result)
name: addition
inputs: x and y (both of them are double)
return: x+y (it returns double variable that is why we defined the method with double type)
*\

3.2 Methods (Static Methods):

double static addition(double x, double y){
return x+y;
}

Show me an example for static and instance methods:

//create an object
// class_name object_name = new class_name();
JourneyToJava001 Journey_obj = new JourneyToJava001;
/*
type: class_name
object_name: any_thing
new: deserve a place in the memory to store an object
*/
public class JourneyToJava001 {

double addition(double x, double y){
return x+y;
}
double static subtraction(double x, double y){
return x-y;
}
public static void main(String[] args) {
JourneyToJava001 journey_obj = new JourneyToJava001();
System.out.println(journey_obj.addition(10.1, 10.2));
System.out.println(subtraction(15, 10.2)); }
}

4- Access modifiers:

4.1 — Private

4.2 — protected

4.3 — Default:

4.4 — Public:

--

--

--

code with love!

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

16 Cool Drupal modules For site builders | Februari 2018

Almost up & running.

Android Build Hacks #1 — build basics

Kubernetes: An Introduction, Part III

Creating Modular Powerup Systems in Unity!

Writing Software is Like Making Pizza

The Detrended Price Oscillator.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Islam Taha

Islam Taha

code with love!

More from Medium

First Steps of a Backend Engineer

Useless Java: Day 20

== and .equals() in Java — Interview Question

Difference between throw & throws in Java?