Garbage Collection and Code Security in Java.
Garbage Collection and Code Security in Java.. Here you will find that what is Garbage collection and data security in java language,. What is variable. how variable is declare. what are main types of error in java. Different data types use in java.
Garbage Collection
Many programming languages allow the dynamic allocation of memory at runtime. It is based on the syntax of the language. Once allocated is no longer required, it should deallocate by the program or running environment.
Programs that do not deallocate memory can eventually crash when there is no memory left in the system to allocate.
These programs are said to have memory-leaks. Java provides a system-level thread that tracks each memory allocation. During idle time in JVM the garbage collection thread checks for and frees any memory that can be freed.
Garbage collection happens automatically during Java program by eliminating the need to deallocate memory and avoiding memory leaks
Code Security
The JRE:
Performs three main tasks
- Loading code – performed by class loader
- Loading code – performed by class loader
- Verifying code – perform by byte code verifier
- Executing code – performed by the runtime interpreter
Class Loader
The class loader loads all classes needed for the execution of a program and adds security by separating the namespace for the class of the local file system form those imported form the network.
Byte code verifier
The JVM put the code through a byte code verifier that tests the format of the code fragments and rule – checks code fragments for illegal code.
Verification Process:-
- The class sticks to the class format of the JVM specifications.
- The class sticks to the class format of the JVM specifications.
- There are no access restrictions violations
- The code causes no operand stack underflow or overflow
- The types of parameters for all operational codes are correct
- No illegal data conversion have occurred or illegal code attached
Types of Errors in Java:-
There are three types of error in java
- Compilation Errors
- Run time Errors
- Syntax Errors
Comments in Java
These statements are ignorable by the compiler during runtime.
- // used for single line
- /* used for one or more lines */
- /** used for Para graphic comment */
Semicolon
Every JAVA statement is terminated by semicolon (;).
Blocks
Blocks are compound statements is a collection of statements bounded by opening brace “{“ and closing brace “}”.
White spaces
White spaces are allowed in order to separate the elements of the source code.
Identifier
An identifier is a name given to a variable, class or method. It can be start with letter, underscore (_) or dollar sign ($). Identifier is case sensitive because JAVA is case sensitive language. Identifier has no maximum length.
Basic JAVA Data types
Primitive data types or Simple types
These data types are provided and supported by the JAVA programming language itself.
- Logical boolean
- Textual char
- Integral byte, short, int & long
- Floating Point double & float
Logical – Boolean
- The boolean data type has two literals, true of false.
- E.g. boolean truth = true;
- Declares the variable truth as boolean type and assigns it a value of true.
Textual – char & String
- Represents a 16-bit Unicode character.
- Must have its literals enclosed in single quotes (‘ ‘).
- E.g. char ch = ‘a’; or char ch1, ch2;
- String is not a primitive data type, it is a class in JAVA.
- Has its literal enclosed in double quotes (“ “).
- E.g. String greeting = “ Good Morning ”; or String str1, str2;
Integral – byte, short, int & long:-
- Use three forms – decimal, octal, hexadecimal e.g. 2, 077, 0xBAAC respectively.
- Has a default int
- Defines long by using the letter “L” or “I”.
Integer Length Name or Type Range
8-bits Bytes -27 … 27 – 1
16-bits short -215 … 215 – 1
32-bits int -231 … 231 – 1
64-bits long -263 … 263 – 1
Floating point – float & double:-
A floating point variable can be declared using the keywords float or double.
e.g. 3.14 (A simple floating point value)
6.02E23 (A large floating point value)
2.718F (A Simple float size value)
123.4E+306D (A large double value with redundant D)
- Has a default double.
- Defines float by using “F” or “f”, double by using “D” or “d”.
Float Length Name or Type
32-bits float|
64-bits double
Integer Literals, Floating point Literals, Boolean Literals,
Character Literals & String Literals.
Variable
Variable is a container whose value can be changed during the execution of the program.
- It must define before it can used
- Initialize the variable by specifying equal sign and the value
- To declare more than one variable of the specified type use comma separated list.
e.g. int a, b, c; or int d=3, e, f=3;
byte z = 22; or double pi=3.141; or char x = ‘x’;
Constant
Constant is container whose value can not be changed during the execution of the program. The prefix const is used to declare constant e.g. const pi = 3.141;
Demo Program to add two numbers by getting input through keyboard OR console input
import java.io.*;
public class TwoDigitsSum { // start of class TwoDigitsSum
public static void main(String args[]) { // start of main()
try { //start of try block
int sum, num1, num2;
System.out.print(” Enter the 1st number = “);
BufferedReader buf = new BufferedReader(new InputStreamReader(System.in));
num1 = Integer.parseInt(buf.readLine());
System.out.print(” Enter the 2nd number = “);
BufferedReader buf1 = new BufferedReader(new InputStreamReader(System.in));
num2 = Integer.parseInt(buf1.readLine());
sum = num1 + num2;
System.out.println(“The sum = ” + sum);
} // end of try block
catch (IOException io) { // start of catch block
System.out.println(” Some Problem “);
} // end of catch block
} // end of main()
} // end of class
Here is also different java and asp.net programs like:
- How to connect java with database|Using JDBC-ODBC Connection string
- How to Create combo box in java|Complete Coding
- Java program to calculate Age from Date of birth
- How to create a Recruitment or job announcement page in asp.net | Complete front end designing and backend coding
- How to Add multiple textbox values and showing their sum
- Employee Registration form | Creation of Registration form in visual studio using c# and asp.net
- How add new webpage in a website using C#, asp.net in visual studio.
- How to create login page using asp.net and C#