Java as an object oriented language
source edited by me
In Java, everything is an Object, when a Java program is considered, it can be defined as a collection of objects that communicate through calling upon each other's methods. Java source code is compiled to byte code. Byte code are obtained from source code which are optimized set of instruction by virtual machine.
For any programming language to be called an object oriented language it always have these features which Java supports
Abstraction
Classes
it is a blue print that creates an object.
Objects
it is an instance of a class.
Instance
As class is a blue print that creates an Object, creating instance is the process of making an object based on the given class which is the blueprint.
Encapsulation
Encapsulation is bundling of data. Java language hides the methods that operate on that data, or restricting of direct access to some of an object's components.
Method
methods are capabilities within an object.
Inheritance
In Java, a class can inherit attributes and methods from another class. Java is a concept that acquires the properties from one class to other classes.
Polymorphism
in Java processing objects differently on the basis of their class and data types is feature it possess.
Why Java is platform independent
Java is platform independent because it is compiled to byte code and the byte code are portable which runs in all platform and environment eg Unix, MDC etc. The compilation of Java starts from source code which is compiled to byte code and byte code interpreted by virtual machine to object code or machine language.
A simple program on Summing two numbers in Java
import java.util.Scanner;
public class Summing {
public static void main(String args [ ])
{
Int a, b, Sum;
Scanner myInput=new scanner (system.in);
System.out.println("please enter a value for a");
a=myInput.nextInt;
System.out.println("please enter a value for b");
b=myInput.nextInt();
Sum=a+b;
system.out.println("sum= " + sum);
}
}
Also, a simple program on Area of a circle πr2
public class Area{
public static void main(String args [ ]){
double r, A;
double PI= 3.142;
Scanner myInput=new Scanner (system.in);
System.out.print("please enter a value for radius")
r =myInput.nextDouble();
A =PI* r* r;
System.out.println("Area="+A);
}
}
SOME SYNTAX OR RULES OF JAVA
Java is case sensitive
Declaring "a" and using "A" in the program means a different thing to Java.All classes should start with Capital letter
All class in should start with Capital letter eg public class "Area".All methods names should start with lower case
Example: Scanner myInput=new Scanner (system.in);public static void main(String args[ ]) must be included in the program Java program processing starts from
the main() method which is a mandatory part of every Java program.
Thanks for going through my post, I really appreciate
I really appreciate this community as I also wish to delegate to this community from my earning in upfront time but to start with I set 20% beneficiary to @siz-official
Best regards
@siz-official
@devann
@bright-obias
@vvarishayy
Java, python and nmt language ls are the most difficult languages i have no knowledge about this but after reading of some posts in our community i like to read it. Keep sharing posting with us.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks, Steem Infinity zone is my best community ever.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Wow...this is amazing, this is really an eye opening, you've really helped broaden my knowledge on programming,🔥
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
Thanks, I appreciate.
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit
@siz-official
@faran-nabeel
Downvoting a post can decrease pending rewards and make it less visible. Common reasons:
Submit