Java Basic Data Driven
Java Basic Data Driven
The main() is the starting point for JVM to start execution of a Java program. Without the main()
method, JVM will not execute the program.
public:
It is an access specifier.
We should use a public keyword before the main() method so that JVM can identify the
execution point of the program.
If we use private, protected, and default before the main() method, it will not be visible to
JVM.
static:
It is a Keyword.
You can make a method static by using the keyword static.
We should call the main() method without creating an object.
Static methods are the method which invokes without creating the objects, so we do not
need any object to call the main() method.
void:
It is Return Type.
In Java, every method has the return type.
Void keyword acknowledges the compiler that main() method does not return any value.
main():
It is a Method Name.
It is a default signature which is predefined in the JVM.
It is called by JVM to execute a program line by line and end the execution after
completion of this method. We can also overload the main() method.
String args[]:
main(String args[]) :-
Here, agrs[] is the array name, and it is of String type. It means that it can store a group
of string. Remember, this array can also store a group of numbers but in the form of string
only. Values passed to the main() method is called arguments. These arguments are stored
into args[] array, so the name args[] is generally used for it.
Class-
Class is the template or blueprint from which object is created and
object is the instance of class.
Class is declared using class keyword
---------------------------------------------------------------------------------------------
Object-
An object in java is the real-world entity which has its own state and
behavior
State – means this is represented by the attributes and properties of an
object.
Behavior – means this is represented by the methods of an object or it’s
Functionality.
Ex:- Mobile is an object. It’s name is redmi, colour is blue known as its state.
It is used for calling,texting messages so its behavior.
---------------------------------------------------------------------------------
Methods-
Why?
Writing methods avoid the rewriting same code again and again. Suppose you
have block of statements in your program that will calculate sum of two numbers
and perform some operation on it. But at later, you want to calculate the sum and
average in another program at that time, you need to write the same code again.
So it will increase your efforts and time also. If you define one method and
write the sum of number logic into it, if you want to calculate same in another
program, you can do it by just calling the method. So it will help you to avoid the
same code again and again. That’s why methods comes into picture.
Note- Writing all codes into one method that is not good programmer
practice.
Statement 1
Statement 2
--------------
Statement n
----------------------------------------------------------------------------------------
Variable
It is an entity that may vary during execution of program called as variable.
Variable is a name which is associated with a value that can be changed.
Object class-
It is the parent class of all the classes in java.
It is called as topmost class of java which 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.
getClass() method
hashCode() method
equals(Object obj) method
clone() method
toString() method
notify() method
notifyAll() method
wait() method
finalize() methhod
-----------------------------------------------------------------------------------------------------------------------------------------
Packages-
Package is nothing but collection of classes and interface that’s works
together called as packages.
Java.lang is default package in java. We can create our custom
packages(user defined packages) also.
Why?
Suppose imagine, if you have large number of files in your project that is deployed
on server, now the code is released on production server. There are bugs in specific
files then how you can reach to that file without packages is very difficult. If you
have packages then it will get very easy to go specific folder and found that file.
That’s why packages comes into picture.
Advantages
Reusability- we can place the common code into one folder and reuse it.
Maintenance- if any new developer/tester joined your company then it will be
easy to find the file which they needed.
Syntax-
package package_name;
----------------------------------------------------------------------------------------
import-
When we use one class within another class in different packages then go for
import statement.
Example- suppose we have two different classes Test & Example in different
packages.
------------------------------------------------------------------------------------------------------------------------------------------
Scanner in java:-
Scanner class is used to take input from user.
Scanner is a class in java.util package used for obtaining the input of the
primitive data types like int, double, etc. and strings. It is the easiest way to
read input in a Java program.
Scanner is predefined class in java.
To read numerical (int) values of a data type, the method we can use nextInt().
-----------------------------------------------------------------------------------------------------------------------------------------
Input and output stream in java-
Java I/O (Input and Output) is used to process the input and produce the
output.
Java uses the concept of a stream to make I/O operation fast.
Stream
Streams are the sequence of data that are read from the source and written
to the destination.
1) Input Streams:- An input stream is used to read data from the source it
may be a File, Memory or Console.