Thursday, October 29, 2015

Basics & Working of GUI Environment in Programming: Introduction to JAVA

GUI, Graphical User Interface, refers to the windows, buttons, dialog, menus and everything visual in a modern applications of JAVA. A GUI application involves much more than a screen made up of GUI components. It also involves properties of its components, actions events etc. in this article, we shall learn about these basics of a GUI.

Working of a GUI

A GUI Application consists of many GUI components such as windows, dialog, menus and other controls etc. while using a GUI Application. When you perform an action, an event is generated. In event-driven programming, that most GUI follow, the program respond to the events. Let us learn about how most GUI's function. And as you can guess that this depends upon how the constituent windows, events etc. function.

Working of windows, Events and Messages

A window can be bought off as simple as rectangular region with its own boundaries. You are already aware of several different types of windows: a document window or a dialog box etc. While these are the most common examples, there are actually many other types of windows. A common button is also a window. Icons, text boxes, option buttons and menu bars are all windows.

The windows operating system manages all of these many windows by assigning each one a unique id number (called window handle). The system continually monitors each of these windows for signs of activity or in other words events. Events can occur through user actions such as a mouse click or press, through programmatic control, or even result of another window’s action.

An event refers to occurrence of an activity.
  • Each time an event occurs, it causes a message to be sent to the operating system.
  • The system processes the message and broadcast it to other windows.
  • Each window can then take the appropriate action based on its own instructions for dealing with that particular message (for example, repenting itself when it has become covered by another window).

A message is the information/request sent to the application.

As you might imagine dealing with all of the possible combinations of windows, event and message could be complex. Fortunately, Java insulate you from having to deal with all of the low-level message handling. Many of the message are handled automatically by Java; others are exposed as Listener method for your convenience. This allows you to quickly create powerful applications without having to deal with unnecessary details.

Saturday, October 24, 2015

NetBeans IDE Components Overview: Java Programming

NetBeans IDE provides different views of your code as well as other windows. When programming in java, programmer feels amazing working experience with windows like palette, properties or output window.

Earlier article was about NetBeans Features, in this article I will discuss about NetBeans IDE with their mostly used components. Start NetBeans IDE and create a desktop application from File-->New Project--> Java Desktop Application. It will show a window like below image:

NetBeans IDE Components Overview: Java Programming

The image shown some important components like properties window, palette with tools, inspector window, output window and etc. This article have a brief description about these components.

Title Bar

The tittle bar displays the tittle of the application. By default, NetBeans will give names as DesktopApplication1, DesktopApplication2 etc. to your project. Notice in following figure, it has given title DesktopApplication1 to your application.

Menu Bar and Pull-down Menu

You are familiar with menu bars as you have worked with MS-Windows operating system. A menu bar is displayed directly below the title bar and includes a lot of options. Each option on the menu bar has a drop down list of item (known as Pull-down menus) that helps you to perform various tasks.

Toolbar

A tool bar is a bar that displays icons for commonly used tasks. The standard toolbar of NetBeans IDE displays icons for the most frequency used commands in NetBeans.

GUI Builder

Also called Design Area or Design Space. The design Area is where you will visually construct your GUI. It is the primary workspace within which GUI design takes place in the IDE. The GUI Builder enables you to layout forms by placing components where you want them and by providing visual feedback in the form of guidelines.

It has two views: Source View and Design View. Design view is the default, as shown above. The Source View opens the code editor for programmer to be add/edit the code for application. You can toggle between views at any time by clicking their respective tabs.

The Palette

The palette contains all of the components needed to create a GUI Application. Palette consist of window controls and frames.

Frames
A frame is a window that typically has decorations such as a border, title, and buttons for closing and iconifying itself. A GUI application typically uses at least one frame. Frames are used to display things like labels, text fields, buttons and other controls.

Controls
Controls are component objects such as text fields, labels, and list boxes etc. that are drawn on frame to get data input or to display output.

Inspector Window

This window displays a hierarchy of all components contained in the currently opened from. Displayed items include visual components and containers, such as buttons, labels, menus and panels, as well as non-visual components such as timers and data source.

Properties window

This window displays the editable settings for the currently selected component. The figure shows the Property Editor for JFrame object.

Code Editor Window

The code editor window is where you write Java code for your application. By code we mean language statements, constants and declarations. The Code Editor window serves as an editor for entering application code. A separate code editor window is created for each top level frame that you create in your application. Using the Code Editor window, you can quickly view and edit any codes in your application.

To open the Code window Double-click the control for which you choose to write code. Or from the GUI Builder window, click at Source tab. You may also press Ctrl + Alt + Page Up/ Page Down.

NetBeans Features in Application Development: Introduction to JAVA

When programming in java, software developer have many in-built features provided by this NetBeans Ide. This Ide provides first-class comprehensive support for the newest java technologies and providing support for JDK 8 previews, JDK 7 including its related HTML5 enhancements.

NetBeans IDE is a free, open-source, cross-platform IDE (Integrated Development environment) with built-in support for Java Programming Language. In fact, NetBeans runs anywhere there’s a JVM (Java Virtual Machine). This ide is a RAD tool, used to develop java softwares. 

Here're some features for application development NetBeans provide:

  • Drag and drop GUI creation
  • Excellent editing (advance source code editor)
  • Web-services
  • Excellent debugging
  • Wizards, code generation and management tools and many more 

Before you start developing application, make sure that Java SDK along with NetBeans IDE is installed on your machines. You can download latest version of NetBeans IDE along with Java SDK (Software Development Kit) from the NetBeans page in java sun pages.

After downloading, install the software by using some simple steps. The downloaded installer will install both Java SDK and NetBeans either through Start →All Programs→NetBeans→NetBeans IDE or by clicking at its shortcut on the desktop. After installation launch the NetBeans IDE, it will show a splash screen containing some information about netbeans, version and etc. shown in the image.


NetBeans Features in Application Development: Introduction to JAVA, splash screen

Splash screen is shown when the ide loads basic information to run. As in the image, the red color progress bar is going on with a message Done loading modules. The NetBeans IDE has many features. But you need not learn every feature of it. To get yourself started, you need to know about the features listed below. Other features, you can leans according to the need.


NetBeans Features in Application Development: Introduction to JAVA, IDE

There are various components of this IDE, which will be discuss in later article.

Rapid Application Development Tools used in JAVA Programming: Introduction to JAVA

To write programs in java, programmer have to know about RAD tools, which is essential topic in the java programming. RAD tools are also helpful in development of large application with a little bit support of JVM.

Rapid development of an application is possible through Rapid Application Development (RAD) tools. The RAD tools are the tools that enable one to create applications in shorter time as compared to conventional language. A range of application can be created with RAD tools. Through RAD tools, you can not only develop a small utility program, but also a large enterprise system or large distributed applications.

In fact, NetBeans IDE offers a RAD style of developing applications for Windows programmers. With NetBeans IDE, you can develop applications just by creating frames, dragging and dropping controls on to frames, setting properties for various things, adding some application-specific code to handle events and that is it? But this simple graphical, form-based approach can create wonderful applications.

Rapid Application Development (RAD) describes a method of developing software through the use of pre-programmed tools or wizards. The pre-programed tools or controls are simply dropped on a screen to visually design the interface of application.    

While developing large application, the RAD tools are used to create prototypes of a large application. A prototype is the first model that is made of something. The prototype is used as a basis for later improved model. These prototype provide the look and feel of application being developed.

There are many more RAD tools in existence that may be of desktop tools, database rad tools, cloud-based tools, cross-platform and etc. Here’re some desktop RAD tools:

  • Accelerator for .NET: Provides end-to-end RAD generation and other productivity frameworks for .NET, including support for MVVM and WCF.
  • Dolphin Smalltalk: is a small talk development environment for windows with advanced RAD features.
  • Microsoft Visual Basic: developed by Microsoft, provide advanced features to developer.
  • Softwell Maker: is a desktop IDE with cross-platform deployment component allowing publish application into almost JAVA enable system.

All other RAD tools are listed on Wikipedia and can be readable from different types of RAD Tools.

How to work with Prefix version of increment/decrement operators in JAVA

When increment or decrement operators works in prefix manner then they follow the change-then-use rule. Java performs these type of operations before using the value of the operand.

When an increment operator precedes its operand (i.e. in its prefix), Java performs the increment or decrement operation before using the value of the operand. For example, the expression

sum = sum + (++count);
will take place in the following fashion. (Assuming the initial values of sum and count are 0 and 10 respectively). The expression will execute in the following sequence:
0=0+10;
-=0+11;
11=0+11

So from this sequence the sum will have its value in the third execution.

The expression
                      P = P * --N;
Will take place in the following fashion. (Assuming the initial values of P and N are 4 and 8 respectively). The expression will execute in the following sequence:

-=4*8;
-=4*7;
28=4*7;
The prefix increment or decrement operators follow Change-then-use rule i.e. they first change (increment or decrement) the value of their operand, then use the new value in evaluating the expression.

How to work with Postfix version of increment/decrement operators in JAVA

When increment or decrement operators works in prefix manner then they follow the Use-then-change rule. Java, first use the value of operand and then change the operand’s value.

When an increment or decrement operator follow its operand (i.e, in its postfix form), Java first uses the value of the operand in evaluating the expression before increment or decrementing the operand’s value. For example, the expression
sum = sum + count++ ;
will take place in the following fashion. (Assuming the initial values of the sum and count are 0 and 10 respectively). The expression then execute in the following sequence:
-=0+10;
10=0+10;
10=0+11;

Check out another expression:
P = P * N--;
Will take place in the following fashion. (Assuming the initial values of P and N are 4 and 8 respectively). The expression then execute in the following sequence:
-=4*8;
32=4*8;
32=4+7;

The postfix or decrement operators follow Use-then-change rule i.e., they first use the value of their operand in evaluating the expression and then change (increment or decrement) the operand’s value.
Prefix version of Operator

Compilation used to Generate Byte Code in Programming: Introduction to JAVA

Compilation Process

The program or code in java written by the programmer is usually called the Source Code in programming. This source code needs to be converted in to language code, which a computer can easily understand. The process of converting a source code in to machine code, is called compilation. The converted machine code depends a lot on the platform it is executed upon. That means for different platforms different machine code is produced. This resultant machine code is called native executable code.

Compilation used to Generate Byte Code in Programming: Introduction to JAVA

Instead of using a compiler, which translates the program all at once, you can use an interpreter, which translate it instruction-by- instruction, as necessary. In order to execute a program, the interpreter repeatedly reads one instruction from the program, decide what is necessary to carry out that instruction, and then performs the appropriate machine language commands to do so.

Java Compilation

Contrary to ordinary compilers, the Java compiler does not produce native executable code for a particular machine. Instead it produce a special format called byte code.
Java Byte Code is a machine instruction for a Java processor chip called Java virtual machine. The Byte code is independent of the computer system it has run upon.
The Java Byte Code looks a lot like machine language, but unlike machine language Java byte code is exactly the same on every platform. This byte code means the same thing on a Solaris workstation as it does on a Macintosh Power Book or on a Windows Vista running on an Intel Pentium V.

Compilation used to Generate Byte Code in Programming: Introduction to JAVA

However, the Java programs that have been complained in to byte code still need an interpreter to execute then on any given platform. The interpreter reads the byte code and translates it into the native language of the host machine on the fly.

Since the byte code is completely platforms independent, only the interpreter and a few native libraries need to be ported to get Java to run on a new computer or operating system.

Java Virtual Machine with Java Platform


About Java, History and Byte Code in Programming: Introduction to JAVA

Introduction 

Java is a popular third-generation language of programming, which can be used to perform any of the thousands of things that a computer software can do. Java has become the language of choice for internet and internet applications. Java plays an important role for the proper functioning of many software-based devices attached to a network.

In this article you’ll be learn about java language, how it works with the code and generate its byte code, history of the language.

About Java   

Java is both a programming language and a platform. Like any other programming language, you can use Java to write or create various types of computer applications. The word platform is generally used to refer some combination of hardware and software e.g. operating system, Windows Vista on Intel Pentium V or windows NT on DEC Alphas or System 8.5 power macs etc. 

The Java platform is a new software platform different from many other platforms; it is designed to deliver and run highly interactive, dynamic and secure applications on networked computer systems.

History

Originally, Java started as an elite project (code named Green) to find a way of allowing different electronic devices such as TV-Top boxes and controllers to use a common language. This language for electronic device was originally named Oak but failed to find a niche despite its optional. In the following lines, the history of Java can be found out on the Java timeline: 
  • 1991: James Gosling Develops Oak (later named Java), language for programming intelligent consumer electronic devices.
  • 1995: Java formally announced incorporated in to Netscape web browser.
  • 1996: Java Development Kit (jdk) 1.0 ships. Java Beans component architecture Corel Office for Java Preview. Sun announces Java station Network computer. Sun announces 100% pure java initiative.
  • 1998: Sun introduces Community Source open licensing. Sun produce JDK 1.2 for Linux.
  • 2006: The Net Beans IDE 5.0 is released. Sun open-sourced Java EE components as the Glassfish Project to java.net. Java SE and ME initial components are released as open source.

Byte code

Do you know the computer programs are very closely tied to the specific hardware and operating system they run on? For example, a Windows program will not be able to run on a computer that only runs DOS; a Mac application can’t run on a UNIX workstation, and so on. To take with diversity of platforms, major commercial application like MS-Word or Netscape Navigator have to be written almost independently for all platforms they run on.

But for the application development with Java, this is not the case. For, these applications are platform-independent i.e. they are not affected with changing platforms. Java solves the problem of platform-independence by using byte code. In order to understand the byte code, you must be clear about compilation process first.

Wednesday, October 21, 2015

Programming Language Constructs used in Java

Statement may be executed sequentially, selectively or iteratively. Every programming language provides constructs to support sequence, selection or iteration. Every programmer should have knowledge of these constructs for using selection statement.

Sequence

Sequence construct means the statements are being executed sequentially. This represents the default flow of control as shown in below image.


Every Java function execution begins with its first statement then each statement in turn is executed (sequence construct). When the final statement of the function is executed, the function is done. This programming construct specifies the normal flow of control in a program and is the simplest one.

Selection

The selection construct means the execution of statement depending upon a condition-test. If a condition evaluates to true, a course-of-action (a set of statements) is followed otherwise another course-of-action (a different set of statements) if followed. Selection construct is also called decision construct because it helps in making decision about which set of statements is to be executed.

Iteration

Iteration construct means repetition of a set of statements depending upon a condition-test. Till the time a condition is true a set of statements are repeated again and again. As soon as the condition becomes false the repletion stops. The iteration construct is also called looping construct.

The set of statements that are repeated again and again is called the body of the loop. The condition on which the execution or exit of the loop depends is called the exit condition or test condition.

Programming Language Constructs used in Java

Statement may be executed sequentially, selectively or iteratively. Every programming language provides constructs to support sequence, selection or iteration. Every programmer should have knowledge of these constructs for using selection statement.

Sequence

Sequence construct means the statements are being executed sequentially. This represents the default flow of control as shown in below image.


Every Java function execution begins with its first statement then each statement in turn is executed (sequence construct). When the final statement of the function is executed, the function is done. This programming construct specifies the normal flow of control in a program and is the simplest one.

Selection

The selection construct means the execution of statement depending upon a condition-test. If a condition evaluates to true, a course-of-action (a set of statements) is followed otherwise another course-of-action (a different set of statements) if followed. Selection construct is also called decision construct because it helps in making decision about which set of statements is to be executed.


Iteration

Iteration construct means repetition of a set of statements depending upon a condition-test. Till the time a condition is true a set of statements are repeated again and again. As soon as the condition becomes false the repletion stops. The iteration construct is also called looping construct.


The set of statements that are repeated again and again is called the body of the loop. The condition on which the execution or exit of the loop depends is called the exit condition or test condition.
So the conclusion is every programming language must provide all these constructs as the sequential program execution in inadequate to the problems we must solve. Java also provides statements that support these constructs.

If Selection Statements used in JAVA

The selection statements allow to choose the set of instructions for execution depending upon an expression’s truth value. Java provides two types of selection statements: if and switch. In this article we will learn about if selection statement and then next one.

In addition, in certain circumstances ?= operator can be used as an alternative to if statement. The selection statements are also called conditional statements or decision statements.

If Statement

An if statement tests a particular condition ; if the condition evaluates to true, a course of action is followed i.e., a statement or set of statements is executed. Otherwise (if the condition evaluates to false), the course of action is ignored. The syntax of the if statement is as shown below:

If (expression)
statement;

where a statement may consist of a single statement, a compound statement, or nothing (in case of empty statement). The expression must be enclosed in parentheses. If the expression evaluates to true i.e. a nonzero value, the statement is executed, otherwise ignored. Look out following code fragment:

if (ch == ‘’)
spaces++;

This statement will checks whether the character variable ch stores a space or not; if it does, the number of spaces are incremented by one. Next example will clarify some more conditions with if statement:

if (ch == ‘’)
label.setText(“It is a space character”);
if (ch >= ‘0’ && ch <= ‘9’)
label.setText(“It is a digit”);

This will compare a character variable ch. If it stores a space, it flashes a message and if it will be a digit, it flashes another message as specified in above.

Tuesday, October 20, 2015

Selection statement used in java part-2

In earlier article we have discussed about if statement that allow you to execute a set of statements if a condition or expression evaluates to true. If there is another course of action to be followed if the expression evaluates to false.

To resolve this, there are another form of if that allows for this kind of either-or condition by providing an else clause. Following is the syntax of if-else statement:

If (expression)
Statement 1;
Else
Statement 2;

According to above code fragment, if the expression evaluates to true statement-1 is executed, otherwise statement-2 is executed. These statements can be a single , compound or may be a null statement.

Nested If

A nested if is an if that has another if in its if’s body or in its else’s body. One of the example among nested if’s is in following form:

If (expression) {
If (expression)
Statement 1;
[Else
Statement 2;]
}
Else
Statement 2;

In if statement, either there can be if statement in its body of if or in its body of else or in both.
The part in [] is optional and inner if’s can themselves be nested ifs, but the inner if must terminate before an outer if.

If-Else-If ladder

A common programming construct in JAVA is the if-else-if ladder, which is often also called the if-else-if staircase because of its appearance. Following is the syntax:

If (condition ) statement 1;
Else
If (condition ) statement 2;
Else
If (condition ) statement 3;
Else statement 4;
………….

The expressions are evaluated from the top downward. As soon as an expression evaluates to true, the statement associated with it is executed and the rest of the ladder is bypassed. If none of the expressions are true, the final else gets executed. If the final else is missing, no action takes place if all other conditions are false.

Although it is technically correct to have indentation in the if-else-if ladder as shown above, however, it generally leads to overly deep indentation.

Ternary operator alternate to IF in JAVA

Java has an operator that can be used as an alternative to if statement. You are familiar with this operator, the conditional operator ?: This operator can be used to replace if-else statements of the general forms:

if (expression)
Statement 1;
else
Statement 2;

The above forms of if can be alternatively written using conditional operator as follows:

expression? statement 1 : statement 2;

It works in the same way as the above given form of if does i.e., expression is evaluated, if it is true, statement 1 gets executed (i.e. its value becomes the value of entire expression) otherwise statement 2 gets executed (i.e. its value now becomes the value of the entire expression). Look out following example:

int c;
if (a > b)
c = a;
else
c = b;

Can be alternatively written as:

int c = a > b ? a : b;

The whole code fragment converts into a single line.

Comparing if and ?:

  • Compared to if-else sequence, ?: offers more concise, clean and compact code, but it is less obvious as compared to if.
  • Another difference is that the conditional operator ?: produces an expression, and hence a single value can be assigned or incorporated into a larger expression whereas, if is more flexible. The if statement can have multiple statements, multiple assignments and expressions (in form of a compound statement) in its body.
  • When ?: operator is used in its nested form, it becomes complex and difficult to understand. This form of ?: is generally used to conceal the purpose of code.
In the next article we will learn about how to use switch statement in JAVA with an example.

Switch Statement used in JAVA

Java provides a multiple-branch selection statement known as switch. This selection statement successively tests the value of an expression against a list of integer or character constants. When a match is found, the statements associated with that constants are executed.

The syntax of switch statement is as follows:

switch (expression)
{
        case constant1 : statement sequence 1;
break;
        case constant2 : statement sequence 1;
break;
        case constant3 : statement sequence 1;
break;
        …….
        case constantn-1 : statement sequence 1;
break;
        [default : statement sequence n];
}

The expression is evaluated and its values are matched against the values of the constants specified in the case statements. When a match is found, the statement sequence associated with that case is executed until the break statement or the end of switch statement is reached. The default statement gets executed when no match is found. If the control flows to the next case below the matching case, in the absence of break, this is called fall through. The default statement is optional and, if it is missing, no action takes place if all matches fail.

If you do not give break after each case, then java will start executing the statements from matching, case and keep on executing statements for following cases as well until either a break statement is found or switch statement’s end is encounted. If the control flows to the next case below the matching case, in the absence of break, this is called fall through.

A case statement cannot exist by itself, outside of a switch. The break statement, used under switch, is one of java jump statements. (You’ll learn more about it later in the chapter.) When a break statement is encountered in a switch statement, program execution jumps to the line of code following the switch statement i.e. outside the body of switch statement.

Following example will show a switch statement:

switch (dow)
{
        case 1 : ans = “Sunday”;
         break;
        case 2 : ans = “Monday”;
        break;
        case 3 : ans = “Tuesday”;
        break;
        case 4 : ans = “Wednesday”;
        break;
        case 5 : ans = “Thursday”;
        break;
        case 6 : ans = “Friday”;
        break;
        case 7 : ans = “Saturday”;
        break;
        default : ans = “Wrong day number”;
}

Comparison between Switch and If-Else: JAVA

The switch and if-else both are selection statements and they both let you select an alternative out of given many alternative out of given many alternatives by testing an expression. However, there are some differences in their operations.

Here are some of those differences listed:

  • Switch statement differs from if statement in that switch can only test for equality whereas if can evaluate a relational or logical expression i.e. multiple conditions.
  • Switch statement selects its branches by testing the value of same variable (against a set of constants) whereas the if-else construction lets you use a series of expressions that may involve unrelated variables and complex expressions.
  • If-else is more versatile of the two statements. For instance, if-else can handle ranges whereas switch cannot. Each switch case label must be a single value.

    If(a>9 && a<15)
    Statement;

    But in case of switch we have to write 9 to 15 per cases.
  • If-else statement can handle floating-point tests also apart from handling integer and character tests whereas a switch cannot handle floating-point tests. The case labels of switch must be an integer byte, short, int or a char.
  • The switch case label value must be a constant. So, if two or more variables are to be compared, us if-else.
  • The switch statement is more efficient choice in terms of code used in a situation that supports the nature of switch operation (testing a value against a set of constants).
When we discuss these differences with an example then we can find some more explanation about if-else and switch statement. Each difference may have an example itself so write a program and make these differences. In the next article we will learn about nested switch.

Comparison between Switch and If-Else: JAVA

The switch and if-else both are selection statements and they both let you select an alternative out of given many alternative out of given many alternatives by testing an expression. However, there are some differences in their operations.

Here are some of those differences listed:

  • Switch statement differs from if statement in that switch can only test for equality whereas if can evaluate a relational or logical expression i.e. multiple conditions.
  • Switch statement selects its branches by testing the value of same variable (against a set of constants) whereas the if-else construction lets you use a series of expressions that may involve unrelated variables and complex expressions.
  • If-else is more versatile of the two statements. For instance, if-else can handle ranges whereas switch cannot. Each switch case label must be a single value.

    If(a>9 && a<15)
    Statement;

    But in case of switch we have to write 9 to 15 per cases.
  • If-else statement can handle floating-point tests also apart from handling integer and character tests whereas a switch cannot handle floating-point tests. The case labels of switch must be an integer byte, short, int or a char.
  • The switch case label value must be a constant. So, if two or more variables are to be compared, us if-else.
  • The switch statement is more efficient choice in terms of code used in a situation that supports the nature of switch operation (testing a value against a set of constants).
When we discuss these differences with an example then we can find some more explanation about if-else and switch statement. Each difference may have an example itself so write a program and make these differences. In the next article we will learn about nested switch.

Nested-Switch statement used in JAVA

Like if statements, a switch statement can also be nested. There can be a switch as part of the statement sequence of another switch as shown below. For instance, the following code fragment is perfectly all right in java.

switch(a)
{
case 1: switch(b)
{
case 0: statement 1;
case 1: statement 2;
}
break;
case 2: may be another switch or statement.
}

Important things about Switch

Following important things you must know about the switch statement:

  • A switch statement cannot work for non-equality comparisons.
  • The case labels of switch statements must be literals or constants.
  • No two case labels in the same switch can have identical values. But, in case of nested switch statements the case constants of the inner and outer switch can contain common values.
  • A switch statement works with data types byte, short, int and char only.
  • The switch statement is more efficient than if in a situation that supports the nature of switch operation.

A switch statement only evaluates the expression once, while if statement will evaluate it repeatedly until it finds a match. Thus, a switch is an efficient choice in such a situation.

There is another thing that we would like you to keep in mind that helps in better programming. And for that: Always put a break statement after the last case statement in a switch.

Although it is not necessary to put a break after the last statement in a switch, since control will leave the statement anyway, yet it should be done to avoid forgetting the break when you add another case statement at the end of the switch.

When there is not any break statement after any case, then the next will execute in a sequence and all the time all the cases will executed. For example:

switch (i++)
{
case 1:
case 2:statement 1;
case 3:statement 2;
case 4:statement 3;
default: statement 4;
}

When case 1 is matched, all the statement till the end of switch are executed as there is no break statement. That’s why programmer must use break statement at the end of each case in switch statement.

Features of Java

Java is a programming language, in which we can develop new system. It is a user friendly language so every one want to learn. Java is similar to c and c++ so if you know about basic building block of c and c++ then no need to more learn about java building block. So there is lots of features provided by it, some of these are:

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

According to Oracle, Java language is too much simple because:
  • Syntax is based on C and C++ , everyone know the basic building block of these languages.
  • Removed hardly learn features from JAVA library e.g., explicit pointers, operator overloading etc.
  • No need to remove unreferenced objects because there is Automatic Garbage Collection in JAVA.
  •  Lots of best GUI available in the market so they makes task easier.
  •  Strong library available so no need to write code for each component like Button, Label in AWT Java.
Strongly typed Language

Java is a strongly typed language, i mean to say each variable is declared with their data type. In VB6 we can assign a variable without their data type but in case of  java, you must to define the type of variable.
In VB6
a=10    ' its correct

In Java
a=10 ; // Wrong,
int a=10 ; //Right

Object Oriented

Java support object oriented concepts so we can design our software on the basis of object properties and their behavior. We have a list of OOP basic concepts, these are:

  • Class :  It is a user define data type or you can say it is a complex data type. With the help of class we can define object properties and their behavior inside the block.
  • Object :  It is a real time entity.
  • Encapsulation : Clubbing the data member (Properties of the object) and member function (Behavior of the object) inside the class known as Encapsulation.
  • Inheritance : In which we have minimum two classes one is base class and  other is child class. Now, the definition of it: access properties and method of the base class access by the child class known as Inheritance.
  • Data hiding & Data abstraction : Hide the data access level by the permission known as data hiding. In case data abstraction we should go for only overview of the system also hide the implementation details.
  • Polymorphism : poly means many and morphism means state. 
Platform Independent
Java code can run in any platform(operating system) so its a platform independent language. First of all source code compiled into byte code by the java compiler. By using JVM, we can interpret the byte code into machine independent code so we can say its a platform independent language.

Platform independent


Note :  Java is a machine dependent language.

Multi-threaded
A thread is a light weight program, executing concurrently. we can execute multiple thread concurrently, i mean to say we can execute two separate thread concurrently. The main advantage of multi-threading is that it shares the same memory. Threads are important for multi-media, Web applications etc.

Distributed
We can create distributed and enterprise applications in java. RMI and EJB are used for creating enterprise applications. EJB is basically used in banking sectors where data changed rapidly. Lots of advantages provide by EJB, these are:
  • Persistent 
  • Remote awareness
  • Transaction
Portable
Portable is similar to platform independent concept. The means of portable is, you can carry the code in any platform. In JAVA JVM interprets the byte code and make platform independent code or you can say portable code.

Robust
Java provide strong features to the code like lack of pointers so strong point in memory management. During program execution java handle garbage collection. There is exception handling and type checking mechanism in java. All these points makes java robust.

High-performance
Java is faster than traditional interpretation since byte code is "close" to native code still somewhat slower than a compiled language (e.g., C++).

Secure:


 Java architecture


According to Java architecture byte code verifier provide following functionality :

  • The code follows JVM specifications.
  • There is no unauthorized access to memory.
  • The code does not cause any stack overflows.
  • There are no illegal data conversions in the code such as float to object references.
  • Difference between application program and applet program in java

    Difference between Application Program and Applet program in java. There are following differences mentioned by me:

    Applet Program
    Application Program
    It is a small and light weight program.
    It may be either small or large.
    It is used to build dynamic applications.
    It is used to build both static as well as dynamic application.
    Applet program run according to their life cycle.
    Life Cycle:
    1.init( )
    2.start( )
    3.paint( )
    4.stop( )
    5.destroy( )
    Application program run according to procedure.
    Applet program run in restricted environment.
    Application program run through Java Runtime environment.
    It does not have any main( ) method
    It start from main ( ) method.
    Applet program must extended from Applet class.
    Newly created application is not necessary to extended from other class.
    Give special permission by the java control panel to run the code in windows 8
    Not required.
    Example :

    Import java.awt.*;
    Import java.applet.*;

    Public class design_applet extends Applet
    {
    public void init()
    {
    //Applet initialization
    }
    Public void start()
    {
    //start applet
    }
    Public void paint(Graphics g)
    {
    g.drawString(“dotprogramming”,50,50);
    }
    Public void stop()
    {
    //repaint possible
    }
    Public void destroy( )
    {
    //repaint not possible
    }
    }

    Example:

    Public class application_program
    {
    Public static void main(String r[])
    {
    // start programming here
    System.oout.println(“dotprogramming”);
    }
    }
    Use paint method to display string
    Use System.out.println() method to display in it.