Steps to Design first java application

Step-1:- Select an Editior.

Step-2:-Write the application.

Step-3:-Save the application.

Step-4:-Compilation Process.

Step-5:-Execution Process.

Step1:- Select an Editor

Editor is a tool or software it will provide very good environment to develop java application. Ex :- Notepad, Notepad++,edit Plus…..etc

IDE:- ( Integrated development Environment )

IDE is providing very good environment to develop the application.

Ex:- Eclipse,MyEclipse,Netbeans,JDeveloper….etc

IDE is a real-time standard but don’t use IDE to develop core java applications because 75% work is done by IDE & remaining 25 % work is down by developer.

75% work of IDE is:-

  1. Automatic compilation.
  1. Automatic package import.
  1. It shows all the predefined methods of classes.
  1. Automatically generate try catch blocks and throws (Exception handling)
  1. It is showing the information about how to fix the bug………………………etc

Note :- Do the practical’s of core java only by using Edit Plus software.

Step 2:-  Write a program.

Example application:-

import java.lang.System;

import java.lang.String;

class Test             //class declaration

{//class starts

public static void main(String[] args)      //program execution starting point

{//main starts

System.out.println(“hi Atul”); //printing statement

}//main ends

}; //class ends class A

{

}

class B

{

}

In above example String & System classes are present predefined java.lang package hence must import that package by using import statement.

There are two approaches to import the classes in java, 1) Import all class of particular package.

a.    Import java.lang.*;    //it is importing all classes of java.lang package.

  1. Import required classes
    1. Import java.lang.System;
    1. Import java.lang.String;

In above two approaches second approach is best approach because we are importing application required classes.

Note: The source file is allows declaring multiple java classes.

Step3:- save the application.

  1. After writing the application must save the application by using (.java) extension.
  • While saving the application must fallow two rules:

If the source file contains public class then public class name & Source filename must be same (publicClassName.java). Otherwise compiler generate error message.

if the source file does not contain public class then save the source file with any name (anyName.java) like A.java , Ratan.java, Anu.java …….etc .

Note: – The source file allowed only one public class, if we are trying to declare multiple public classes then compiler generate error message.

Step-4:- Compilation process.

Compile the java application by using javac command.

Syntax:-               Javac   filename

Javac Test.java

Process of moving application saving location:-

C:\Users\hp> initial cursor location

C:\Users\hp>d: move to local disk D

D:\>cd atul changing directory to ratan

D:\atul>javac Sravya.java compilation process

Whenever we are performing compilation the compiler will check the syntax errors.

If the application contains syntax errors then compiler will generate error message in the form of compilation error.

If the application does not contains syntax errors then compiler will generate .class files.(conversion of .java to .class)

Note: – in java .class files generated by compiler at compilation time and .class file generation based on number of classes present in source file.

If the source file contains 100 classes after compilation compiler generates 100 .class files

The compiler generate .class file and .class file contains byte code instructions it is intermediate code.

Process of compiling multiple files:-
D:  
|–>atul
 |–>Sravya.java
 |–>A.java
 |–>B.java
 |–>C.java
javacA.javaone file is compiled(A.java)
javacB.java C.javatwo files are compiled
javac *.javaall files are compiled

Step-5:- Execution process.

Run /execute the java application by using java command.

Syntax:-               Java  class-name

Java  Test

Whenever you are executing particular class file then JVM perform fallowing actions.

JVM wills loads corresponding .class file byte code into memory.

After loading .class file JVM calls main method to start the execution process.

In above two cases if the class file or main method is not available then at runtime JVM will generate error message.

If the main method is not available: “Main method not found in class A, please define the main method”.If the .class is not available : “Could not find main class”.

Executing all generated .class files based on example given in second step:-

Test class—>class is loaded & main is present
A class—>class is loaded but main is not present
B class—>class is loaded but main is not present
XXX class—>XXX class is not present

D:\atul>java Test

Hi Atul

D:\atul>java A

Error: Main method not found in class A, please define the main method as:

D:\atul>java B

Error: Main method not found in class B, please define the main method as:

D:\atul>java XXXError: Could not find or load main class XXX

1.compiler is translator it is translating .java it is translating .class file to machine code.file to .class where as JVM is also a translator

2.Compiler understandable file format is .java file but JVM understandable file format is .class file.

3.It is possible to compile multiple files at a time but it is possible to execute only one .class file at a time.

4.The .java file contains high level language (English) but .class file contains byte code instructions.

5.java is a platform independent language but JVM is platform dependent.

Conclusion 1:- Java contains 14 predefined packages but the default package in java is java.lang

class Test

{

public static void main(String[] args)

{

System.out.println(“hi ratan”);

}

}

Conclusion -2:-

The class contains main method is called Main class and java allows to declare multiple main

class in a single source file.

Conclusion -3:The source file is allows to declare only one public class, if you are declaring morethan

one public class compiler generate error message.

conclusion-4 The below example compiled & executed but it is not recammanded because the class

name starting with lower case letters.


Published by Atul maurya

i am student of computer science & engineering .i want to become a java developer. my hobby is to learn programming language in easy way.

Leave a comment

Design a site like this with WordPress.com
Get started