Jump to content

Recommended Posts

Posted

 

The teachings of basic, proper Java

 

Normally I wouldn't mess around and would just get to it. But I believe at least an introduction is necessary. So here goes.

 

Hello Joe, my name is Blake and I'm posting this tutorial to teach you how to understand and write in the Java programming language. It wont be easy, so don't expect it to be. This tutorial will not teach you how to compile or set up a private server, this tutorial will teach you the basics of Java, nothing less, nothing more.

 

So, where do we begin?

 

Variables

In Java, there are certain things that you can create called variables. Technically, a variable is an object that can hold a specific type of data. In other words, a variable is something that can hold a value.

Here are the types common of variables, what they stand for, and the type of value they can hold:

int - integer - whole numbers under 2.17 billion in size

long - long integer - whole numbers that are larger than 2.17 billion.

double - double - variable that can contain numbers with decimal values

boolean - boolean - holds only two values, true or false

String - String - holds more than one character, like a word or sentence.

 

 

int

This is a very common variable. It stands for integer, and can hold values of whole numbers less than 2.17 billion (this includes negatives), but cannot hold decimal values. If you try to make an integer bigger than 2.17 billion, your program will crash.

 

long

This is the exact same as an int, except it can hold larger values than 2.17 billion (on Windows machines). It cannot hold decimal values.

 

double

The double is the exact same as a long, except it can hold decimal values.

 

boolean

This is a helpful little variable, although it can only hold two values. The boolean cannot hold numbers, it can only hold two values: true and false.

 

String

The String is a special type of variable. It can hold multiple characters to form a series of words or a sentence.

 

So how do we use these variables?

In Java, any variable must be explicitly declared. Because of this, Java is sometimes considered a strongly typed language. Don't worry about that though. Just know that before you want to use a variable, you must tell Java that it exists. To do this, we declare our variable.

 

Declaring a variable looks like this:

Code:

 

accesslevel type name;

 

 

Access Level:

The access level is how your variable can be accessed. By default, other packages cannot see or use a variable unless you set the access level properly. A package is a folder that contains related Java classes. A Java "class" is a Java file. Most private servers don't use packaging, so you don't need to be too worried about the access level.

Common access levels are as so:

Code:

 

public

private

 

 

There are more, but you don't need to worry.

 

public

The access level public means that other packages can see it, hence the term public.

 

private

The direct opposite of public, other packages cannot see a variable with access type of private

 

You do not have to specify an access level for your variables. By default, variables are private and cannot be accessed by other packages unless you declare them as public.

 

Type:

The type in our variable declaration is the type of variable we are declaring: int, long, boolean, double, etc.

 

Name:

Name is simply the name you give to the variable you are declaring. By Java conventions, your variables should start with a lowercase letter, and any other words in your name must start with an upper case letter. The name cannot contain spaces.

 

An example of a variable declaration:

public int myInteger;

 

Statements

A statement in Java is basically anything you are coding. Anything from declaring a variable to doing advanced math is either a statement or a series of statements. The variable declaration above is a statement. Statements must end with a semicolon unless you are using a code block. A code block is simply, a block of code, starting with { and ending with }. Therefore, for every {, there must be a } to end the statement.

 

Conditional Statements

A conditional statement is a statement that will execute only when a certain condition is met. These statements are also called "if" statements. This is the layout for an if statement:

if(arguement)

    code to execute;

 

 

If you are using only a semi colon in any statement, you cannot perform more than one action in the statement. Here is an example explaining this concept:

int myInteger;

myInteger = 1;

if(myInteger == 1)

    System.out.println("Yay!");

System.out.println("myInteger is equal to one!");

 

How many statements are in the above code? There are actually four statements in the above code.

Statement one: declaring myInteger.

Statement two: setting myInteger to 1.

Statement three: this is our conditional statement, it therefore includes the "System.out.println("Yay!")", but only executes it if myInteger is 1.

Statement 4: printing "myInteger is equal to one!" into our console.

 

System.out.println(String) prints text to the console.

What do you think the output is of this program? Here is what it will say:

Yay!

myInteger is equal to one!

 

What happens if we change the code to this?

int myInteger;

myInteger = 2;

if(myInteger == 1)

    System.out.println("Yay!");

System.out.println("myInteger is equal to one!");

 

 

Now what is the output?

myInteger is equal to one!

Surprised? I expect you to be. By changing myInteger to 2, the conditional statement should not execute and it should not say anything at all. Wrong, because as I stated above, you can only execute one action if you are using just a semi colon. To change this, we will use what is called a code block. A code block allows you to execute more than one action at once within one statement.

Here is an example of the above code, with a code block instead:

int myInteger;

myInteger = 2;

if(myInteger == 1)

{

    System.out.println("Yay!");

    System.out.println("myInteger is equal to one!");

}

 

Now what is the output of the program?

Nothing.

We have successfully bunched two actions into our code block, and because our myInteger variable is 2, the if statement never executes because it only executes if myInteger is 1.

 

You might have noticed the "=" and "==" characters in the above statements. These are called operators, which brings me to the next section...

 

Operators

 

An operator is something that performs a calculation. There are many operators, all meant for specific calculations. Here is a list of the common ones, and their purpose.

/ ~ Division

> ~ Greater Than

< ~ Less Than

>= ~ Greater than or equal to

<= ~ Less than or equal to

== ~ Equal to

!= ~ Not equal to

++ ~ Increment

-- ~ De-increment

&& ~ AND

|| ~ OR

 

Thats a lot of operators eh? Trust me, there are more operators, designed for performing calculations on the level of bits and bytes. For the sake of your sanity, we'll just stay with the operators I've listed above.

 

I wont go into detail about these operators for the sake of time, you can figure out what they do by looking at the list above.

Now that I've gone over basic conditional statements and variables, lets go onto methods.

 

Methods

Simply put, a method is a chunk of code that performs a calculation, and returns a value based on the calculation it makes. Its not as complicated as it seems. A method is just like a variable, it is declared in the same way. The key difference is that a method must have a code block, while a statement doesn't have to. A method is a holder for statements. Here are a few types of methods:

 

void

int

long

String

boolean

double

 

The list goes on, however, these are the most common types of methods. You may have noticed that they are very similar to variables, well in a sense they are. I mentioned before that a method returns a value. Every method returns a value except for a void. Lets go over what they return.

 

void

No return type.

 

int

Returns an integer.

 

long

Returns a large integer.

 

String

Returns a String value.

 

boolean

Returns a boolean value

 

double

Returns an integer value with decimal points supported, or a double.

 

You may have noticed that the methods return the value that their brother variables can hold. If you made this connection, good job. If not, that's okay.

 

Declaring a method is just like declaring a variable, but you add a code block.

Here's the way you declare methods:

accesslevel type name(parameters)

{

    Code inside the method

    return value

}

 

Parameters are slightly more advanced. Basically, a parameter is a way of giving our method variables so it can perform calculations. You can have multiple parameters in your method.

 

To make a method execute, we have to call the method by its name and its parameters. Here is the layout of calling a method:

name(parameters);

 

Separate parameters are separated by a comma. Here is an example of how to use parameters:

public static void main(String[] args)

{

    System.out.println("The value of 5.5 + 5.5 is equal to" + doAddition(5.5, 5.5));

}

double doAddition(double one, double two)

{

    double solution = one + two;

    return solution;

}

 

We will go over the above code line by line

Line 1: our main method which Java calls when it starts the file.

Line 2: opening brace for our main method code block

Line 3: printing to the console window by calling doAddition(int, int) method

Line 4: closing brace for our main method code block

Line 5: declaration of our doAddidion method which is the double type, so we can do addition with not only whole numbers but also decimals

Line 6: opening brace for our doAddition method code block

Line 7: creating a new integer called solution, then setting solution to one + two.

Line 8: returning solution, the value that was calculated based on the parameters given

Line 9: closing brace for our doAddition method code block

 

The output of the above program looks like this:

The value of 5.5 + 5.5 is equal to 11

 

 

What might confuse you is the parameters. You declare variables in parameters, and use them only within the code block of the method that has the new variables. We give the parameter variables their value when we call the method.

 

Why do this when we can just do variable = number + number? Well sometimes we want to do more advanced calculations than just addition, such as the quadratic formula or distance formula. Methods are advanced, custom calculations.

 

About the void. A void is a method with no return type, therefore it does not return anything. The void simply executes the statements within it and finishes whenever it is called.

 

Classes

A class, technically, is an object in object-oriented programming. Simply put, a class is usually a Java file that holds methods. This is a slightly more advanced concept than we have previously talked about.

A class is declared just like a method, except you must put 'class' as the type. All of your code must be contained within the code block of a class.

 

Here is what a normal Java program looks like:

public class HelloWorld

{

    public static void(String[] args)

    {

        System.out.println("Hello World!");

    }

}

 

The above code will compile and run in the Java environment.

When running once compiled, it will say

Hello From Danoobz0r!

 

Cute.

Lets move on.

 

Classes can be (here comes a big word) instantiated, or created an instance of. Creating an instance of a class from another class tells that class to run relative to the class that is creating an instance of it. Its complicated, you may have to read that sentence a few times to understand. Basically, you can call a class like you can call a method. But instead of calling the class, you must create an instance of the class. Once you create an instance of the class, you can use almost any method or variable that is inside the class.

Here is how you instance a class:

classname variablename = new classname(parameters);

 

Yes, classes can also have parameters. This is done by what is called the classes constructor. It is an advanced concept that you may not understand for a while until you get used to programming Java.

By default, any class you create has no parameters, so you do not include any parameters in the instance of the class.

This is how to create an instance of a class using parameters.The class we are going to instantiate

 

public class SayHello

{

    String text;

 

    public SayHello(String text)

    {

        this.text= text;

    }

 

    public static void main(String[] args)

    {

        System.out.prinltn(text);

    }

}

 

 

}

 

Line 1: declaring our class SayHello

Line 2: opening brace for our SayHello class

Line 3: declaring a new string, naming it 'text'

Line 4: white space

Line 5: constructor. Notice the parameters, we are creating a new variable inside the constructor.

Line 6: opening brace of the code block for our constructor

Line 7: setting the String text in the outside of our constructor to the parameter that we received when the class was instantiated.

Line 8: closing our constructor code block

Line 9: white space

Line 10: main method called by Java when the program starts

Line 11: opening brace for our main method code block

Line 12: printing to the console the value of the 'text' String

Line 13: closing our main method code block

Line 14: closing our SayHello class code block.

 

Instancing the class

SayHello mySayHelloClassVariable = new SayHello("Hello, From Danoobz0r!");

 

Now, when we run the above statement that instances the SayHello class, the SayHello class will print the following text:

Hello, World!

 

 

Congratulations, if you have made it this far, you now understand the basics of Java programming.

 

credits to  tsgh mike

 

  • 3 weeks later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Posts

    • if you want auto vote reward system lucera2 i support it add me discord c1c0s#3564
    • @Update improved config files & updated vote sites @Update added JMobius Support
    • @Update improved config files @Update added Lucera2 Support @Update added JMobius Support
    • Nope just sellers bumping their topics. Wlc back 😜
    • General Trackers :   IPTorrents invite IPTorrents account 1 tb TorrentLeech invite Torrentleech account 1 tb buffer  InTheShaDow ( ITS ) account Acid-lounge invite Torrentday invite Crnaberza account Abn.Lol account Limit-of-eden account Norbits account Xspeeds account Xspeeds invite Bemaniso invite Wigornot account Bithumen invite Filelist account Funfile invite AvistaZ invite Potuk.net invite ResurrectThe.Net invite GrabThe.Info invite Greek-Team invite LinkoManija invite Fano.in account TreZzoR account Speed.cd invite Arab-torrents.net account Arabscene.me account Scenetime account 4thd.xyz invite Btarg.com.ar account Dedbit invite Estone.cc account Speedapp invite Finvip invite Fluxzone account GigaTorrents account Gimmepeers account Haidan.video invite Mojblink account Mycarpathians invite Newinsane.info account Oscarworld.xyz account Peers.FM invite Pt.msg.vg account Ransackedcrew account Redemption invite Scene-rush account Seedfile.io invite Teracod invite Torrent.ai account Torrentmasters invite Ttsweb invite X-files invite X-ite invite Ncore account TorrentHR account Rptorrents account BwTorrents account Superbits invite Krazyzone account Immortalseed account Tntracker invite Pt.eastgame.org account Bitturk account Rstorrent account Tracker.btnext invite Torrent-turk.de account BeiTai.PT account Pt.keepfrds account 52pt.site account Pthome account Torrentseeds account Aystorrent account Blues-brothers.biz invite Divteam account Thesceneplace invite CinemaMovies.pl account Brasiltracker account Patiodebutacas account Newheaven.nl account  Xthor account Swarmazon.club invite Bc-reloaded account Crazyspirits account Silentground invite Omg.wtftrackr invite Milkie.cc invite Breathetheword invite Madsrevolution account Chilebt account Yubraca account Uniongang.tv account Frboard account Exvagos account Diablotorrent account Microbit account Carp-hunter.hu account Majomparade.eu account Theshinning.me account Bithorlo account Youiv.info account Dragonworld-reloaded account Sharewood.tv account Partis.si account Digitalcore.club invite Fuzer.me account R3vuk.wtf invite Ztracker account 1 tb buffer 3changtrai account Best-core.info account Bitsite.us account Eliteunitedcrew invite Exitorrent.org account Hellastz account Tophos invite Torrent.lt account Sktorrent.eu account Oshen account Blackhattorrent account Pirata.digital account Esharenet account Ohmenarikgi.la Pirate-share account Immortuos account Kiesbits account Cliente.amigos-share.club account Broadcity invite Ilovetorzz account Torrentbytes account Polishsource account Portugas invite Shareisland account ArabaFenice account Hudbt.hust.edu.cn account Audiences account Nanyangpt account Pt.sjtu.edu.cn account Pt.zhixing.bjtu.edu.cn account Byr.pt invite Ptfiles invite Red-bits account Pt.hdpost.top account Irrenhaus.dyndns.dk (NewPropaganda) account Mnvv2.info (MaxNewVision V2) account 1ptba.com account Spidertk.top account Casa-Torrent (Teamctgame) account Film-paleis account Generation-free account Aftershock-tracker account Twilightsdreams account Back-ups.me invite Sor-next.tk ( Spirit Of Revolution ) account Tfa.tf ( The Falling Angels ) account Hdmayi account S-f-p.dyndns.dk ( Share Friends Projekt ) account Unlimitz.biz account Pttime account St-tracker.eu account New-retro.eu account Zbbit account Tigers-dl.net account Jptvts.us account Lat-team account Club.hares.top account Falkonvision-team account Concen account Drugari account Megamixtracker account T.ceskeforum account Peeratiko.org account Zamunda.se account Central-torrent.eu account h-o-d.org account Hdturk.club account Torrentleech.pl account Demonoid invite Lst.gg account Fakedoor.store account LaidBackManor account Vrbsharezone.co.uk invite Torrenteros account Arenaelite account Datascene account Tracker.0day.community Tapochek.net invite Jme-reunit3d account Ptchina invite Lesaloon account Exyusubs account Therebels.tv account Ubits.club invite Zmpt.cc account Turktorrent.us account Dasunerwarte account Funsharing account Hawke.uno account Monikadesign account Theoldschool.cc invite Fearnopeer account Alpharatio account Desitorrents account Wukongwendao.top account Chinapyg account Azusa.wiki account   Movies Trackers :   Pixelhd account Cinemageddon account DVDSeed account Cinemageddon account Cinemaz account Retroflix account Classix-unlimited - invite Movie-Torrentz (m2g.link) invite Punck-tracker.net account Tmghub account Tb-asian account Cathode-ray.tube account Greatposterwall account Telly account Arabicsource.net account   HD Trackers :   Hdf.world account HD-Only account Torrentland.li account HdSky account Hdchina account Chdbits account Totheglory account Hdroute account Hdhome account TorrentCCF aka et8.org account 3DTorrents invite HD-Torrents account Bit-HDTV account HDME.eu invite Hdarea.co account Asiancinema.me account JoyHD invite HDSpace invite CrazyHD invite Bluebird-hd invite Htpt.cc account Hdtime invite Ourbits.club account Hd4fans account Siambit account Privatehd account Springsunday account Tjupt account Hdcity.leniter invite Ccfbits account Discfan account Pt.btschool.club account Ptsbao.club invite Hdzone.me invite HDDolby account Danishbytes account Zonaq.pw account Tracker.tekno3d account Arabp2p account Hd-united account Reelflix.xyz account Hdatmos.club account Anasch.cc invite Tigris-t account Nethd.org account Hd.ai invite Hitpt.com account Hdmonkey account Dragonhd.xyz account Hdclub.eu account Forum.bluraycd.com account Carpt account Hdfun.me invite Pt.hdupt invite Puntotorrent account Ultrahd account Rousi.zip account Blutopia account   Music Trackers :   Dicmusic account Music-Vid account Open.cd account LzTr account ProAudioTorrents invite Jpopsuki invite TranceTraffic invite Audionews invite Kraytracker invite Libble.me invite Losslessclub invite Indietorrents.com invite Dimeadozen account Funkytorrents invite Karaokedl account zombtracker.the-zomb account Concertos invite Sugoimusic account Satclubbing.club invite Metal.iplay invite Psyreactor invite Panda.cd account Adamsfile account Freehardmusic account Tracker.hqmusic.vn accouunt Twilightzoom account 3 tb buffer Hiresmusic account Metalguru account   E-Learning Trackers :   BitSpyder invite Brsociety account Learnbits invite Myanonamouse account Libranet account 420Project account Learnflakes account Pt.soulvoice.club account P2pelite account Aaaaarg.fail invite Ebooks-shares.org account Abtorrents account   TV-Trackers :   Skipthecommericals Cryptichaven account TV-Vault invite Shazbat.TV account Myspleen account Tasmanit.es invite Tvstore.me account Tvchaosuk account Jptv.club account Tvroad.info   XXX - Porn Trackers :   FemdomCult account Pornbay account Pussytorrents account Adult-cinema-network account Bootytape account 1 Tb buffer Exoticaz account Bitporn account Kufirc account Gaytorrent.ru invite Nicept account Gay-torrents.org invite Ourgtn account Pt.hdbd.us account BitSexy account   Gaming Trackers :   Mteam.fr account BitGamer invite Retrowithin invite Gamegamept invite Cartoon/Anime/Comic Trackers : U2.dmhy account CartoonChaos invite Animetorrents account Nyaa.si account Mononoke account Totallykids.tv account Bakabt.me invite Revanime account Ansktracker account Tracker.shakaw.com.br invite Bt.mdan.org account Skyey2.com account Animetracker.cc   Sports Trackers :   MMA-Tracker invite T3nnis.tv invite AcrossTheTasman account RacingForMe invite Sportscult invite Ultimatewrestlingtorrents account Worldboxingvideoarchive invite CyclingTorrents account Xtremewrestlingtorrents account Tc-boxing invite Mma-torrents account Aussierul invite Xwt-classics account Racing4everyone account Talk.tenyardtracker account Stalker.societyglitch invite Extremebits invite   Software/Apps Trackers :   Ianon account Brokenstones account Appzuniverse invite Teamos.xyz account Graphics Trackers: Forum.Cgpersia account Gfxpeers account Forum.gfxdomain account Documentary Trackers: Forums.mvgroup account   Others   Fora.snahp.eu account Board4all.biz account Filewarez.tv account Makingoff.org/forum account Xrel.to account Undergunz.su account Corebay account Endoftheinter.net ( EOTI ) account Thismight.be invite Skull.facefromouter.space account Avxhm.se (AvaxHome) account Ssdforum account Notfake.vip account Intotheinter.net account Tildes.net invite Thetoonz account Usinavirtual account Hdclasico invite HispaShare account Valentine.wtf account Adit-hd account Forum-andr.net account Warezforums account Justanothermusic.site account Forbiddenlibrary.moe account Senturion.to account Movieparadise account Militaryzone account Dcdnet.ru account Sftdevils.net account Heavy-r.com account New-team.org account   NZB :   Drunkenslug account Drunkenslug invite Usenet-4all account Brothers-of-Usenet account Dognzb.cr invite Kleverig account Nzb.cat account Nzbplanet.net invite Ng4you.com account Nzbsa.co.za account Bd25.eu account NZB.to account   Prices start from 3 $ to 100 $   Payment methods: Crypto, Neteller, Webmoney, Revolut   If you want to buy something send me a pm or contact me on:   Email: morrison2102@gmail.com   Discord: LFC4LIFE#4173   Telegram: https://t.me/LFC4LIFE4173   Skype: morrison2102@hotmail.com
  • Topics

×
×
  • Create New...