Mdu core java solution

JAVA UNIT-I

How garbage collector works in java ?

In java , garbage means unreferenced objects.

Garbage collection is the process of reclaiming the runtime unused  memory automatically. In other words it is way to destroy the unused objects.

For garbage collection

In c we use –free()

In c++ we use –delete()

But in java it is performed automatically .so, java provide  better memory management .

 

ADVANTAGE of garbage collection

  • Memory efficient
  • Automatic garbage collection

Finalize() method in java ?

The finalize() method is invoked each time before the object is garbage collected. This method can be used to perform cleanup processing. This method is defined in Object class as.

  1. Syntax—-­protectedvoid finalize(){  }

 

 

gc() method—-

The gc() method is used to invoke the garbage collector to perform cleanup processing. The gc() is found in System and Runtime classes.

  1. Syntax——­publicstatic void gc(){}

 

******************PROGRAM FOR GARBAGE COLLECTION********************

public class Garbage{

public void finalize(){System.out.println(“garbage collection succesfull”);}

public static void main(String []args){

Garbage g=new Garbage();

Garbage g1=new Garbage();

g=null;

g1=null;

System.gc();

}

}

 

OUTPUT

COMPILE BY –javac className.java

RUN BY-java className

garbage collection successful // output

 

 

What is operator in java ?

Operator in java is a symbol that is used to perform operations

For example -/*-+= etc.

There are many types of operators in java which are given below.

  • Unary operator
  • Arithmetic Operator
  • Shift Operator
  • Relational Operator
  • Bitwise Operator
  • Logical operator
  • Ternary operator
  • Assignment operator

 

Operator Type Category Precedence
Unary Postfix expr++ expr
Prefix ++expr —expr +expr –expr ~ !
Arithmetic Multiplicative * / %
Additive + –
Shift Shift << >> >>>
Relational Comparison < > <= >= instanceof
Equality == !=
Bitwise bitwise AND &
bitwise exclusive OR ^
bitwise inclusive OR |
Logical logical AND &&
logical OR ||
Ternary Ternary ? :
Assignment Assignment = += -= *= /= %= &= ^= |= <<= >>= >>>=

 

 

 

Example of unary operator

Class Unary{

Public static void main(String []args){

Int x=10;

System.out.println(x++);

System.out.println(++x);

System.out.println(x–);

System.out.println(–x);

 

}

}

——————— Output———

10

12

12

10

 

Class Tiled{

Public static void main(String []args){

Int a=10;

Int b=20;

Boolean c=true;

Boolean d=false;

  1. out.println(~a);
  2. out.println(~b);
  3. out.println(!c);
  4. out.println(!d);

 

}

}

 

 

What is Array in java ?

An array is a collection of similar type of elements that have a contiguous memory location.

Java Array is an object which contains element of a similar data type . it is a data structure where we store similar elements . we can store only fixed set of elements in java array.

Array in java is index based , the first element of the array is stored at the 0 index.

 

Advantages of java Array:-

  • Code optimization:-it make the code optimized, we can retrieve a sort the data efficiently.
  • Random access :–we can get any data located at an index position.

Disadvantages :-

  • Size limit :-we can store only the fixed size of elements in the array . it doesn’t grow it’s size at runtime .

Types of array in java

  • Single dimensional array
  • Multidimensional array

 

  • Single dimensional array:

Syntax to declare an array in java

dataType[] arr;

dataTypr []arr;

dataType arr[];

 

Example :-

 

class Single{

public static void main(String []args){

int a[]=new int[5];

a[0]=1;//initilization

a[1]=4;

a[2]=8;

a[3]=10;

a[4]=15;

 

for(int i=0;i<a.length;i++)

System.out.println(a[i]);

}

}

 

//output

1

4

8

10

15

  • Multidimensional array

dataType[][] arrayRefVar;

dataType [][]arrayRefVar;

dataType arrayRefVar[][];

dataType []arrayRefVar[];

 

Example

class Multi{

public static void main(String []args){

 

int arr[][]={{1,2,3},{4,5,6},{7,8,9}};

 

for(int i=0;i<3;i++){

for(int j=0;j<3;j++){

System.out.println(arr[i][j]+” “);

}

System.out.println();

}

}

 

 

//output

1              4              7

2              5              8

3              6              9

 

HISTORY OF JAVA

 

The history of Java is very interesting. Java was originally designed for interactive television, but it was too advanced technology for the digital cable television industry at the time. The history of java starts with Green Team. Java team members (also known as Green Team), initiated this project to develop a language for digital devices such as set-top boxes, televisions, etc. However, it was suited for internet programming. Later, Java technology was incorporated by Netscape.

The principles for creating Java programming were “Simple, Robust, Portable, Platform-independent, Secured, High Performance, Multithreaded, Architecture Neutral, Object-Oriented, Interpreted and Dynamic”.

Currently, Java is used in internet programming, mobile devices, games, e-business solutions, etc. There are given the significant points that describe the history of Java.

Why Java named “Oak”?

5) Why Oak? Oak is a symbol of strength and chosen as a national tree of many countries like U.S.A., France, Germany, Romania, etc.

6) In 1995, Oak was renamed as “Java” because it was already a trademark by Oak Technologies.

 

JAVA VERSION HISTORY:-

Many java versions have been released till now. The current stable release of Java is Java SE 10.

  1. JDK Alpha and Beta (1995)
  2. JDK 1.0 (23rd Jan 1996)
  3. JDK 1.1 (19th Feb 1997)
  4. J2SE 1.2 (8th Dec 1998)
  5. J2SE 1.3 (8th May 2000)
  6. J2SE 1.4 (6th Feb 2002)
  7. J2SE 5.0 (30th Sep 2004)
  8. Java SE 6 (11th Dec 2006)
  9. Java SE 7 (28th July 2011)
  10. Java SE 8 (18th March 2014)
  11. Java SE 9 (21st Sep 2017)
  12. Java SE 10 (20th March 2018)

 

FEATURES OF JAVA

The primary objective of Java programming language creation was to make it portable, simple and secure programming language. Apart from this, there are also some excellent features which play an important role in the popularity of this language. The features of Java are also known as java buzzwords.

A list of most important features of Java language is given below.

 

  1. Simple
  2. Object-Oriented
  3. Portable
  4. Platform independent
  5. Secured
  6. Robust
  7. Architecture neutral
  8. Interpreted
  9. High Performance
  10. Multithreaded
  11. Distributed
  12. Dynamic

 

DEFINE ABOUT MAIN METHOD IN JAVA

Class Test{

Public static void main(String[] args)//it is main method of java

{

//the code you want to write

}

}

Public –Access modifier(we need to make main method public because jvm call main method outside of class)

Static-Non access modifier

Void-return type of method

Main-Method name in java

String-Predefined class

[]-Array

args-Variable

 

What is System.out.println in java?

System.out.println(“it is use to print a message on console”);

system-Predefined class in java.lang package

out-Predefined instance of print writer class from java.io package

println-Method calling of print writer class

(“it is use to print a message on console”)-args value of string type

 

BASIC REQUIREMENT OF JAVA PROGRAMMIG?

JDK-JAVA DEVELOPMENT KIT

JVM-JAVA VIRTUAL MACHINE

JRE – JAVA RUN TIME ENVIROMENT

JDK-Collection of so many tools

JDK is platform dependent developed in 1993.

  • JAVA IS OF THREE TYPES

JSE-JAVA STANDARD EDITION (ALSO KNOW AS CORE JAVA )

JEE-JAVA ENTERPRISE EDITION(ALSO KNOW AS ADVANCE JAVA)

JME – JAVA MICRO EDITION

 

HOW TO SET PATH OF JDK ?

  • 1:-COPY PATH FROM JDK OF BIN FOLDER
  • 2:-RIGHT CLICK ON PC (GO TO PROPERTIES)
  • 3:-GO TO ADVANCED SYSTEM SETTING IN PROPERTIES
  • 4:-GO TO ENVIROMENT VARIABLE
  • 5:-YOU WILL SEE TWO PATH THERE

USER

SYSTEM

  • YOU NEED TO PASTE PATH IN SYSTEM VARIABLE WITH NAME PATH

BACKEND PROCESS OF JAVA PROGRAM?

AVAILABLE TOMORROW …….!

 

 

 

 

 

 

Author: Team onlinestudy.guru

1 thought on “Mdu core java solution

Leave a Reply

Your email address will not be published. Required fields are marked *