A blog for computer science passionates.

Wednesday, 29 January 2020

Hello Friends!!!!

In this article, I am going to share one big thing i.e. Say Hello World i.e. How to start Java programming. Let's start.

I give you one suggestion before the start, if you are a beginner in programming please use notepad as an editor don't use any smart editor for Java or any other development. For Java, Netbeans and Eclipse both are smart editors but don't use it if you are a beginner otherwise you don't feel Java programming and work hard and tough so we can remember syntaxes and can learn more effectively.

Let's start Java Programming. Our First Program is to say Hello World, Hello Java!!!

So for that open notepad (I am working on Windows) or open run (window+r) and type notepad press enter.

It will open notepad now type below program:


And you just need to run this code in the command prompt: To open a command prompt again go to the run (window+r) and type cmd and press enter or click OK button.

Now you need to open your path i.e. your drive and directory. Just follow the following commands

To open drive in cmd:
type drive letter and colon i.e. if you want to open d drive, type d: command.
And you will get your drive open with

d:\>

To open directory (folder) that should be available in your drive use below command:

cd <your_directory_name>\<another directory name (if any)>

For Example, in d drive, we have java folder in which ch1 folder so type

This command opens all directories in one command
d:\> cd java\ch1

or
This command opens directory one by one.
d:\> cd java
d:\java> cd ch1

it will open d:\java\ch1> directory.Check out this video on how to open drive and directory in cmd. (I show two different ways to open directory either one by one or in a hierarchy)

To Compile & Run Java Program:

We have javac command to compile the program and java command to run the program.

For example, in our above example we define a class with the name SayHello now we just save this file with the name "SayHello.java" and just compile this file with the following command:


javac SayHello.java
This command generates a class file and  we need to run this class file by using the following command:


java SayHello

This command shows the output "Hello World, Hello Java!!!" See the figure below:
Fig. The output of the Java program

So, that's it for today in the next article I will tell you about what we exactly use i.e. which classes and what is the main method and some other aspects.

Till then Happy Coding☺

Monday, 27 January 2020

Hello Friends!!!
Let's discuss some concepts of 😊bject-☺riented Programming. First of all,
What is Object?
  • In simple words, the object is a combination of Data and Functions. It represents a class and class contains data and functions (methods). For example, consider a class of Animals and an object of an animal class is a dog, cat, etc. it has data i.e. a dog has four legs, two eyes and function i.e. the behavior of a dog is barking.
What is the Class?
  • The class is from which object belongs, i.e. in our above example if an object is a dog, it comes from Animal class. Even we can say that the class is a collection of Data and Function and to represent the data and function we need to make an object. 
What are Methods?
  •  The methods, to work on data, manage data and operate these data. For example, if we have the data about the employee of a company such as employee id, name salary and based on that salary want to calculate allowance and total salary of an employee one needs to define a method.
These three are the main pillars of object-oriented programming. Let's discuss more topics about it...

Inheritance: 
As we know that object-oriented programming is based on real-world concepts and in the real world we have different relations. so object-oriented programming also believes in the relationship. So we have this concept of inheritance. In which, we have more than one class and we relate these classes with each other and reuse the attributes. Reusability is the key for OOP. There are different types of inheritance such as,
  • Single-Level
  • Multi-Level
  • Hierarchical
  • Multiple
  • Hybrid
  • Multipath
But, Multiple and Multipath inheritances do not support by Java. As Java works on real world concept and in real world multiple parents are not possible on child or children, in multiple and multipath inheritance work on multiple parent so.
I just want to figure out all the types of inheritance. And it is easy to get.

Fig. Types of Inheritance
Polymorphism:
It is a greek word means Multiple forms of an attribute such as methods or constructor. To build method or constructor in a class with multiple forms we have to follow some rules,
  • Pass different numbers of arguments in a method or constructor.
  • In a method, we can set a different return type of a method.
For example,
int area(int length, int breadth)
double area(int radius)

This is called Method Overloading.
In inheritance, we can achieve Method Overriding. In inheritance, we have two classes parent and child class, in parent class we have one method and we redefine that method with the same syntax is called method overriding.

Abstraction and Encapsulation:
Through abstraction, we can show all the essential elements and in encapsulation, we can hide the necessary data.

We will see all the concepts in detail when we will look at examples, through all these concepts you feel that Java is based on Real-World thus Java is really great and powerful because it works with and on data.
While working with any object-oriented programming we need to think only one thing and it is data.

Hope you enjoy, this and feel these concepts are yours and related to our life somewhere :)

Sunday, 5 January 2020

Hello Friends!!! and welcome again,
Happy new year to all Hope you enjoyed, this is the first post of this year...
In this article, we are going to discuss more features of Java. If you do not look at the first part, please read it first. Now, Let's move to the remaining features of Java,
  • Secure: Java is secure, as it is interpreted and compiled even it doesn't work directly with memory. It has JVM, so Java is a secure programming language.
  • Portable: The main problem with any programming is portability. And Java is designed to work with 
    WORA "Write Once, Run Anywhere"
    rule and JVM is the main part to provide portability. So, our Java Application runs today, tomorrow and F☺rever.
  • Multithreaded: Java is a multithreaded programming language. In our application, there are lots of different tasks, that we need to manage simultaneously. So, Java works with the threading mechanism and our application can manage multiple threads at the same time even we can synchronize it.
  • Interpreted and High Performance: As we have discussed earlier, Java is interpreted programming language. It interprets in JVM and generates a byte code and uses JIT (Just - in - time) compiler to achieve high performance.
  • Distributed: Java can work with distributed environment also, it has RMI (Remote Method Invocation) API to work on a distributed environment.
  • Dynamic: Java programs have run-time type information to validate and verify the access of objects at run-time to make code type-safe.
 So, These are the different features, after seeing all the features we can get that Java has rich set of features and How Java becomes powerful?
In the next article, we will learn more about Java Programming Language.