You Must Know This About Java - II
Tags: java, beginners, codenewbie, discuss
Published: 2021-06-06 10:56:22

This article is remaining half of my last article, it would be better if you do check this one before continuing (in last article I wrote about what is Java how it works etc) ***[You Must Know This About Java - I](https://dev.to/ritvikdubey27/you-must-know-this-about-java-i-k9h)***, in this I'll conclude the other remaining basic terms of Java making it as short as possible.
## Let's begin...
## Let's talk about Java code
So Java code is a well organized code. Java code must be written in Class or Interface or in enum body. Writing code in any of these bodies gives security and connectivity or mapping [one to one, one to many, many to one, many to many]. When developing applications in Java, hundreds of classes and interfaces will be written.
>- Java is case sensitive
- Java is strongly typed
- White-spaces are ignored by compiler
- Unlike JavaScript and Python you have to take care of semicolons (;) in Java.

### Object
![object.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1622955363364/WBwIFJUBi.jpeg)
Look around and you'll find many examples of real-world objects like your car, your computer system, your bag etc. They all have state and behavior. Car have state(fuel level, wheels, gears etc) and behavior(accelerating, changing gear etc). Objects have states and behaviors. Object's state is stored in fields(variables) and behavior is shown via methods. 
### Class
![class.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1622955373020/jMEaE-8mc.jpeg)
When you look around you'll find many individual objects of same kind for example BMW, Audi, Mercedes etc all are car, it means they all have 4 wheels, gears etc that means they all are built from the same set of blueprints and therefore contains the same components. *A class is the blueprint from which individual objects are created.* A class can have any number of methods.

**This will be more clear from this picture:-**
![class-object.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1622965177203/Yr6MEIGvn.jpeg)

#### Object class
Object class is present in **java.lang** package. Every class in Java is directly or indirectly derived from the Object class. If a Class does not extend any other class then it is direct child class of Object and if extends other class then it is an indirectly derived. Hence the Object class is the parent class of all the classes in java by default. In other words, it is the topmost class of java.
#### Runtime class
Java Runtime class is used to interact with java runtime environment. Java Runtime class provides methods to execute a process, invoke GC, get total and free memory etc. There is only one instance of **java.lang.Runtime** class is available for one java application.

>#### There are 4 different access levels-
- **default** - Accessible within same package
- **public** - Accessible everywhere
- **private** - Accessible within same class
- **protected** - Can be accessed after importing

### Method
Method represents some specific task in a program. Methods allow us to reuse the code without retyping the code. The most important method in Java is the **main()** method.
![method.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1622955730353/Wb4vCRrVv.jpeg)
- Method describes the mechanisms that actually perform its
tasks.
- Method hides from its user the complex tasks that it performs.
- Method call tells method to perform its task.

>Two methods of same class can be called together

>**Syntax:-**
method().method();

### Instance Variable
Instance variables is used by Objects to store their states. Instance variables are declared in a class, but outside a method, constructor or any block. They are called so because their values are instance specific and are not shared among instances. Each object have a unique set of instance variable.
### Packages
A Package can be defined as a collection of similar types of classes, interfaces and sub-packages in the form of directory structure. In simple words you can say a Java package is used to group related classes together. To use any package **import** keyword is used. There are two categories of packages, built-in packages and user-defined packages. You can think of it as a folder. 
![packages.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1622972235862/2AHM4AzYF.png)
#### Description of package importing -
![package-structure.jpeg](https://cdn.hashnode.com/res/hashnode/image/upload/v1622974552856/Nx_pTE-VT.jpeg)
**Importing a particular class from the package**
 ```Java
import java.util.Scanner;
```
**Importing all classes of the package**
 ```Java
import java.util.*; //this is bad practice
```
>The Number of words in a package are called identifiers.


### Framework
A Framework can be defined as collection of built-in objects and libraries to create any real world application. In other words, Java Framework is a collection of predefined classes and functions that is used to process input, manage hardware devices interacts with system software. It provides more security, more networking features, and no server down on huge traffic.
**Java provides us some very strong frameworks -**
![strong.jpg](https://cdn.hashnode.com/res/hashnode/image/upload/v1622975207533/kS5Uuk6Hr.jpeg)
- Spring
- Hibernate 
- Grails 
- JavaServer Faces(JSF) 
- Struts

### Okay so that's enough for now follow my this journey to learn more about Java.
#### *Thank you for reading.*
#### *Please share your thoughts about it and correct me if I'm wrong.*
#### *I hope you liked it and found it helpful.*
#### ***Cover:- [Rajat Gour](https://twitter.com/rajatgour20)***
#### *Connect with me on [Twitter](https://twitter.com/ritvikdubey27?s=09) or [LinkedIn](https://www.linkedin.com/in/ritvik-dubey-3bbb22169)*
#### *My personal blog [blog.ritvikdubey.com](https://blog.ritvikdubey.com/)*