Showing posts with label Features of Java. Show all posts
Showing posts with label Features of Java. Show all posts

Monday, 29 March 2021

Methods in JAVA Language

 In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a selected task. It provides the reusability of code. we will also easily modify code using methods. during this section, we'll learn what's a way in Java, sorts of methods, method declaration, and the way to call a way in Java.


What is Method in JAVA language? 

A method may be a block of code or collection of statements or a group of code grouped together to perform a particular task or operation. It is wont to achieve the reusability of code. We can write a method once and use it many times. We don't require to write down code again and again. It also provides the straightforward modification and readability of code, just by adding or removing a piece of code. The method is executed only we call or invoke it.
The most important method in Java is that the main() method.


Method Declaration in JAVA. 

The method declaration provides information about method attributes, like visibility, return-type, name, and arguments. It has six components that are known as method header, as we have shown in the following figure.



Method Signature: Every method has a method signature. It is a part of the method declaration. It includes the method name and parameter list.

Access Specifier: Access specifier or modifier is that the access sort of the tactic. It specifies the visibility of the method. Java provides four types of access specifier:

Public: The method is accessible by all classes when we use public specifier in our application.

Private: once we use a personal access specifier, the tactic is accessible only within the classes during which it's defined.

Protected: once we use protected access specifier, the tactic is accessible within an equivalent package or subclasses during a different package.

Default: once we don't use any access specifier within the method declaration, Java uses default access specifier by default. It is visible only from an equivalent package only.

Return Type: Return type may be a data type that the tactic returns. It may have a primitive data type, object, collection, void, etc. If the tactic doesn't return anything, we use void keyword.

Method Name: it's a singular name that's wont to define the name of a way . It must be like the functionality of the tactic . Suppose, if we are creating a way for subtraction of two numbers, the tactic name must be subtraction(). A method is invoked by its name.

Parameter List: it's the list of parameters separated by a comma and enclosed within the pair of parentheses. It contains the data type and variable name. If the method has no parameter, left the parentheses blank.

Method Body: It is a part of the method declaration. It contains all the actions to be performed. It is enclosed within the pair of curly braces.

Wednesday, 9 November 2016

Features of Java Language

From the original Sun Java whitepaper: "Java is a simple object-oriented, distributed, interpreted, robust, secure, architecture-neutral , portable, high performance, multi-threaded, and dynamic language."

Java features are also know as Java Buzzword. Here are some original Java buzzwords....
  • Simple 
  • Secure
  • Portable
  • Object-Oriented
  • Robust
  • Multi threaded
  • Architectural neutral
  •  Interpreted
  • High performance
  • Distributed
  • Dynamic

Simple:
  •  Very simple C/C++ syntax , operators etc
  •  Java inherits many of the  object oriented features of C++.
  •  The core language is simpler than C++, no operator overloading, no pointers, and no multiple inheritance
  •  The way a java program deals with memory is much simpler than C and C++. 


Secure: 
  • Java achieves protection by confining a Java program to the Java execution environment (JVM) and not allowing it access to other parts of the computer. 
  • Java runtime Security Manager  can check which operations a particular piece of code is  allowed to do. As a result. java can run un-trusted code in a "sandbox" where, for example, it can draw to the screen but cannot access the local file system.



Portable: 
  • For Java "Write Once Run Anywhere" , and for most part this work. 
  • When you compile a Java program, a .class file (bytecode) is created, and you can run it on any platform e.g. Window, Linux, MAC.  
  • Not even a recompile is required , a Java executable can work, without change, on any Java enabled platform.
  

Object Oriented: 
  • Java is fundamentally based on the OOP notions of classes and objects.
  • Java uses a fundamental OOP type system that must be obeyed at compile-time and run-time.


Robust:

  Robust means reliable and Java is robust and secure as there are many  features which support this concept.
  • Crash Recovery
  • Exceptional Handling
  • Strict Run-time checking
  • No pointers
  • Memory Management  

Multithreaded:
  • Java  support multithreaded  programming, which allows you to write programs that do many things simultaneously.
  • Threads are important for multi-media , web applications etc.


Architecture-neutral:
  • Java is platform independent language.
  • There is no implementation dependent feature e.g size of primitive data type is fixed.
  • This was made with goal "write once; run anytime , any where , forever".

High Performance:
  • Java bytecode was designed so that it would be easy to translate directly into native machine code for very high performance by using a just-in-time compiler. 

 Distributed:
  • Java is designed for distributed environment of the Internet, because it handles TCP/IP protocols. 
  • The original version of Java(Oak) included features for intra address-space messaging. This allowed objects on two different computers to execute procedures remotely. Java revived these interfaces in a package called Remote Method Invocation(RMI).

 Dynamic:
  • Class and type information is kept around at runtime. This enables runtime loading and inspection of code in a very flexible way.

Methods in JAVA Language

 In general, a way may be thanks to perform some task. Similarly, the tactic in Java may be a collection of instructions that performs a sel...