Java Programs - Programming Examples | 499+
Beginners Programs :

Java Programs – Programming Examples | 499+

Java programs: Java Tutoring is one of the finest blogs where we share, all the Java tutorials, Java interview questions. Our site currently has more than 500+ beginner programs and advanced programs for both newbies and developers. If you want any new program just leave a comment or contact us. We do publish on our site asap.

All of our programs are written by expert authors who had high command on Java programming. Even our Java Tutorials are with rich in depth content so that newcomers can easily understand. You can subscribe to our blog here.

1. EXECUTION OF A JAVA PROGRAM   

Static loading:  A block of code would be loading into the RAM before it executed ( i.e after being loaded into the RAM it may or may not get executed )

Dynamic loading:  A block of code would be loaded into the RAM only when it is required to be executed.

Note:  Static loading took place in the execution of structured programming languages. EX:  c- language

Java  follows Dynamic loading

–     JVM would not convert all the statements of the class file into its executable code at a time.

–     Once the control comes out from the method, then it is deleted from the RAM and another method of exe type will be loaded as required.

–     Once the control comes out from the main ( ), the main ( ) method would also be deleted from the RAM. This is why we are not able to view the exe contents of a class file.

Functions of JVM:

  • It converts the required part if the byte code into its equivalent executable code.
  • It loads the executable code into the RAM
  • Executes this code through local operating system
  • Deletes the executable code from the RAM

We know that JVM converts the class file into its equivalent executable code. Now if a JVM is in windows environment executable code that is understood by windows environment only.

Similarly, same in the case with unix  or other or thus JVM ID platform dependent.

But the platform dependency of the JVM is not considered while saying Java is platform independent because JVM is supplied free of cost through the internet by the sun microsystems. (hotel – tiffin – water: example ).

Simple Hello Word Program

Out of 500+ Java Programs: Hello world is a first ever program which we published on our site. Of course, Every Java programmer or C programmer will start with a ” Hello World Program ” Here it is. Followed by rest of the programs on different Topics.

Simple Formula Based Java Programs

Platform independency :

Compiled code of a program should be executed in any operating system, irrespective of the as in OS in which that code had been generated. This concept is known as platform independency.

à The birth of oops concept took place with encapsulation.

à Any program contains two parts.

Date part and Logic part

Out of data and logics the highest priority us given to data.

But in structured programming language the data insecurity is high.

Thus in a process if securing data in structured prog. lang. the concept of encapsulation came into existence.

Note :  In structured programming lang programs, the global variable play a vital role.

But because of these global variables, there is data insecurity in the structured programming lang programs. i.e functions that are not related to some variables will have access to those variables and thus data may get corrupted. In this way data is unsecured.

“This is what people say in general about data insecurity. But this is not the actual reason. The actual concept is as follows”.

Let us assume that, we have a ‘C’ program with hundred functions. Assume that it is a project. Now if any upgradation is required, then the client i.e the user of this program (s/w) comes to the it company and asks the programmers to update it according to his requirement. Now we should note that, it is not guaranteed that the programmers who developed this program will still be working with that company. Hence this project falls into the hands of new programmers.

Automatically it takes a lot of time to study. The project itself before upgrading it. It may not be surprising that the time required for writing the code to upgrade the project may be very less when compared to the time required for studying the project.

Thus maintenance becomes a problem.

If the new programmer adds a new function to the exiting code in the way of upgrading it, there is no guarantee that it will not affect the existing functions in the code. This is because of global variables. In this way data insecurity is created.

To overcome this problem, programmers developed the concept of encapsulation.

For example let us have a struc.prog.lang. program with ten global variables and twenty functions.

It is sure that all the twenty functions will not use all the global variables.

Three of the global variables may be used only by two functions. But in a structured prog. Lang like ‘C’ it is not possible to restrict  the access of global variables by some limited no of functions.

Every function will have access to all the global variables.

To avoid this problem, programmers have designed a way such that the variables and the functions which are  associated with or operate on those variable are enclosed in a block and that bock is called a class and that class and that class is given a name, Just as a function is given a name.

Now the variables inside the block cannot be called as local variable because they cannot be called as global variables because they are confined to a block and not global.

Hence these variables are known as instance variables

Ex :

struct. Prog. Lang. program

# include < stdio.h>

int i,j,k,l,m,n;

fun 1 ( )

{

—–

——-

——–

}

Fun 2

{

——

——–

——-

}

Fun 10 ( )

{

——

——

——

}

Main ( )

{

——

——

——

}

_______________________________________________________________

Ex :

Oop. Lang program

Class Abc

Int  i,j,k

Fun 1 ( )

{

—–

——-

——-

}

Class Xyz

{

Int  l,m,n;

Fun 3 ( )

{

—–

—–

——

}

Fun 4 ( )

{

—–

—–

—–

}

There fore a class is nothing but grouping data along with its functionalities.

Note 1: encapsulation it’s the concept of binding data along with its corresponding functionalities.

Encapsulations came into existence in order to provide security for the data present inside the program.

Note 2 : Any object oriental programming language file looks like a group of classes. Every thing is encapsulated. Nothing is outside the class.

à Encapsulation is the back bone of oop languages.

à JAVA supports all the oop concepts ( i.e. encapsulation, polymorphism, inheritance) and havece it is known as object oriented programming language.

à  C++ breaks the concept of encapsulation, because the main ( ) method in a  C++ program is declared outside a class. Hence it is not a pure oop language, in fact , it is a poor oop language