Download an install samsung usb drivers from here.
Download odin (latest version preferred) from here.
Download the exact rom of your device. Check out samsung roms from here.
Watch video tutorial from here
Make sure only Auto Reboot & F. Reset Time is ticked.
Put your device into download mode by pressing down Volume Down > Home > Power key
Press volume up on the screen that has a yellow triangle to get into odin mode.
Connect the device to the computer.
Added!! will be seen showing the device has connected successfully.
Click on AP (new versions of odin) or PDA (older versions of odin).
Navigate to the folder containing the rom of the device.
Select the rom. (roms names always end with .tar or .md5).
Wait for odin to process the rom.
The flashing or upgrading process will now begin.
A green progress bar will be seen at the top left.
This process will take about 8 mins or more (depends on the size of the rom.
When you see PASS! at the top of odin GUI know that you have successfully flashed or upgraded the device
The device will reboot.
First boot after this process takes time. Be patient.......................
Do a factory reset if phone bootloops.
Press Volume up > Home > Power key
Select factory reset.
Scroll down to Yes.