Day 1 : Learn Java Programming for Beginners
What is Java ?
The below words describes java in a better way :
- general purpose
- object oriented
- class based
- platform independent
modern programming language. It is designed in the early 1990s by Sun Microsystems but currently owned by Oracle.
Describe why Java is a general purpose programming language ?
Since 2000s, Java is a highly popular programming language till today. It is used for different purposes like banking, retail, information technology, Android application development, financial services, stock market, scientific and research work. Some softwares using Java as an essential core of their functionalities, for example node.js, spring, Angular . I believe these reasons are sufficient to prove Java as a general purpose programming language.
What is object oriented programming ?
As the name suggests, object oriented programmings, known as OOPs, use objects in programming. Now let us discuss,
what is a object in real world ?
cat, dog, cow, car, bus, human these are all examples of objects. All these objects have state and behavior. Let us consider dog
What is the state of an object ?
A dog may be of brown color, white color or any other color. Means the color of dog may change from dog to dog. The name of dog may also change from dog to dog. The bread of dog may also very from dog to dog. These name, color and bread can also be called as different states of dog object.
What is the behavior of an object ?
A dog may wag the tail, may bark, may eat. These bagging the tail, barking and eating can be called as behavior of dag object.
Objects of programs also have states and behaviors like these real world objects. We will discuss about them later.
Describe why Java is a platform independent programming language ?
A programming language can be said as platform independent, if the programs compiled in this language can be run on any operating system.
In reality nothing is platform independent. Java is useing a specific technique to make it a platform independent. The programs written using java programming are known as java source codes. First, using java compiler we will compile these source codes and generate Java byte codes. These byte codes are still not in machine understandable format. We have to use Java Virtual Machine (JVM) to run this java byte code on any platform. This means JVM is platform specific. We have to use platform specific JVMs.
This is the beauty of Java platform, we donot have to change our source code to run it on another platform. That is the reason, for which Java is known as a platform independent programming language.
What are the prerequisites to write a Java Program?
We need three things to write compile and run a java program.
- We need a Text editor to write our Java program. The program written should be saved with .java extension.
- We need Java compiler to compile the file into Java byte code.
- We need JRE (java run time environment) which has JVM (java virtual machine) required to run the java byte code.
But we will keep it simple and use IDE(Integrated Development Environment) which will help us to write, compile and run the java program.
If you are using windows computer, then you can download BlueJ which is easy to use for new programmers. BlueJ is available for Windows, Mac, Ubuntu and other platforms with Java or Java FX 11 support. You can download latest version of BlueJ by clicking here or visiting bluej.org.
If you are using android phone, then download from many number of available IDEs from playstore.
How to write first java program using BlueJ ?
If you are using windows computer i personally suggest to download the portable version. It does not require installation. You can take it on pendrive and use on any windows computer.
As shown in image click on Standalone Zip to download the portable version. A zip file will be downloaded. After downloading right click on the zip file and select Extract to Bluej-windows-422 as shown in figure. In your case it may be something different then 422 if you have downloaded a different version.
Now open Bluej-windows-422 folder and double click on Bluej.exe file to open it. As you are opening it for first time it will show you a dialog box. Click on I agree to take part and I certify that i am 16 or older. You can also choose no thanks. Now Bluej is opened and ready to write our first program.
Step : 1
Click on project menu and select new project. Here enter a project name and the location where you want to store your project.
What is a project in BlueJ ?
Bluej project or a standard java package is a directory which contains the files included in the project. Most of the files are java class files with .java extension and other files are a build file, image files etc.
Step : 2
Every java program must have a class. Click on New Class to create a Java class file. It will show a create new class dialog box. Write the name HelloWorld in the class name box as shown in figure. Click on Ok. It will create a file in the name of HelloWorld.java. Remember Java is a case sensitive language. Means here capital letter S and small letter s has different meaning. HTML programming is not case sensitive means for that language capital letter S and small letter s has same meaning. So while write java source code be careful about case of letters. Watch carefully here in our file name we have written, upper case H and upper case W.
Step : 3
A brown color box with black border will be shown. Double click on that, our source code file will open. For the timing don’t worry by seeing all these codes in the file. Delete all the codes showing and write below codes.
public class HelloWorld
{
public static void main(String args[]){
System.out.println(“Hello World!”);
}
}
Step : 4
Now Click on compile button to compile the source file.
Then click on close button to close the source file.
Now right click on the same brown color box with black border. A menu will appear. Click on void main String[] args from that menu. You will see a new window and Hello World! written there.
Congratulations you wrote, executed and got the output of your first java program successfully.
Now we will discuss step by step what we wrote in our program.
In java every code we want to execute should be with in a class. In this program we created the class HelloWorld. With in class we write methods. What ever we write for this class will be enclosed with in curly braces.
Methods do actual operation. The method Main is special because it is the start of program. The program starts from Main method and runs accordingly as per our program. The word wise meaning of the statement :
publis static void main(String[] args)
- public: Mean that main () can be call from anywhere
- static: This type of method can be run without creating an instance of the class containing the main method.
- void: method does not return any value
- main: is the name of the function or method.
- String: mean the data type. String[] means array of strings.
- args: args is the argument passed to the function. “args” is not special and you can name it to anything else and the program would work the same
- [] can be suffixed to String or args. In both the cases the program would work the same.
Now we will write codes that main method will execute. All these statement of codes will be with in curly braces like our class. In our program we wrote only one statement. This statement displays the string with in double quotes, on the computer screen.
Remember at the end of each statement we will use semicolon (;) to close the statement. But do not use semicolon after method and class declaration if those have body defined using curly braces.
We will discuss regarding each term in detail in our later chapters. So do not worry if you have still doubts.
Now try to print different text on the screen. This can be done by changing the text parameter of println method. If you want to learn programming perfectly always play with codes.
To practice the quiz : Click here
For Life time valid video tutorials of this course : Link comming soon
Downloadable video tutorials for TTRC Player : Link comming soon
Tag:bluej, describe why java is a platform independent programming language, difference between real world object and java objects, java programming for beginners, java programming for school students, java programming using bluej, java projects from scratch, what is a real world object, what is java, what is object oriented programming
You must log in to post a comment.