[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Care to explain line be line how my simple program works /b/?
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.
The stories and information posted here are artistic works of fiction and falsehood.
Only a fool would take anything posted here as fact.
You are currently reading a thread in /b/ - Random

Thread replies: 13
Thread images: 2
File: Japjeg.jpg (283 KB, 700x544) Image search: [Google]
Japjeg.jpg
283 KB, 700x544
Care to explain line be line how my simple program works /b/?


I just started learning java 3 hours ago because /g/ said it's the best language. So right now Java is getting more confusing so while i'm having this burning passion to learn something motivate me /b/
Learning is fun /b/
>>
Line 2 creates a class
Line 4 creates a void
Line 6 creates a for loop that loops from 1 to 11
Line 8 checks if looped number is even
Line 9 prints the number if it is even
>>
>>580380005
Java sucks, /g/ is fucking with you.

Regardless. The second line is required because in java everything has to be within a class. The curly brackets define the start and end of the class. Then line four begins a method. The main method is where actual execution begins, so lines 6 through 10 are the meat of your program. The for loop in line 6 executes lines 8 and 9 once for every number (call it i) up to ten starting from zero. Line 8 causes line 9 to execute if i is even. Line 9 prints the value of i.
>>
>>580380798
>The curly brackets define the start and end of the class

false. The curly brackets define the start and end of a block
>>
>>580380417
Nice simple explanation.
>>580380798
Thanks. So which programming language is worth learning than java?
>>
>>580380005
So, the first line declares a class. Every method has to be in a class in Java, for reasons you will later understand.

The second line is the so called "entry-point". This is what the system looks for when starting to execute your program. It always looks the same.

The third line is a loop, starting from the integer one, incrementing by one every iteration (i++) and then checking if it that counter is still below 11

The next line is called a condition. You check if your counter modulo two (thats the reminder of a division by two) is equal to zero, so in other words if you have an even number.

And then you tell the system to print "#: " + i, and append a newline (the difference between print and println(=printline) )
>>
>>580380005
the first line states you will never have a gf
>>
>>580381365
Java is a good starting point, but later you will want to get into some more advanced languages and concepts, if programming and learning is what you really enjoy.

As a step up I would recommend Scala because it runs on the JVM (the thing enabling your java code to run on linux and windows alike) and can therefore use any Java code and vice versa
>>
>>580380005
>the best language
Kek
>>
>>580381687
also, it's way more sexy.
Later, you will want to look into Python and JavaScript (just casually), Haskell (for the real understanding of functional programming), Go (as a C++ alternative) and Rust (because that's really interesting as well).

Languages aren't everything tho, so get to know your environments.

Best thing you can do: Learn Java enough to join a company, and everything else will fall into place.
>>
>>580380005
>because /g/ said it's the best language

nigger, the only /g/ approved languages are scheme, common lisp and all the other lisp dialects
>>
>>580381961
Kek
>>
>>580381903
Thanks for the great advice. I'll follow that advice.
Thread replies: 13
Thread images: 2

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.