- easy4tuts.blogspot.com

Hot Contents To Know

Post Top Ad

Your Ad Spot


 

Q What is JAVA environment?

The environment (tools) used for running a java application is called java environment. The JAVA environments include following things(Tools).

(1) JDK (Java Development Kit) : JDK provide development environments for software developers. It includes development tools such as the Java compiler, Jar, Javadoc, and a debugger.

(2) JRE(Java Runtime Environment) : It contains the parts of the Java libraries which are required to run Java programs. It help the end users to run the JAVA program. JRE is the  subset of Java Development Kit (JDK).
(3)JVM (Java Virtual Machine): JVM provides run time environments in which java byte code can be executed. Many hardware and software platforms are supported by JVMs.

 

Q What is JRE?

Java Run-time Environment (JRE) is the part of the Java Development Kit (JDK). It is a freely available software. It contains Java Class Library, specific tools, and  JVM. It provides common environment to run java programs. The Java source code gets compiled and converted to Java byte code. If we wish to run this byte code on any platform, we require JRE. The JRE loads classes, verify access to memory, and retrieves the system resources.

Q What is Java Virtual Machine (JVM)?

JVM is a part of the Java Run Environment (JRE). It provides a runtime environment to execute the Java Code or applications. It converts Java byte code into machine language. In other programming languages, the compiler produces machine code for a particular system. However, the Java compiler produces code for a Virtual Machine known as Java Virtual Machine.Here are the important reasons of using JVM:

  • JVM provides a platform-independent way of executing Java source code.
  • It has numerous libraries, tools, and frameworks.
  • Once we run a Java program, we can run on any platform and save lots of time.
  • JVM comes with JIT (Just-in-Time) compiler that converts Java source code into low-level machine language. Hence, it runs faster than a regular application.

Q What is the Structure of Java Program

Java is an object-oriented programming, platform-independent, and secure  programming language that makes it popular. Using the Java programming language, we can develop a wide variety of applications.

Java program contains the following elements:

Documentation Section

Package Declaration

Import Statements

Interface Section

Class Definition

Class Variables and Variables

Main Method Class

Methods and Behaviors

Documentation Section

The documentation section is an important section but optional for a Java program. It includes basic information about a Java program. The information includes the author's name, date of creation, version, program name, company name, and description of the program. To write the statements in the documentation section, we use comments. The comments may be single-line, multi-line, and documentation comments.

Single-line Comment: It starts with a pair of forwarding slash (//). For example:

//First Java Program  

Multi-line Comment: It starts with a /* and ends with */. We write between these two symbols. For example:

/*It is an example of 

multiline comment*/  

Documentation Comment: It starts with the delimiter (/**) and ends with */. For example:

/**It is an example of documentation comment*/  

Package Declaration:- The package declaration is optional. It is placed just after the documentation section. In this section, we declare the package name in which the class is placed. Note that there can be only one package statement in a Java program. It must be defined before any class and interface declaration. It is necessary because a Java class can be placed in different packages and directories based on the module they are used. For all these classes package belongs to a single parent directory. We use the keyword package to declare the package name. For example:
package javatpoint; //where javatpoint is the package name  

package com.javatpoint; //where com is the root directory and javatpoint is the subdirectory  

Import Statements:- The package contains the many predefined classes and interfaces. If we want to use any class of a particular package, we need to import that class. The import statement represents the class stored in the other package. We use the import keyword to import the class. It is written before the class declaration and after the package statement. We use the import statement in two ways, either import a specific class or import all classes of a particular package. In a Java program, we can use multiple import statements. For example:

import java.util.Scanner; //it imports the Scanner class only  

import java.util.*; //it imports all the class of the java.util package  

Interface Section:-It is an optional section. We can create an interface in this section if required. We use the interface keyword to create an interface. An interface is a slightly different from the class. It contains only constants and method declarations. Another difference is that it cannot be instantiated. We can use interface in classes by using the implements keyword. An interface can also be used with other interfaces by using the extends keyword. For example:

interface car  

{  

void start();  

void stop();  

}  

Class Definition:-In this section, we define the class. It is vital part of a Java program. Without the class, we cannot create any Java program. A Java program may conation more than one class definition. We use the class keyword to define the class. The class is a blueprint of a Java program. It contains information about user-defined methods, variables, and constants. Every Java program has at least one class that contains the main() method. For example:

class Student //class definition  

{  

}  

Class Variables and Constants

In a Java program, the variables and constants are defined just after the class definition. The variables and constants store values of the parameters. It is used during the execution of the program. We can also decide and define the scope of variables by using the modifiers. It defines the life of the variables. For example:

class Student //class definition  

{  

String sname;  //variable  

int id;   

double percentage;   

}  

Main Method Class :- In this section, we define the main() method. It is essential for all Java programs. Because the execution of all Java programs starts from the main() method. In other words, it is an entry point of the class. It must be inside the class. Inside the main method, we create objects and call the methods. We use the following statement to define the main() method:

public static void main(String args[])  

{  

}  

For example:

public class Student //class definition  

{  

public static void main(String args[])  

{  

//statements  

}  

}  

Java Tokens:-Java program is basically a collection of classes. But it have a basic bulding blocks, these basic buildings blocks in Java language which are constructed together to write a java program. This basic bulding blocks are called Token.

Each and every smallest individual units in a Java program are known as tokens.

Simply we can say that java program is also collection of tokens, comments and whitespaces.

In Java Programming tokens are of six types. They are,

No

Token Type

Example 1

Example 2

1

Keyword

int

For

2

Constants

height

Sum

3

Identifier

-443

43

4

String

"Hello"

"atnyla"

5

Special Symbol

*

@

6

Operators

*

++

 

Token

Meaning

Keyword

A variable is a meaningful name of data storage location in computer memory. When using a variable you refer to memory address of computer

Constant

Constants are expressions with a fixed value

Identifier

The term identifier is usually used for variable names

String

Sequence of characters

Special Symbol

Symbols other than the Alphabets and Digits and white-spaces

Operators

A symbol that represents a specific mathematical or non-mathematical action

 

Keyword:-Keywords are an special part of a language definition. Keywords are predefined, reserved words used in programming that have special meanings to the compiler. The keywords cannot be used as variable names. Keywords are part of the syntax and they cannot be used as an identifier. Java language has reserved 50 words as keywords. All the Keywords are written in lower-case letters. Since java is case-sensitive.

Here is a list of keywords in the Java programming language.

abstract

continue

for

new

switch

assert***

default

goto*

package

synchronized

boolean

do

if

private

this

break

double

implements

protected

throw

byte

else

import

public

throws

case

enum****

instanceof

return

transient

catch

extends

int

short

try

char

final

interface

static

void

class

finally

long

strictfp**

volatile

 

Identifiers:-Identifiers are the names of variables, methods, classes, packages and interfaces

Identifier must follow some rules. Here are the rules:

All identifiers must start with either a letter( a to z or A to Z ) or currency character($) or an underscore.

They must not begin with a digit

After the first character, an identifier can have any combination of characters.

A Java keywords cannot be used as an identifier.

Identifiers in Java are case sensitive, foo and Foo are two different identifiers.

They can be any length

Each variable has a name by which it is identified in the program. There is no limit to the length of a Java variable name.

Types of Java Statements:-Java supports three different types of statements:

Expression statements change values of variables, call methods, and create objects.

Declaration statements declare variables.

Control-flow statements determine the order that statements are executed.

No comments:

Post a Comment

Post Top Ad

Your Ad Spot