Learn to Code via Tutorials on Repl.it!

← Back to all posts
computer science tutorials
h
HahaYes (1212)

Yay Java Time + Computer Science Time

Why I Made This Course

Basically school's starting again. (Yay) That means schoolwork. I'll be taking AP Computer Science, and Java is required to learn. So bear with me on Java.
This isn't just about Java, but computer science in general so feel free to watch this
My Rules:
I will not cycle squeeze.
I will get to the point
Long series.(pretty long)
Daily Tutorials.
Your Rules.
Two. Just don't be toxic in the comment section
Set up your development area. wait... this is REPL. Just make a new JAVA repl.
(@wuru want to help make the series?)
Pings:
@AbhayBhat
@Bookie0 wanted this

Yay! Chapter One of Java!


History on Java

Quoted from Wikipedia so very reliable
"Java is a general-purpose programming language that is class-based, object-oriented, and designed to have as few implementation dependencies as possible. It is intended to let application developers write once, run anywhere (WORA),[17] meaning that compiled Java code can run on all platforms that support Java without the need for recompilation.[18] Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of the underlying computer architecture. The syntax of Java is similar to C and C++, but it has fewer low-level facilities than either of them. As of 2019, Java was one of the most popular programming languages in use according to GitHub,[19] particularly for client-server web applications, with a reported 9 million developers." - Wikipedia
Yes, Java is the MOST POPULAR language.
Why Java? Minecraft. Want to mod minecraft? Learn Java.
AMAZON uses Java
EBAY uses Java
Big Companies use Java
I use Java
Squid likes to use Processing Java (way different I wouldn't reccommend leraning it other than games)
Java is SUPER popular(read wiki statement above)
anyways, lets START


Primitive Data Types

Primitive data types are the most basic data types available within the Java language. There are 8. byte, short, int, long, float, double, char, and boolean. (String is not included for it is not a primitive data type.) All data in Java goes in one of the two categories: primitive data and objects. Again, there are only 8 primitive data types. However, java has many types of objects, and you can invent as many others as you need. Any other data type you invent will be a type of object. (Java is a object oriented language ya know) For know, this is all you need to know.

  • A primitive data value uses a small, fixed number of bytes.
  • There are eight primitive data types
  • you can't make more primitive data types.
  • A object is a big chunk of data. A(n)? object may uses lots of memory.
  • A object consists of a lot of other pieces(Like legos)
  • Data type of an object is called a CLASS(lowercase but I'm too lasy to hit backspace)
  • Classes are basically forced in Java (Yay java you are the best)

Bits, and more Bits.

If you noticed, you would've realised that six of the eight primitive data types are numeric types. Numbers are very IMPORTANT. There are both integer and floating point primitive types/number types.
(amasad add flow chart support pls)
Integer types are basically whole numbers, and floating point types are basically decimal numbers.
Integer Primitive Data Types
Type | Size | Range
byte | 8 bits | -128 to 127
short | 16 bits | -32k to 32k
int | 32 bits | -2 billion to 2 billion
long | 64 bits | -9e18 to 9e18


Floating Point Data Types
Type | Size | Range
Float | 32 bits | -3.4e38 + 3.4e38
Double | 64 bits | -1.7e308 to 1.7e308
Very big numbers!!!

All primitive type uses a fixed number of bits. (!!!Very important)
This means that iif you are using a specific data type, then the same number of bits will be used no matter what the value is.
For example, the value in int data type uses 32 bits. The value 1 and the value 20000000 all use 32 bits no matter the number.(Same goes with negative)
Values that are very large need more bits to be represented, or else the computer will not evaulate the number correctly.
Preferabbly, you will long for larger numbers and int for all regular numbers.


More bits and More Range

Think of a Tesla. If you want to get more range, you pay more money. The same goes for these operators. (Except there are free! Yay!) if you want to use a larger number, you have to use a bigger number type. If the number is 15987453584538, then you would want to use long but usually, int for integers, and double for decimal numbers should be enough.

WARNING

If you want to use long, this 64 bit literal needs a upper case L or lower case l at the end for it to work.
NEVER use lower case l for it looks almost EXACTLY like 1. (See?)
Sometimes you need to explicitly ask for a single-precision float literal.


Other primitive data types

Sometimes you don't just have numbers, you also have characters. The primitive data type for characters in Java is named char chars can only store one character.
characters have a single character with a apostrophe on one side.
Like this:
'H' 'a' 'h' 'a' 'Y' 'e' 's' YOU CAN ONLY USE ONE AT A TIME
There are such things like control characters, like '\n' amd '\t' which gives a new line or a tab, but these are controllers, which we currently don't need.

Another primitive type is called boolean. It is used to represent true or false value.

Quick history lesson

boolean is named after George Boole, because he found that you could do a lot of stuff with true/false stuff.


Yayyyyyyyy its finally over

I'll be putting a quiz soon in the share place.
There will be a link here soon

Please Upvote! (because I just hit 1000 cycles so hehe)

Commentshotnewtop
DynamicSquid (3558)

No no no you have all wrong it done it. C++ is clearly is bestest there is it

HahaYes (1212)

@DynamicSquid yes it is. Don't worry Squid, I'm just trying to get a better concept of classes.

AtriDey (170)

@DynamicSquid repl go broom broom

cpp faaaaaaaaaaaaaaaahst

Lethdev2019 (178)

In a matter of fact, Rust has a comparable speed to C++ and C, it is about as fast as c++ despite using less RAM.

https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/rust-gpp.html

@DynamicSquid

HahaYes (1212)

@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 GET BACK ON THE REPl

HahaYes (1212)

@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?
@AmazingMech2418 Where are you? are you okay?

octopyBot (263)

@HahaYes hahayes, my little boy, growing up to be a SPAMMER?

L0l

HahaYes (1212)

@octopyBot oh the problem was we were working on a project, and we were actually worried that Amazingmech was gone.

octopyBot (263)

@HahaYes like ded?!

didn't mean to be NSFW sry if I was

octopyBot (263)

@HahaYes did u mean gone as in ded?

HahaYes (1212)

@Amazingmech2148 go to code jam communication, we starting to program, or else a Triumvirate will become a Duo.

DigitCommander (31)

mind blown

I can't understand Java, but well done @HahaYes
The tutorial is much appreciated.

I have upvoted

DigitCommander (31)

By the way, is C++ good?

HahaYes (1212)

@DigitCommander yes of course! All languages are good, and C++ is quite similar to java

DigitCommander (31)

@HahaYes Ok, I'll think about trying C++ out soon

HahaYes (1212)

@DigitCommander yeah its a good language to learn. Just a heads up, Java is required to learn if you are gonna do AP Computer Science in High School.

DigitCommander (31)

@HahaYes Thanks, but I'm not in high school yet

JustAWalrus (1144)

Im writing a C++ course rn. Wait till that comes out. @DigitCommander

AaronPhilip (2)

@DigitCommander
I think im pretty fluent with C++ and Java. My sincere advice is that you tend to understand Java after you do C++. But i have always preffered Java over C++ because the error handling is very easy and also Java is pretty versatile. I want to do python but im pretty adamant about Java :p

DigitCommander (31)

@Wuru Ok, I'll check it out when it comes.

DigitCommander (31)

@AaronPhilip I'll do C++ first, then Java.

HahaYes (1212)

@AmazingMech2418 AMAZING PLS PLS PLS REGISTER @DynamicSquid AND I PLS NOWNOWNOW

JustAWalrus (1144)

I have been doing java for 2 years now, I would be happy to help on the series. Bear in mind my weird workflow.

HahaYes (1212)

@Wuru Yeah I mean sure. Coming from a C++ user, its cool to learn classes. (Sorry for late reply, there is some comment lag going on)

JustAWalrus (1144)

No problem :) I'm doing some stuff with working on my custom linux distro right now anyway. @HahaYes

firefish (510)

language.getByName("C#").getRating() > language.getByName("Java").getRating() && language.getByName("C#").getSyntax() == language.getByName("Java").getSyntax();

EpicGamer007 (541)

@firefish, NO, C# is microsofts java rip-off, the only good thing about C# is Unity. java is supreme. C# isn't even cross platform.

How dare you insult java.

HahaYes (1212)

@AbhayBhat C# is just basically what happened when Microsoft got scared of competition

DungeonMaster00 (130)

@HahaYes c# is better because it has tons of features

DungeonMaster00 (130)

@nk1rwc you only need using System; at the top of your program for a whole lot of cool stuff but you need to import a ton to make a java program

DungeonMaster00 (130)

@nk1rwc ill give it that you dont need to program in sucky c++ if you want to make mods in minecraft java edition.

dlang is better than c++ anyway

firefish (510)

@nk1rwc That's wrong because System basically ignored by the CIL compiler, For example System.Console.WriteLine("This would suffice without the using System;, Just use ownership");. All the using statement does is a note to the compiler: "Well, for everything inside this namespace I'm just gonna forget to put that namespce infront, and properly deal with ownership, can you deal with that?"

AmazingMech2418 (899)

@firefish Are you saying C# is better than Java? That's funny! You are saying a Microsoft-only non-cross-platform language is better than a cross-platform language that is also used majorly in Android development and also has a full graphics language based on it (Processing)?

AmazingMech2418 (899)

@firefish By the way, YOU CAN'T EVEN USE C# IN REPL.IT WITHOUT MONO!!!

AmazingMech2418 (899)

@nk1rwc C++ is great! I have no idea what you are talking about!

DungeonMaster00 (130)

@AmazingMech2418 both c# and c++ are non-cross-platform, but c++ is a monstrosity now.

one of the reasons is <bits/stdc++.h>.

that header is evil. it is one of the worst things you can do in your c++ program.


and there's more.

when i coded a morse code converter in c++, there was a bug that if you put a space, then it wouldn't convert the rest of the sentence (probably because im still not that good at c++ yet) and the code looked fine.
and finally, there is no built in string type. ok thats not a big deal, but if not c#, i prefer dlang over c++.


also, microsoft's c# documentation is really good, so it makes development more efficient.

could've phrased it better

sources:

AmazingMech2418 (899)

@nk1rwc Um... C++ is cross-platform... Also, I've never even heard of that header. LOL! Also, can you give me the code for your morse code converter? I bet there is a bug that you just couldn't see... Also, there is std::string in C++, but you can still use C-style strings...

DungeonMaster00 (130)

@AmazingMech2418 well some stuff just don't work on all platforms (should've used unportable.) i heard found that clearing the console (or as it's called in other programming languages) varies depending on the os as an example.

source:
https://stackoverflow.com/questions/6486289/how-can-i-clear-console

AmazingMech2418 (899)

@nk1rwc Yeah, but you can just use a OS checker and define based on the OS...

DungeonMaster00 (130)

@AmazingMech2418 ok lets just end this right here.

dlang should feel familliar to c and c++ programmers. you can learn about it here.

HahaYes (1212)

@nk1rwc bits/stdc++.h was built for competitive programmers

firefish (510)

@HahaYes hAha, yes. I absolutely love it when I come back with 15 pings in my notific bar. Lovely.

DungeonMaster00 (130)

@HahaYes i just did. you got away with it this time.

AtriDey (170)

@AbhayBhat laughs in python
Only in the Godot Engine can you run Python at C++ speeds

firefish (510)

@HahaYes

let main of str = "HahaYes is godly";
write(main);
EpicGamer007 (541)

@nk1rwc...

I would say that java is better than C# for the following reasons:

  • Java is cross platform(Already stated).
  • MUCH better for mobile development(at least android)
  • Java is faster than C# in most cases
  • Java is more widely used so if you are looking to get a job, then learn java rather than C#
  • Better with other languages(Jython, SQL)

Also, java will not get bloated by too many imports which makes it great. And all the default parts of a java program are imported in java.lang.*;, which is imported in ALL programs by default.

The only thing I think that C# does better than Java is:

  • Support for Unity
  • Support for Pointers
  • Support for Operator Overloading
HahaYes (1212)

@AbhayBhat well there are references instead of pointers.

HahaYes (1212)

@AbhayBhat C# will beat any language for game dev, thats why you learn Java. If you learn java, you can create apps, and the transition from Java to C# is quite easy.

HahaYes (1212)

Someone please Grammar police this

DynamicSquid (3558)

@HahaYes You forgot a period at the end of that sentence.

HahaYes (1212)

@DynamicSquid thanks, are we gonna do the jam?

DynamicSquid (3558)

@HahaYes yeah. is CodeLong going to register us?

DynamicSquid (3558)

@HahaYes oh wait yeah yeah yeah oops lol

DynamicSquid (3558)

@HahaYes I got confused cause I was working with codelong on another project lol

HahaYes (1212)

@DynamicSquid oh ok. lemme ping amazing @AmazingMech2418 AMAZING REGISTER US IN 6 HOURS

DynamicSquid (3558)

@HahaYes oh, go on the multiplayer repl, we have to vote for a lang and team name

firefish (510)

@HahaYes Just like Lord @DynamicSquid said, remember your full stops.

firefish (510)

@AmazingMech2418 Look. I personally think that making more than one language is necessarily a bad thing.

AmazingMech2418 (899)

@firefish It is not more than one language. It is a single but customizable language.

firefish (510)

@AmazingMech2418 Those two concepts are very similar. Take .NET, it has many languages part of it. VB, C#, F#, they all compile to CIL which is the only thing .NET supports. Do you see my point here?

AmazingMech2418 (899)

@firefish But, I thought .NET was a core framework they all are based on (being mainly for Windows applications) that transpiles all of its languages (VB, C#, F#, etc.) to CIL which is then compiled to an executable. What our idea for the language is that it will not transpile to another language before being converted to an executable. It would just use separate lexers to be sent to the same parser to interpret/compile the code. .NET seems more like my idea for Adapt dialects (including the (I think) still in-progress THAIL) than the language idea for the language jam.

HahaYes (1212)

@AmazingMech2418 SIGN US UP FOR LANG JAM NOW NOW NOW

JustAWalrus (1144)

I wil get to the point

It seems that your English teacher failed to abide by that.

eekboi (272)

I like how ya put this entire tutorial into one! Nice tutorial my dude!

HahaYes (1212)

@eekboi yes. I've stopped my cycle squeezing!

EpicGamer007 (541)

@eekboi, What is cycle squeezing?

Also, Am I a spammer? this says I am a spammer
EpicGamer007 (541)

@HahaYes, upvoted :)

I suggest not asking people to upvote posts because it is kinda rude and people may not like it(You can ask me though lol idrc)
eekboi (272)

@AbhayBhat No you are not a spammer.

EpicGamer007 (541)

@eekboi, ok thanks a lot for telling me, I was about to go on hiatus from repl talk for a while, but I guess I can continue posting my java swing tutorials.

HahaYes (1212)

@eekboi I'm asking you a quick favor. Will you add your name to my upvotes in order to defeat wuru? basically all joe biden ads but whatever

eekboi (272)

@HahaYes That's... A hard no from me. Cycles weren't supposed to be a competition smh.

HahaYes (1212)

IF there are any typos, please tell me