Basics Of Core Java:
Core Java :
In java there are three basic java programming element will be there.
Class
Interface
Enum
Syntax: Syntax means some set of rules which we need to follow whenever we are writing the code. If we are not following the syntax we will be getting an Error.
Access Modifier : Access Modifier Access restriction which will enhance the data security.
There are four types of Access Modifier :- 1) Public
- Private
3)Protected
4)Package Private(Default)
1) Class :
Syntax of a Class : <AccessModifier>class<ClassName>
{
--------;
--------;
}
2) Interface :
Syntax Of a Interface : <AccessModifier>interface<InterfaceName>
{
--------;
--------;
}
3) Enum :
Syntax of a Enum : <AccessModifier>enum<EnumName>
{
-----------;
----------;
}
We can write only two access modifier for java class ie., Public and package private (Default). A java class never be an Private and Protected.
Java Method :
Java method is the place where we can write the "Business Logic".
Syntax of a java method : <AccessModifier><Return Type><Method Name>
{
-----------;
-----------;
}
Return Type : There are four return types.
void
All 8 primitive data types (int , byte , short , long , double , float , char , boolean)
Classes
Interface
For java class we can use all four return types.
void method does not return any type.
Any data in the double quote " " this is called String .
We can create any number of Objects inside a class.
A method will be getting executed ONLY whenever we are calling it.(If we are not calling a method it will never be executed).
We need to call a method with the help of RESPECTIVE CLASS OBJECT.
How to create an Object: In order to create an object first we need to write "new" keyword and then initialize it with the help of constructor.(constructor name should be same as ClassName).
If we want to see the output of the java program we need to perform two tasks. 1)Compilation.
2)Running.
1) Compilation : Compilation means checking the code whether we have written according to the java language syntax or not.
After successful compilation java compiler is going to generate a .class file
The generated .class file will be same as ClassName.
The generated .Class file consist of byte code instruction which are understandable only by the machine , human's can't understand them.
Extension for the compilation is Javac FileName.java
2) Running : In order to run our java program we need to provide the generated .Class file as an input to the JVM(Java Virtual Machine).
JVM is going to check whether all the byte code instruction which are present in the .Class file right or wrong. If those are correct we will be getting our output , if those are wrong we will be getting an Exception.
Java main() :
Java main() will be executed even without calling (No need to call main()).
Without writing a main() we can not run our java program.
Every java program execution start with main() and end with main().
I hope the information shared in this article was helpful to you.
If you have any question or suggestion, you can leave them in the comments section below, and I'll be happy to answer every single one.
ThankYou.
Subscribe to my newsletter
Read articles from Pallavi Sadawarte directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Pallavi Sadawarte
Pallavi Sadawarte
๐ Hello..I'm pallavi sadawarte. ๐Blogger | web developer | tech enthusiast. ๐ Passionate about writing , coding and sharing knowledge about the tech. ๐ Connect with me on social media and let's collaborate on exciting projects. ๐ Check out my latest article on hashnode Blog. ๐I enjoy problem solving and finding efficient solutions for everyday tasks.