0% found this document useful (0 votes)
25 views10 pages

Java Basic Data Driven

The main() method is the starting point for Java program execution by the JVM. It must be declared as public static void and accepts a String array of command line arguments. Without a main() method, the JVM will not execute the program. The main() method indicates the entry point of the program and runs the program line by line until completion.

Uploaded by

Vikas Pallewar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
0% found this document useful (0 votes)
25 views10 pages

Java Basic Data Driven

The main() method is the starting point for Java program execution by the JVM. It must be declared as public static void and accepts a String array of command line arguments. Without a main() method, the JVM will not execute the program. The main() method indicates the entry point of the program and runs the program line by line until completion.

Uploaded by

Vikas Pallewar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 10

What is Main Method In Java:-

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.

The syntax of the main() method is:

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[]: 

 It is Array of String type.


 The main() method also accepts some data from the user.
 It accepts a group of strings, which is called a string array.
 It is used to hold the command line arguments in the form of string values.

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

e.g class Student{

How to create the class:-

<Access Specifier> class <class name> {

---------//class body here

---------------------------------------------------------------------------------------------

 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.

 Object is an Instance of a class.


 Object is created through new keyword.
 Ex:- Student s = new Student();

---------------------------------------------------------------------------------

 Methods-

It is block of statements are used to perform the task called as 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.

Syntax- [Specifiers] return_type method_name (arg 1,arg 2)

Statement 1

Statement 2

--------------

Statement n

Note- Method arguments is an optional thing.

----------------------------------------------------------------------------------------
 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.

Guidelines for declaring variables

Note- Variable is declared followed by semi-colon (;)


 Data Types:-
Data types are used to represent type of data or information which will be
stored into variables called as data types.
Ex:- byte, int, short, long, boolean, char, float, double. these are the data
types.

 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.

There are different methods of object class are as follows.

 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 create an object of Scanner class, we usually pass the predefined object


System.in.

 To read numerical (int) values of a data type, the method we can use nextInt().

 To read strings, we use nextLine() or next().

-----------------------------------------------------------------------------------------------------------------------------------------
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.

There are Two Basic types of Streams:-

1) Input Streams:- An input stream is used to read data from the source it
may be a File, Memory or Console.

 FileInputStreams are the Subclass of Input Streams.

2) Output Streams:- An output stream is used to write data to the


destination it may be a File, Memory or Console.

 FileOutputStreams are the Subclass of Output Streams.


 FileWriter:- FileWriter is used to write a streams of character to a file.

 FileReader:- It reads data as a streams of character from a file.

You might also like