Thursday, November 29, 2018

Java basic

WHAT IS JAVA?

Java is a high- level programming language. But what does it mean for a programming language to be high? First I should tell you about the lower levels. The "lowest" is the binary language. Which also known as machine language. It consists of 1's and 0's. When we go one level higher we see assembly language. Which is an English like language. Has only simple commands. When I say simple commands I don't mean "simple" language. For example, to display "Hi everyone"you have to write the code below:


section .text
   global _start
_start:
   mov   edx,len
   mov   ecx,msg
   mov   ebx,1
   mov   eax,4
   int      0x80

section   .data
msg   db   'Hi everyone'   ,   0xa
len   equ   $   -   msg

These two languages (binary and assembly) together considered as low-level languages. One step higher of that is high-level languages. And Java comes right here. A language is high-level when it can be written in "English English" and it can be written machine independent. 
Java runs on a variety of platforms such as Windows, Mac OS, and the various versions of UNIX. Which makes it highly portable (That's the reason you can play Minecraft on Mac :))
Java is Object Oriented. What that means is that everything is an Object. Like Class. And you will see it when we write our first hello world as a tradition. Also, one last-important thing about Java is that: Java is Platform Independent. What that means is that: when you compile Java code, it is not compiled into platform specific machine, but into platform-independent bytecode. This bytecode is interpreted by JVM (Java Virtual Machine) no matter whichever platform it is being run on.

JAVA EDITORS

You can write Java on Notepad if you would like. (Don't forget that extension for java files is .java).
You can also write in Netbeans or Eclipse. I will probably use Eclipse for examples.

SOME IMPORTANT THINGS BEFORE STARTING

Case Sensitivity--> Java is case sensitive. Which means is that two variables that named "number" and "Number" refers to different variables.
Class Names--> For now, it is not an important note but you will probably thank me at one point for this. All class names should start with an uppercase letter. 
Method Names--> All method names should start with a lowercase letter. 
Program File Name--> It should be same with the class name. Very important.
public static void main(String args[])--> This indicates your main method. Java processing starts from this method. It MUST exist in the Java program. Otherwise, it can't understand where to start.


JAVA VARIABLE TYPES:

There are 8 types of Primitive data types in Java. Which are:
boolean--> true or false. Its default value is false.
byte--> It takes an integer. Up to 8 bits. Its minimum value is -128 and the maximum value is 127. Its default value is 0.
char--> Represents 16-bit Unicode character. Its minimum value is '\u0000' or 0. Its maximum value is '\uffff' or 65,535. Its default value is '\u0000'.
int--> Stands for integer. Takes minimum value -2^31, maximum value 2^31-1 and default value 0.
double--> We use this variable type to write non-integer numbers. Its name is double because takes double-precision 64-bit IEEE 754 floating point. Its default value is 0. 
short--> 16-bit signed two's complement integer. Minimum value: -32,768, Max value: 32,767 and default:0.
long--> Just like short but longer. It is 64-bit. That means a lot.
float--> Just like double. Shorter. 32-bit. You can use it to save memory. Especially in large arrays of floating point numbers. 
HONORABLE MENTION --> String--> I know that it is not a primitive data type. But it is used a lot. Even in the main method (As you can see on "some important things before starting"). It takes an "ARRAY" of chars. (That's the reason the main method writes it as "String args[]" those brackets stands for an array as you can see again on "some important things before starting"). But what does it mean to take an array of chars? In English, it means that it takes words, sentences. Its default value is null.

FIRST PROGRAM IN JAVA

Let's start with displaying "Hello Universe".

class Hellooo
{
     public static void main (String args[])
     {
           System.out.println("Hello Universe");
     }
}

IMPORTANT THINGS ABOUT THAT CODE: First of all, I want to say that, the most important thing to be a good coder is, putting same brackets on the same vertical line. (It is not true but I think it looks waaay better.) The second important thing is that how I wrote the code. Class name starts uppercase, the main method exists, and my command is written as "System. out.println()". This indicates that my println function is (stands for "print line", after printing cursor goes to below line) taken from System class. This way of writing is only something that you can see on object-oriented languages. One more important thing is that we use ";" to indicate that our command is over. If you forget putting one you will have a hard time trying to find where the problem is. Because it won't compile.

COMMENT LINE:

To indicate comments we usually use "//". Comment lines are used for coders comments on the code. We recommend (even if we fail to use it properly) using comments often to explain what your code does in methods and complicated, hard to read commands. An example of the use of comments shown below:
class Hellooo
{
     public static void main (String args[])
     {
           System.out.println("Hello Universe"); //prints hello universe
     }
}


JAVA IF-ELSE:
The syntax of if-else is stated below:
if (condition)
{
     //code to be executed
}

The condition here is a code that returns true or false. For example:

class Hellooo
{
     public static void main (String args[])
     {
           if (1>2)
          {
               System.out.println("Hello Universe");
          }
     }
}
This code won't display "Hello Universe" because 1>2 = false. But below code will:

class Hellooo
{
     public static void main (String args[])
     {
           if (1<2)
          {
               System.out.println("Hello Universe");
          }
     }
}
Else is used with if statements. What it means is that do if block if condition is true else(if condition is not true) do else block. An example code is shown below:

class Hellooo
{
     public static void main (String args[])
     {    int a=2;
           if (a>1)
          {
               System.out.println("A is greater than 1");
          }
           else
          {
               System.out.println("A is not that great.");
          }
     }
}

This code above will print "A is greater than 1" to console (without "s). Because we created an int variable and told that its value is 2. Then our code looked into if statement's condition and saw that it is true and compiled it. There was no reason to look else block.

If there was more than one if what would happen? Let's look at the code below:

class Hellooo
{
     public static void main (String args[])
     {    int a=2;
           if (a>0)
          {
               System.out.println("A is greater than 0");
          }
           if (a>1)
          {
               System.out.println("A is greater than 1");
          }
           else
          {
               System.out.println("A is not that great.");
          }
     }
}

This code would print both "A is greater than 0" and "A is greater than 1". Because it looked at the if statement and condition provided. Compiled first if, then saw second if. Condition provided again and block compiled. There was no reason to compile else block, because if conditions are provided. To compile else block, the code should have passed all if statements and had no chance but to compile else block.

There is also else if statement. Let's look at an example:

class Hellooo
{
     public static void main (String args[])
     {    int a=2;
           if (a>0)
          {
               System.out.println("A is greater than 0");
          }
           else if (a>1)
          {
               System.out.println("A is greater than 1");
          }
           else
          {
               System.out.println("A is not that great.");
          }
     }
}
What I did is to simply change second if statement to an else if statement. But now console will only display "A is greater than 0". Because what else if does is, it only compiles when if statements ignored but its condition is provided.

Friday, November 9, 2018

HTML tags

<html> </html> 

Indicates the start and end of the HTML document.

<head> </head>

Head of the HTML document. Has no attribute that displays directly on the document. Contains only metadata of the HTML document.

<body> </body>

The body of the HTML document. This part is what you will display on your page.

MOST USED TAGS YOU CAN USE BETWEEN HEAD TAGS

<title> </title>

Title of the page. Basically, the tab name that you see on your browser.

<style> </style>

The part that you can customize the colors and styles of your document. The CSS part. We will give more information about it.

<meta  />

It hasn't got a different ending tag. We use this tag to indicate character set that we are using, keywords that you can use to search on google, description, and content of the page. We will talk about it more.

<link>

Has no ending tag. You can use it to use CSS or JS documents from a link. We will talk more about it.

<script> </script>

Javascript part if you want to add.

<base>

Has no ending tag. It specifies default URLs and default link targets on a page.


MOST USED TAGS YOU CAN USE BETWEEN BODY TAGS

<p> </p>

Stands for PARAGRAPH. What you write between will be displayed as a paragraph.

<h1> </h1> , <h2> </h2>, <h3> </h3>, ...

Stands for HEADER1, HEADER2, ... Displays text as a header. H1 indicates the main header.

<a> </a>

An abbreviation for ANCHOR. What it does is anchoring to another link.

<button> </button>

Adds BUTTON.

<ul> </ul>

Stands for UNORDERED LIST. Starts a list with unordered bullets.

<ol> </ol>

Stands for ORDERED LIST. Starts a list with ordered bullets.

<li> </li>

Stands for LIST ITEM. Every item you add to your list should start and end with these.

<br> or </br>

Stands for BREAK. You can use it as enter button.

<img>

Stands for IMAGE. You can use it to add images.

<table> </table>

Indicates the start and end of a TABLE.

<caption> </caption>

Indicates the CAPTION of the table.

<tr> </tr>

Stands for TABLE ROW. Indicates the start and end of a table row.

<th> </th>

Stands for TABLE HEADER. Indicates the start and end of a table column header.

<td> </td>

Stands for TABLE DATA. Indicates the start and end of a table data.



Thursday, November 1, 2018

HTML Structure and Tips

* HTML STRUCTURE

    For starters, a simple HTML structure is like this:

   There is also " THE <!DOCTYPE> DECLARATION"

It represents the document type declaration. It helps browsers to display web pages correctly but the codes you write will work without declaring the document type if you save them as HTML files.

Document type declaration for HTML5 is: 
           <!DOCTYPE html>

* TAGS IN HTML ARE CASE-INSENSITIVE. 
Which means that there is no difference between writing:
    <p>Hi</p>        and        <P>Hi</P>

* HOW TO START WRITING A HTML DOCUMENT:  

You can use Notepad ++ or other editors but a simple text document would do the job. 
Just add a text document to wherever you want in your computer.
Name your file whatever you want and change document extension to htm like this:

myName.htm

The first page in web pages often named as index because they often contain the index of the site.

SOME TIPS:

TIP 1:















This is a simple code that I have written. What it displays is this:

But when I organize the code a little it becomes like this:

Now it is easier to see which tags are under which tag and it is harder to forget a not closed tag.

TIP 2:

You can simply use Notepad for your code. But what I recommend is using an editor such as Notepad++ in order to get a more organized code and shortcuts:

Just open a document in Notepad++ and save as an HTML document. And it will give the colors and shortcuts for you.

TIP 3:

I recommend closing the tags right after opening one in order to deal with forgotten tags.







HTML Quick Introduction

Hello everyone,

After finally putting my things on track, I can finally concern myself about my blog. This post will be about HTML.

1. HTML IS NOT A PROGRAMMING LANGUAGE!

HTML stands for Hyper Text Markup Language. Which means it can just MARKUP. What it simply does is that it describes the structure of Web page using a markup language. You can see any web page's structure just by pressing F12 on browser or CTRL+U.

2. HTML HAS BLOCKS!

If you pressed F12 you will see something like this:


















When I put the cursor on sections you will see that some parts of the web page are highlighted.
That is because of the code you put the cursor on describes that part of the web page.


The part you see on the right bottom corner of the page describes the layout of the page. On future posts, I will explain what they mean more detailed.

3. HTML HAS TAGS!

Every HTML element is represented by tags. And all tags are surrounded by angle brackets. And tags come with pairs (with 1-2 exceptions)  like this:
<html> </html>
The first tag is the start tag and the second tag is the end tag. If there is an element that is not shown, you probably forgot one of the tag pairs.

Thursday, October 4, 2018

Hello World!

    I guess I was in the sixth grade when I first saw the cryptography challenges that a website posts online and at the eight grade I saw about the puzzle "Cicada 3301". At that point, I realized that  I really love challenges and programming is a great way to keep getting new ones. I decided to learn how to programme. I wanted to learn about solving cryptograms, making video games, even maybe hacking FBI(just a joke NSA). Well, after an hour of research I realized that it is not that easy. Because when you don't know anything you can't know where to start.
    After I started at university I was teaching some of my classmates about programming lessons. And I was really tired of telling the same thing over and over again. Then I realised I will have to tell everything to my freshman brother too. So when our digital marketing teacher asked us to keep a blog I wanted to use it for quick programming videos, programming tips, jokes and maybe about cybersecurity. Hope you'll like it...