Forums
New posts
Search forums
News
Security News
Technology News
Giveaways
Giveaways, Promotions and Contests
Discounts & Deals
Reviews
Users Reviews
Video Reviews
Support
Windows Malware Removal Help & Support
Inactive Support Threads
Mac Malware Removal Help & Support
Mobile Malware Removal Help & Support
Blog
Log in
Register
What's new
Search
Search titles only
By:
Search titles only
By:
Reply to thread
Menu
Install the app
Install
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Forums
Guides
Programming Guides & Questions
How to start programming in Java (simple and quick tutorial)
Message
<blockquote data-quote="JM Safe" data-source="post: 783023" data-attributes="member: 35684"><p>Hello guys,</p><p></p><p>I decided to make this simple and quick tutorial about Java.</p><p>Java is not very suitable for security development but let's talk about this important language anyway!</p><p></p><p>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).</p><p></p><p>[CODE=java]public class Car{</p><p>String colour="";</p><p>public Car(String colour){</p><p>this.colour=colour;</p><p>}</p><p>}</p><p> [/CODE]</p><p>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.</p><p></p><p>In Java we have several types: Integer, String, Double, Float, etc.</p><p></p><p>Example of integer declaration (a variable which holds the value 5):</p><p></p><p>[CODE=java]int count = 5;[/CODE]</p><p></p><p>In our class we can define a <strong>method, </strong>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:</p><p></p><p>[CODE=java]public void hello(){</p><p>System.out.println("hello"); //this instruction prints hello</p><p>}[/CODE]</p><p></p><p>We can call it in another class with the following:</p><p></p><p>[CODE=java]Car car = new Car("blue");</p><p>car.hello();[/CODE]</p><p></p><p>Now let's talk about arrays: an array is like a list of elements, for example this is a String array:</p><p></p><p>[CODE=java]String[] array = new String[50];</p><p>array[0] = "MT"; //there we set the first element[/CODE]</p><p></p><p>Now let's talk about if and loops!</p><p></p><p>The if is fundamental for conditions for example:</p><p></p><p>[CODE=java]if(count>5)</p><p>{</p><p>System.out.println("MT");</p><p>}[/CODE]</p><p></p><p>So yes when our variable is bigger than 5 we print "MT".</p><p></p><p>A while loop instead: the code is executed while the condition is true, for example:</p><p></p><p>[CODE=java]while(count<5){</p><p>System.out.println("MT");</p><p>count++; //if we don't put this the loop can be infinite</p><p>}[/CODE]</p><p></p><p>Okay guys we arrived at the end of this simple tutorial: the "for".</p><p></p><p>[CODE=java]for(int i = 0; i < 10; i++)</p><p>{</p><p>System.out.println("count: " + i);</p><p>}[/CODE]</p><p></p><p>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.</p><p></p><p>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.</p><p></p><p>JM.</p></blockquote><p></p>
[QUOTE="JM Safe, post: 783023, member: 35684"] 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). [CODE=java]public class Car{ String colour=""; public Car(String colour){ this.colour=colour; } } [/CODE] 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): [CODE=java]int count = 5;[/CODE] In our class we can define a [B]method, [/B]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: [CODE=java]public void hello(){ System.out.println("hello"); //this instruction prints hello }[/CODE] We can call it in another class with the following: [CODE=java]Car car = new Car("blue"); car.hello();[/CODE] Now let's talk about arrays: an array is like a list of elements, for example this is a String array: [CODE=java]String[] array = new String[50]; array[0] = "MT"; //there we set the first element[/CODE] Now let's talk about if and loops! The if is fundamental for conditions for example: [CODE=java]if(count>5) { System.out.println("MT"); }[/CODE] 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: [CODE=java]while(count<5){ System.out.println("MT"); count++; //if we don't put this the loop can be infinite }[/CODE] Okay guys we arrived at the end of this simple tutorial: the "for". [CODE=java]for(int i = 0; i < 10; i++) { System.out.println("count: " + i); }[/CODE] 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. [/QUOTE]
Insert quotes…
Verification
Post reply
Top