Guide | How To How to start programming in Java (simple and quick tutorial)

The associated guide may contain user-generated or external content.

JM Safe

Level 39
Thread author
Verified
Top Poster
Apr 12, 2015
2,882
Hello guys,

I decided to make this simple and quick tutorial about Java.
Java is not very suitable for security development but let's talk about this important language anyway!

Java is an Object Oriented Programming language (also called OOP). The "objects" are fundamental when we talk about Java, an object could be for example a car, an object has attributes (for example the car has a colour, this is an attribute of our object).

Java:
public class Car{
String colour="";
public Car(String colour){
this.colour=colour;
}
}
In this source code we created the class "Car" which has only a parameter: the colour. In Java a program is a group of classes (.java files) which can be linked and work together. The constructor is a method without type which can initialize objects of that class.

In Java we have several types: Integer, String, Double, Float, etc.

Example of integer declaration (a variable which holds the value 5):

Java:
int count = 5;

In our class we can define a method, so a piece of source code we can call and use also in another class. So, if for example, in our class "Car" we define the method:

Java:
public void hello(){
System.out.println("hello"); //this instruction prints hello
}

We can call it in another class with the following:

Java:
Car car = new Car("blue");
car.hello();

Now let's talk about arrays: an array is like a list of elements, for example this is a String array:

Java:
String[] array = new String[50];
array[0] = "MT"; //there we set the first element

Now let's talk about if and loops!

The if is fundamental for conditions for example:

Java:
if(count>5)
{
System.out.println("MT");
}

So yes when our variable is bigger than 5 we print "MT".

A while loop instead: the code is executed while the condition is true, for example:

Java:
while(count<5){
System.out.println("MT");
count++; //if we don't put this the loop can be infinite
}

Okay guys we arrived at the end of this simple tutorial: the "for".

Java:
for(int i = 0; i < 10; i++)
{
System.out.println("count: " + i);
}

The "for" executes the code while the condition is true. The "for" can be used to loop through an array and print its elements or modify them for example.

Guys, please consider this is only just a very quick tutorial, there would be a lot of other things to talk about, maybe in future threads.

JM.
 
Last edited:

About us

  • MalwareTips is a community-driven platform providing the latest information and resources on malware and cyber threats. Our team of experienced professionals and passionate volunteers work to keep the internet safe and secure. We provide accurate, up-to-date information and strive to build a strong and supportive community dedicated to cybersecurity.

User Menu

Follow us

Follow us on Facebook or Twitter to know first about the latest cybersecurity incidents and malware threats.

Top