Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,151,167 members, 7,811,383 topics. Date: Sunday, 28 April 2024 at 10:41 AM

Java Programming Tutorial From Scratch - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Java Programming Tutorial From Scratch (1347 Views)

Python Programming Tutorial for Beginners(Software development) / C Programming Language Overview - Programming Tutorial Tellmoreblog / How Can I Get Full Web Development/programming Tutorial Video For Free. (2) (3) (4)

(1) (Reply) (Go Down)

Java Programming Tutorial From Scratch by Elementaltinz(m): 2:09pm On Dec 30, 2018
Java is an object-oriented programming language that was first developed in 1995 under Sun Microsystems which today has been acquired by Oracle. The Java language today is used in a lot of server side applications, database programming alongside SQL, embedded controls, games, etc. Many people often rank it as the First or second most important programming language to learn. Most importantly, Java is used to create Android Applications.
So what is Java? as aforementioned it's an Object-oriented programming language much like C#, Objective-C, Swift, Ruby, C++, etc. We will get into what it means to be object-oriented later.
Today, we will construct our own first program, but before we can begin, I need you to install the JDK (Java Development Kit), current release from the official website, which comprises of the compiler, JVM, etc. The JDK can be found from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Please scroll down to where you see Java SE Development Kit 8u77 and select your operating system's version of Java to install (I assume that you have some basic computing knowledge and know which OS you are using).
For the time being, it's optional if you would like to use an IDE (integrated Development Environment) to write your programs. If so, I recommend Netbeans which can be found here and is the official IDE created and updated by Oracle: https://netbeans.org/ , or alternatively Eclipse: http://www.eclipse.org/downloads/ or IntelliJ: https://www.jetbrains.com/idea/.
If Data is an issue, don't worry, you can simply use a text editor, but the JDK is mandatory to compile your programs and for them to run on the Java Virtual Machine (which we will discuss in detail later in day 2 of Java Programming).
When you have finished installing, you can check what version of java you are running with the following command on command line terminal
Mac: java -version in terminal
Linux: java -version in terminal
Windows: java -version (in command prompt)


For those that doesn't have a computer and would love to join us
Go to playstore, download and install JAVA-IDE
Just 28mb
The tutorial kicks off on the first in this thread
Interested members comment below!!!
Re: Java Programming Tutorial From Scratch by dicksonadams(m): 2:20pm On Dec 30, 2018
Great
Re: Java Programming Tutorial From Scratch by stiles009(m): 3:52pm On Dec 30, 2018
Nice one op. I'm eargerly anticipating
Re: Java Programming Tutorial From Scratch by amadiwati(m): 4:03pm On Dec 30, 2018
Interested!
Re: Java Programming Tutorial From Scratch by masterfactor(m): 5:36pm On Dec 30, 2018
following
Re: Java Programming Tutorial From Scratch by Fela4ese: 11:30pm On Dec 30, 2018
Interested
Re: Java Programming Tutorial From Scratch by Obagreatdatoye(m): 6:31pm On Dec 31, 2018
Interested....
Re: Java Programming Tutorial From Scratch by payne4real(m): 8:35pm On Dec 31, 2018
Following
Re: Java Programming Tutorial From Scratch by Nobody: 3:09am On Jan 01, 2019
Interested
Re: Java Programming Tutorial From Scratch by Just2endowed2(m): 4:01am On Jan 01, 2019
Interested
Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 7:28pm On Jan 01, 2019
Sorry it was late......



CLASS 1: JAVA PROGRAMMING
Now today, I'm gonna teach the basics of writing a simple program.
We're gonna skip the notes and go straight into programming.
I promise you are going to understand because I myself hate notes. They are just a group of jumbled English(just kidding).
CLASS AIM: WRITING A PROGAM TO PRINT OUT YOUR NAME
For those on PC
If you've installed netbeans,
Open it(like every normal computer program)
It's going to take a little time to load
At the top left corner click FILE
it's going to open some sub menus
click NEW PROJECT
And it would take you forward to a platform
The platform is already set JAVA as default
So don't change anything (unless you want to run another language)
Click NEXT
Then it would display project name, package,main class,.....
Change only the project name and nothing else unless you are moving into another platform
The project name is the name you want your program to bear
The project name is set as JAVAAPPLICATION1 or any other one that suits them.
Delete whatever is in it and input the name you want your program to bear.
E.g ELEMENTALTINZ or Elementaltinz or elementaltinz or eLeMeNtAlTiNz
Any that suits you!
Then move down and click FINISH
It will then take you to the platform where you will write your source code.
FOR MOBILE PHONES
Like I said I recommended JAVA-IDE but for those managing data, go to playstore and download DCODER.
DCODER writes all languages but JAVA-IDE specializes on Java
DCODER is not up to 8mb sha....
OK
Open the app
Click options (it's the one that looks like a file)
It will open then click New Java Console Project
It will ask for these three things for you fill
1. Project name (the neme of your project)e.g Elementaltinz
2. Java package name(the name of the storage source code*not exactly correct, just a layman language*)
Always write it as com.(anything or your project name....make sure it is small letter all through)
E.g com.element
3. Main class name (mostly, it is the name of your project but if there is space in your project name, make sure there is no name in your main class)
E.g Project name: Nairaland Programming
Main class: NairalandProgramming
Click OK then it would take you to the page where you would write your source code
CODING
Once you've gotten to this stage, this is what you're going to see
package com.Register;
public class Register {
public static void main(String[] args) {
}
};
Now let me explain the above codes
class keyword is used to declare a class in java.
public keyword is an access modifier which represents visibility, it means it is visible to all.
static is a keyword, if we declare any method as static, it is known as static method. The main method is executed by the JVM, it doesn't require to create object to invoke the main method. So it saves memory.
void is the return type of method, it means it doesn't return any value.
main is a entry point of the program. Execution of programs starts from main. It is called by Runtime System
String[] args is used for command line argument. We will learn it later.
Now do you get??(all these are stories*just kidding*just make sure they are always there)
Now when you want to write something, make sure you write it
public static void main(String[] args){
Write your code here;
Unless ERROR(not all cases; would explain later)
If you didn't find a space here, just Tab or enter so as to push this brace down
}
Now to print any statement, we use the code
System.out.println();
1.Always make sure you add your semi colon";"
2.System.out.println() is used print statement.
3. Type it into those braces I mentioned earlier
4. Now to type anything you want into it, in between the brackets ...println(); always add your inverted comma. i.e " "
Then anything you want to type would be inside the inverted comma
Else, tying into the bracket without inverted comma, declares it as a constant*later*
So it would be like this
Lets write our name
System.out.println("My name is Elementaltinz "wink;
That's how it should look like
So the full source code for writing your name is e.g
package com.name;
public class name {
public static void main(String[] args) {
System.out.println("My name is Elementaltinz"wink;
}
}
And the output would be:
name
My name is Elementaltinz
And now we've come to the end of today's class.
For those with question, drop it below
And to make sure you guys are following up, I would give you guys some assignment
1. Write a project called MyName that will print out your name
2. Create a project called ComputerExpression that will print out 2 + 2 - 4 = 0
To submit, screenshot your project and submit here
Next class loading......
Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 7:31pm On Jan 01, 2019
.........
Re: Java Programming Tutorial From Scratch by BHANKYPSALM: 9:29pm On Jan 01, 2019
Thanks interested
Re: Java Programming Tutorial From Scratch by Obagreatdatoye(m): 9:36pm On Jan 01, 2019
Nice one...
But I haven't gotten the answer to the expression 4+4-2=0 yet!
Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 10:56pm On Jan 01, 2019
Obagreatdatoye:
Nice one... But I haven't gotten the answer to the expression 4+4-2=0 yet!
you can ask questions wherever you aren't clear
Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 12:39pm On Jan 03, 2019
Assignment correction package com.tu;
public class tu {
public static void main(String[] args) { System.out.println("2+2-4 = 0"wink; } }
Output tu 2+2-4 = 0

Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 12:45pm On Jan 03, 2019
output

Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 12:50pm On Jan 03, 2019
We worked with a class called "MyName". I won't go into much detail about what a class is, but in general terms, a class is the general blueprint for an object. It is what is used to build an object with various variables, functions/methods, etc. We will elaborate more on that later once we improve our level of knowledge in the realm of Java.
Today, I would like to discuss the Java programming language in a sense as well as variables which is what one finds in every programming language.
Human beings process data differently from computers. When I communicate with another human being, I communicate with them in English, French or my native languages spoken in the great nation of Nigeria. When I say hello, you, the human understands that as a greeting.
Computers handle data differently and interpret it differently. Often, a computer processes data in a series of 0s and 1s. This kind of data is what we refer to as binary or base 2.
Java is often referred to as a high-level language. What high-level language means is that it is closer to human interpreted language. This course will not delve into machine language and high-level language much so I won't go into further detail. Contact me personally if you would like to know more via messaging here.
In Java, when you write a programme in the High-level language, and compile the programme, it is read by a Virtual machine known as the Java Virtual Machine (JVM). The code that the Virtual machine reads is referred to as Bytecode. It is code that is not readable by most human beings and only intepreted by the virtual machine. The JVM makes it possible for java programmes to be run on various platforms (Linux, Windows, Mac/UNIX). Which means if you write a programme on Windows, you can run it on a Linux or Mac Machine due to the JVM.
We will discuss this further in a later lesson. Today's main lesson is in regards to Variables and Literals and basic output.
Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 12:52pm On Jan 03, 2019
Variables and Literal
We created a programme that outputs a string literal to the screen.

What you see in quotation marks is often referred to as a String literal or very simply put a String. In most high-level programming languages String are a form of datatype, however in Java, String is part of an Object class and is often referred to as an object. We will expand on this more later on the tutorial.
In Java, there are 8 data types that store data which we refer to as variables. These data types are: short, int (which is actually an Integer), byte, long, boolean, float, double, and char. In a sense, we refer to these data types as primitive types in Java.
A byte is a primitive type that stores 8 bits of data, a short is a datatype that stores 16 bits or 2 bytes of data (1 byte = 8 numerical bits), an int stores 4 bytes of data, a long stores 8 bytes of data, a boolean stores 1 bit of data in the form of either true or false, a float is a floating point number that stores 4 bytes of data, a double is an even larger floating point primitive type that stores 8 bytes of data and a char stores individual characters. In essence, a String object is an array of type 'Char'.
All of this may sound very foreign to you right now and that's understandable as that is just how it is for everybody. However, I will try to simplify it so that you understand by writing a programme.
int is used for storing numbers or integers in your program or making an integer a constant. E.g int a = 1;
Char is used for storing just one single alphabet or character e.g char a = w;
Float is used to store decimals(let's say but the decimals are rounded up to e.g 2.3, 1.5, 0.5 etc) it has just one number after the decimal point
Double is used to store decimals(let's say it would give your decimal out in full e,g 5.3948283747472724959)
String is used to store characters(char) or words e.g String a = my name is IDK;
boolesn is used to tell whether a statement is true or false
Byte, long, short are for signed integers e.g -3343..... But there are also exceptions

Are you following?

1 Like

Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 12:57pm On Jan 03, 2019
*Today's Project*

We are going to write a project that we will input our constants into the program, then ask the program to add or subtract, whatever

package com.tu;

public class tu {

public static void main(String[] args) {
int a;
int b;
int c;
a = 8;
b = 12;
c = a + b;
System.out.println(a + "+" + b + " =" + c);
}
}


Output
tu
8+12 = 20
Screenshots below���
Now how do we write this codes?
I told you into is used for storing numbers ;
Then I want to use three numbers : 8, 12 and the summation of the two
Then I need two ints for 8 and 12
So I said int a(or anything);
Always remember to add ; at the end of each code u write
Int b;
Then we tell the computer what to do with int a and b
That's why we said
a = 8;
b = 12;
So anywhere we want to use a and b, it would replace the output with 8 and 12
Then we brought int c;
Because we want a and b to be added up and since a and b are int, then to add then up, we use int for them also
Then c = a + b;
If we were multiplying, we use a*b, subtraction a-b, division a/b;'
Then for it to print out

System.out.println(a(cuz it should show first num....we didn't add " " cuz it will just print "a". So if we wrote just a, it will print out what a stands for) (Space) +(compulsory always add plus when you want your first printing to also join with the next thing you want to write)(Space)"+" (I added + cuz when it prints out, it would print 8 + ......."wink(Space) + (Space) b(as I explained a)(Space) + (Space) " = "(So your output would be 8 + 12 = ......)(Space) + c(as I explained c));
That is;
System.out.println(a + " + " + b + " = " + c);


Simple
Then run it let's see
Out put
8 + 12 = 20

Chikena
Simple
Assignment
Create a program that add, subtract, multiply and divide
You can follow the above example

Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 12:58pm On Jan 03, 2019
output

Re: Java Programming Tutorial From Scratch by amadiwati(m): 2:40pm On Jan 03, 2019
Elementaltinz:
Java is an object-oriented programming language that was first developed in 1995 under Sun Microsystems which today has been acquired by Oracle. The Java language today is used in a lot of server side applications, database programming alongside SQL, embedded controls, games, etc. Many people often rank it as the First or second most important programming language to learn. Most importantly, Java is used to create Android Applications.
So what is Java? as aforementioned it's an Object-oriented programming language much like C#, Objective-C, Swift, Ruby, C++, etc. We will get into what it means to be object-oriented later.
Today, we will construct our own first program, but before we can begin, I need you to install the JDK (Java Development Kit), current release from the official website, which comprises of the compiler, JVM, etc. The JDK can be found from here: http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Please scroll down to where you see Java SE Development Kit 8u77 and select your operating system's version of Java to install (I assume that you have some basic computing knowledge and know which OS you are using).
For the time being, it's optional if you would like to use an IDE (integrated Development Environment) to write your programs. If so, I recommend Netbeans which can be found here and is the official IDE created and updated by Oracle: https://netbeans.org/ , or alternatively Eclipse: http://www.eclipse.org/downloads/ or IntelliJ: https://www.jetbrains.com/idea/.
If Data is an issue, don't worry, you can simply use a text editor, but the JDK is mandatory to compile your programs and for them to run on the Java Virtual Machine (which we will discuss in detail later in day 2 of Java Programming).
When you have finished installing, you can check what version of java you are running with the following command on command line terminal
Mac: java -version in terminal
Linux: java -version in terminal
Windows: java -version (in command prompt)


For those that doesn't have a computer and would love to join us
Go to playstore, download and install JAVA-IDE
Just 28mb
The tutorial kicks off on the first in this thread
Interested members comment below!!!

Apologise for being behind the class, however, I'd meet up
I have few questions
1. The Javae SE link you gave us doesn't have 8u77 but 8u191 and 8u191
2. My system is 32bit operating system
Re: Java Programming Tutorial From Scratch by Elementaltinz(m): 2:47pm On Jan 03, 2019
amadiwati:

Apologise for being behind the class, however, I'd meet up I have few questions 1. The Javae SE link you gave us doesn't have 8u77 but 8u191 and 8u191 2. My system is 32bit operating system

I would check it out and reply u later

1 Like

Re: Java Programming Tutorial From Scratch by Just2endowed2(m): 4:09pm On Jan 04, 2019
nice class

keep it up

(1) (Reply)

Warri Developers Meetup / Software Engineering Instructor - Urgently Needed / Vtn Online/gsm Payment System For Nigeria. What About It?

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 64
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.