Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,143,336 members, 7,780,879 topics. Date: Friday, 29 March 2024 at 02:04 AM

Learning To Program With Java by the Fulaman - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Learning To Program With Java by the Fulaman (40997 Views)

How To Program Arduino Uno / How To Program With Your Android Phone Using Aide IDE Environment / Which Training Center Can Someone Learn How To Program Quickly (2) (3) (4)

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (16) (Reply) (Go Down)

Learning To Program With Java by the Fulaman by Fulaman198(m): 8:09pm On Apr 06, 2016
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)

you should see something similar to the screenshot below:

3 Likes

Re: Learning To Program With Java by the Fulaman by Ewizard(m): 8:18pm On Apr 06, 2016
following..
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:21pm On Apr 06, 2016
Your first programme:

Step 1. Open up a text editor of your choice (you can even use VIM if you are versed at using Linux/UNIX). Gedit, textedit, etc. etc. are all fine.

Step 1b. Alternatively, If you would like to go the IDE route, go to File, new Project, then type "Day1Project" as the project name. When that is done in the IDE, go to File, then new Class (call it Day1Programme), this new class will be part of the project you created.

Step 2: On the top of the text file, type "class Day1Programme"

Step 3. type the following below "class Day1Programme": "public static void main(String[] args) {

//This section here is referred to as the body of the programme.
}"

Step 4: Within the body of the programme, type System.out.println("Welcome to Java Programming! programming is fun!"wink;

Your program should look like this if you used a text editor (see screenshot below):

Save the file as Day1Programme.java

IMPORTANT NOTE: Your saved file name must always match the class name of your programme otherwise you will get a compilation error.


Step 5: If you are doing this in an IDE, you can see errors typically indicated by red dots or marks, also if you save the file, it automatically compiles the programme as you save it. In a text editor, you would need to compile the file which is demonstrated in the next post.

1 Like

Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:27pm On Apr 06, 2016
Step 5 cont: To compile the programme you have to use your terminal/command prompt to do so see screenshot below. Type 'javac Day1Programme.java'

Step 6: You should not get any errors if you typed everything correctly. (As shown in screenshot 1 of this post)
Step 7: Now type java Day1Programme, you should see the output that we printed using the "System.out.println" from the System class in java. (Screenshot 2)

This is the first day. Tomorrow we may do some more programming, but we will actually discuss more important concepts like what is the JVM, what is output, what is input (I won't show you how to do input yet). Thank you and I apologise if this guide is not great thus far. I will work on improving the content.

1 Share

Re: Learning To Program With Java by the Fulaman by Nobody: 8:40pm On Apr 06, 2016
wow interesting
Re: Learning To Program With Java by the Fulaman by Kingpinukecy(m): 8:48pm On Apr 06, 2016
bros dis is interesting ,Bros if any challenges am here to support also. if u av any whatsapp forum u can join me
Re: Learning To Program With Java by the Fulaman by Nobody: 9:01pm On Apr 06, 2016
Fulaman198:
Step 5 cont: To compile the programme you have to use your terminal/command prompt to do so see screenshot below. Type 'javac Day1Programme.java'

Step 6: You should not get any errors if you typed everything correctly. (As shown in screenshot 1 of this post)
Step 7: Now type java Day1Programme, you should see the output that we printed using the "System.out.println" from the System class in java. (Screenshot 2)

This is the first day. Tomorrow we may do some more programming, but we will actually discuss more important concepts like what is the JVM, what is output, what is input (I won't show you how to do input yet). Thank you and I apologise if this guide is not great thus far. I will work on improving the content.

Please is this free? Will you continue this to the end??
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 9:53pm On Apr 06, 2016
Sugarhugs:


Please is this free? Will you continue this to the end??

This is free, the only thing you have to worry about is your monthly data allotment from your ISP.

As long as people show interest, I'll update this
Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 10:28pm On Apr 06, 2016
Am Following thou i may nt comment always.
Goodwrk Fulaman!! shocked

1 Like

Re: Learning To Program With Java by the Fulaman by Nobody: 11:30pm On Apr 06, 2016
Fulaman198:


This is free, the only thing you have to worry about is your monthly data allotment from your ISP.

As long as people show interest, I'll update this

Sure! I can purchase enough data and also will follow up on this very soon, because I'm so busy so I just hope this will be up for a while till I can settle down to learn it

1 Like

Re: Learning To Program With Java by the Fulaman by CAMNEWTON4PRES: 11:52pm On Apr 06, 2016
thank you ....following , i would love to know if i can self learn programming...

1 Like

Re: Learning To Program With Java by the Fulaman by CAMNEWTON4PRES: 11:56pm On Apr 06, 2016
Fulaman198:


This is free, the only thing you have to worry about is your monthly data allotment from your ISP.

As long as people show interest, I'll update this
You and people who do this are blessings in disguise, i have always said we need to make knowledge esp practical one available to our people, it would also be nice if this could be done in hausa,fulani and other native/African languages, knowledge needs to spread throughout our societies and continent in general.

definitely following.

1 Like

Re: Learning To Program With Java by the Fulaman by Manus17(m): 11:57pm On Apr 06, 2016
fulaman is at it again... more power to your elbow man... really appreciate your effort...

Let's Learn....

1 Like

Re: Learning To Program With Java by the Fulaman by seunny4lif(m): 2:48am On Apr 07, 2016
grin
Thank God oooh
I don get headache becos of Java
I started like 2 months ago cool
Strings and Array can be confusing shocked shocked
I wish am young like 25 sad
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 7:33pm On Apr 07, 2016
CAMNEWTON4PRES:
thank you ....following , i would love to know if i can self learn programming...

Yes you can absolutely, learning programming by yourself is very possible, but learning the science behind it requires extra research. It's all about understanding how to form algorithms.

In regards to your earlier query of why I can't teach this in Hausa for Hausa speaking people and Fulfulde for Fulani speaking people, it would be nice, however the people I'm addressing here are not all Hausa and Fulfulde speakers and other Africans. I'm not here to be an ethnic lion for the Fulani people. I'm here to try and help others from the great continent learn about an important programming language. I hope that you understand.
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 7:34pm On Apr 07, 2016
seunny4lif:
grin
Thank God oooh
I don get headache becos of Java
I started like 2 months ago cool
Strings and Array can be confusing shocked shocked
I wish am young like 25 sad

Hopefully we can explain it to you in a manner that will help you understand. Learning programming is never too late.
Re: Learning To Program With Java by the Fulaman by seunny4lif(m): 7:46pm On Apr 07, 2016
Fulaman198:


Hopefully we can explain it to you in a manner that will help you understand. Learning programming is never too late.
cool
I'm more than 28 years
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 7:49pm On Apr 07, 2016
Day 2:

Like I mentioned yesterday, Java is an object-oriented language. What does it mean to use objects? Well think of it this way, your car is an object, each car has things that make them a car. A stereo system, steering wheel, headlamps, wheels, chassis, etc. etc. Think of these things as the variables that make up the car.

Yesterday we worked with a class called "Day1Programme". 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.

1 Like

Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 7:50pm On Apr 07, 2016
seunny4lif:

cool
I'm more than 28 years

I know people who started programming in their 50s, there is nothing to be ashamed of.
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:04pm On Apr 07, 2016
I hope that I'm a good teacher, my main goal is that you guys understand what is being posted here. Please feel free to ask questions if you don't understand something.

Variables and Literals:

Yesterday, we created a programme that outputs a string literal to the screen. To be more exact, we output "Welcome to Java Programming! programming is fun."

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. I have decided to use Netbeans today and no longer the command prompt. I actually encourage you to do the same. Before we start writing code today, I would like for you to please pause and have a look at the table below for the primitive data types and the ranges that they can be declared to.

Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:16pm On Apr 07, 2016
What do these datatypes mean you may be wondering well, let's assume I make what we call a declarative statement. A declarative statement is when one creates a variable and assign it to a datatype. For instance

byte myAge = 130; //This will give you a compilation error. This is what we call a declarative statement.

As you can see in the table, the byte data type only allows one a range between -128 and 127.

When you attempt to compile the programme with the Java compiler, you will get a compilation error of incompatible types. You would have to utilise a larger primitive type like "int" to make it work. As you can see, the int range covers anywhere from -2 billion something to 2 billion something. It can be used for larger numbers. The 'long' datatype can be used for even larger numbers than type 'int'.

Before I proceed, I wanted you to know what the two backslashes I used indicates in Java.

// - Indicates a comment in the code, the compiler completely ignores comments. // Can be used to comment on one line of code. E.g. //This is a comment

/* */ - Comment a huge section of code in Java. For example: /* This is a huge section of code that has been commented out. It can have multiple lines of code and often when we want to end this huge section of commenting, we close with */
Re: Learning To Program With Java by the Fulaman by seunny4lif(m): 8:19pm On Apr 07, 2016
shocked
Dats nice but the java is hard
Fulaman198:


I know people who started programming in their 50s, there is nothing to be ashamed of.
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:26pm On Apr 07, 2016
In today's programme, we will create a programme that has maybe no more than 3 or 4 lines of code. The assignment would be to create a programme that declares your age and your name using the String object and printing it out to output.

Recall your assignment from yesterday, when you used "System.out.println("Welcome to Java Programming! programming is fun!"wink " We were printing to output.

In computing, output is something that the user sees. For instance, when you print a physical documentation, a report, etc. on a printer, you can see it. When you are reading an article on your monitor, you can see it visibly. Printers and Monitors are often referred to as output devices because we can see the data or the information.

Keyboards are referred to as input devices, because when you type data, you can't see it until it goes to an output device like your monitor.

Touchscreens play the role of both Input and Output device, you make selections and you type on them (input) and you read data on them (output).

I will provide a screenshot for today's programme. Note: I'm not using my real name for privacy purposes. But the programme you create should look something like this.

I am using Netbeans as you can see from the screenshot today. Can you guess and anticipate what my programme will do?

Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:27pm On Apr 07, 2016
seunny4lif:
shocked
Dats nice but the java is hard

Things are only difficult if we convince ourselves that it is.
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:30pm On Apr 07, 2016
If you guessed that the output is the following below screenshot, then you guessed it correctly. Good job, reward yourself with some nice eba, rice, gari or whatever food you enjoy.

If you have any questions, please feel free to ask them.

Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:34pm On Apr 07, 2016
Your assignment:

Write a simple programme that declares 2 variables (num1 and num2) as type int with the values 80 and 1010, and print the addition and multiplication solution to output. Be neat, It should be clear which solution is the multiplication part and which is the addition part.

HINT: To add in java, use the '+' symbol. To multiply in Java, use the '*' symbol.
Re: Learning To Program With Java by the Fulaman by seunny4lif(m): 8:44pm On Apr 07, 2016
cheesy
I'm still learning sha grin
Fulaman198:


Things are only difficult if we convince ourselves that it is.
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 8:48pm On Apr 07, 2016
seunny4lif:
cheesy
I'm still learning sha grin

You have to remember you walked the valley of the great Sahara and God was with you like your signature says. God will be with you in your learning of Java.
Re: Learning To Program With Java by the Fulaman by seunny4lif(m): 9:00pm On Apr 07, 2016
smiley
Thanks
Java is a nice program
cool cool
Fulaman198:


You have to remember you walked the valley of the great Sahara and God was with you like your signature says. God will be with you in your learning of Java.

1 Like

Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 9:36pm On Apr 07, 2016
Fulaman198:
Your assignment:

Write a simple programme that declares 2 variables (num1 and num2) as type int with the values 80 and 1010, and print the addition and multiplication solution to output. Be neat, It should be clear which solution is the multiplication part and which is the addition part.

HINT: To add in java, use the '+' symbol. To multiply in Java, use the '*' symbol.
CHECK & CORRECT IF AM WRONG.

int num1 = 80;

int num2 = 1010;

int answer = num1 + num2;

int multiplicationAnswer = num1 * num2;

system.out.printIn(answer);

system.out.printIn(multiplicationAnswer);
Re: Learning To Program With Java by the Fulaman by Fulaman198(m): 9:45pm On Apr 07, 2016
ANTONINEUTRON:
CHECK & CORRECT IF AM WRONG.

int num1 = 80;

int num2 = 1010;

int answer = num1 + num2;

int multiplicationAnswer = num1 * num2;

system.out.printIn("answer"wink;

system.out.printIn("multiplicationAnswer"wink;

Check your output statements currently what they would print out are:

answer
multiplicationAnswer

Good try so far though.
Re: Learning To Program With Java by the Fulaman by ANTONINEUTRON(m): 9:50pm On Apr 07, 2016
Fulaman198:

Check your output statements currently what they would print out are:
answer multiplicationAnswer
Good try so far though.
ok! i made it String??
Check Out The New Code

(1) (2) (3) (4) (5) (6) (7) (8) (9) (10) ... (16) (Reply)

Facebook Is Suing Me For This / How Much Will It Cost Me To Design a mobile APP In Nigeria / Java Vs PHP: Which Has The Brightest Future?

(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. 96
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.