Blog

  • Java vs C++

    Java is a general-purpose, high-level programming language. Java is used for web development, Machine Learning, and other cutting-edge software development. Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems’ Java platform (Java 1.0 [J2SE])

    C++ is a middle-level, case-sensitive, object-oriented programming language. Bjarne Stroustrup created C++ at Bell Labs. C++ is a platform-independent programming language that works on Windows, Mac OS, and Linux. C++ is near to hardware, allowing low-level programming. This provides a developer control over memory, improved performance, and dependable software.

    Read through this article to get an overview of C++ and Java and how these two programming languages are different from each other.

    What is Java?

    The latest release of the Java Standard Edition is Java SE 21. With the advancement of Java and its widespread popularity, multiple configurations were built to suit various types of platforms. For example: J2EE for Enterprise Applications, J2ME for Mobile Applications.

    The new J2 versions were renamed as Java SE, Java EE, and Java ME respectively. Java is guaranteed to be Write Once, Run Anywhere.

    Features of Java

    Java is −

    • Object Oriented − In Java, everything is an Object. Java can be easily extended since it is based on the Object model.
    • Platform Independent − Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by the Java Virtual Machine (JVM) on whichever platform it is being run on.
    • Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.
    • Secure − With Java’s secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.
    • Architecture-neutral − Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system.
    • Portable − Being architecture-neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler in Java is written in ANSI C with a clean portability boundary, which is a POSIX subset.
    • Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.
    • Multithreaded − With Java’s multithreaded feature it is possible to write programs that can perform many tasks simultaneously. This design feature allows the developers to construct interactive applications that can run smoothly.
    • Interpreted − Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light-weight process.
    • High Performance − With the use of Just-In-Time compilers, Java enables high performance.
    • Distributed − Java is designed for the distributed environment of the internet.
    • Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

    Java Example

    Take a look at the following simple Java program −

    packagecom.tutorialspoint;importjava.util.Scanner;publicclassJavaTester{publicstaticvoidmain(String args[]){String a, b;Scanner scanner =newScanner(System.in);System.out.println("Enter The value for variable a");
    
      a = scanner.nextLine();System.out.println("Enter The value for variable b");
      b = scanner.nextLine();System.out.println("The value you have entered for a is "+ a);System.out.println("The value you have entered for b is "+ b);
      scanner.close();}}</code></pre>

    In our example, we have taken two variables "a" and "b" and assigning some value to those variables. Note that in Java, we need to declare datatype for variables explicitly, as Java is strictly typed language. As Java is an object oriented language, we uses objects to perform any action. In the example, we've used Scanner class object to read user input from console which is represented by System.in object. System.out object method println() is used to print the values received.

    Output

    On execution, this Java code will produce the following output −

    Enter The value for variable a
    10
    Enter The value for variable b
    20
    The value you have entered for a is 10
    The value you have entered for b is 20
    

    What is C++?

    C++ is a statically typed, compiled, multi-paradigm, general-purpose programming language with a steep learning curve. Video games, desktop apps, and embedded systems use it extensively. C++ is so compatible with C that it can build practically all C source code without any changes. Object-oriented programming makes C++ a better-structured and safer language than C.

    Features of C++

    Let's see some features of C++ and the reason of its popularity.

    • Middle-level language − It's a middle-level language since it can be used for both systems development and large-scale consumer applications like Media Players, Photoshop, Game Engines, etc.
    • Execution Speed − C++ code runs quickly. Because it's compiled and uses procedures extensively. Garbage collection, dynamic typing, and other modern features impede program execution.
    • Object-oriented language − Object-oriented programming is flexible and manageable. Large apps are possible. Growing code makes procedural code harder to handle. C++'s key advantage over C.
    • Extensive Library Support − C++ has a vast library. Third-party libraries are supported for fast development.

    C++ Example

    Let's understand the syntax of C++ through an example written below.

    #includeusingnamespace std;intmain(){int a, b;
       cout <<"Enter The value for variable a \n";
       cin >> a;
       cout <<"Enter The value for variable b";
       cin >> b;
       cout <<"The value of a is "<< a <<"and"<< b;return0;}

    In our example, we are taking input for two variables "a" and "b" from the user through the keyboard and displaying the data on the console.

    Output

    On execution, it will produce the following output −

    Enter The value for variable a
    10
    Enter The value for variable b
    20
    The value of a is 10 and 20
    

    Difference Between Java and C++

    Both Java and C++ are among the most popular programming languages. Both of them have their advantages and disadvantages. In this tutorial, we shall take a closure look at their characteristic features which differentiate one from another.

    Sr.No.CriteriaJavaC++
    1Developed byJava was developed by James Gosling at Sun Microsystems. Initially it was designed for embedded systems, settop boxes, televisions etc. Later it become a preferred language for internet based application developmentC++ was developed by Bjarne Stroustrup at Bell Labs, as an extension to C language. It supports both high level as well as low level machine code access. C++ is mainly used to develop system softwares, compilers etc.
    2Influenced byIt was influenced by Ada 83, Pascal, C++, C#.It was influenced by Ada, ALGOL 68, C, ML, Simula, Smalltalk.
    3Dependency on ArchitectureThe Java bytecode works on any operating System. Bytecode is targeted for JVM. JVM or Java Virtual Machine then interpret the byte code and run the underlying machine specific code. Thus Java code needs not to be changed to run on different machines.It doesn't work on every operating system since libraries are different on different systems.
    4Platform independenceIt can run on any OS. Java code is platform independent. No platform specific code is required. Size of int, long remains same on all platforms.It is compiled differently on different platforms, can't be run on any OS.
    5PortablityIt is portable. Being platform independent, a java code can be transferred as it is on any machine without any plaform specific modification. A java code written in Windows machine can run in Unix machine in same fashion without any modification.It isn't portable.
    6Interpreted/CompiledIt is an interpreted language.It is a compiled language.
    7Memory managementMemory management is done automatically. Java provides Garbage Collector service which automatically deallocates memory once an object is not required.Memory management is to be done manually.
    8virtual KeywordIt doesn't have ‘virtual' keyword.It has the ‘virtual' keyword.
    9Multiple Inheritance supportIt supports single inheritance only. Multiple inheritance can be achieved using interfaces (partial only). A class can extend only a single class. Although interface can extend multiple inheritance. Multiple inheritance can lead to ambigous results. As virtual keyword is not supported in Java, multiple inhertance is not supported.It supports single and multiple Inheritance. Using virtual keyword, ambigous reference can be resolved.
    10operator overloading supportIt doesn't support operator overloading. Java supports only method overloading. Operator overloading is considered to add the complexity to base language so is not implemented to keep language simple.It supports operator overloading. In C++, we can overload both methods and operators.
    11pointersIt provides limited support to pointers. Pointers being a complex functionality, Java refrains from using them. It provides concept of reference to point to objects or precisely their addresses.It supports pointer operations. Developers can perform complex operations, can write optimized memory based code using pointers. But it is quite complex and requires strong programming skills to master them.
    12Low level machine code accessThey have high level functionalities. Java is platform independent language and the compiled code of java as byte code is for JVM which further converts code to low level code. So using java, developer cannot write low level machine code. This is the reason, that Java is mainly used for application development.They have low level functionalities. As C++ supports low level machine code code. It is mainly used to write system softwares, compilers etc.
    13Native libraries accessIt doesn't support direct native library call. Java is not designed to work with low level machine code and it is not supporting native call. But we can configure native call using third party libraries.It supports direct system library calls.
    14documentation commentIt supports documentation comment (/**.. */) for source code. Javadoc tool can read the documentation comments from source code and generate html based java documentation based on the comments.It doesn't support documentation comment for source code.
    15MultithreadingIt supports thread operations. Java has by default support for multithreading. It allows concurrent programming to improve efficiency and to reduce time takenIt doesn't support threads by design. It can be done by using third party threading libraries.
    16Console InputIt uses the 'System' class, i.e System.in for input. System.in class can be used to take input from user on console.It uses 'cin' for input operation. cin allows user to enter value in console.
    17Console OutputIt uses System.out for output. System.out.println() method prints the required value on system's console.It uses 'cout' for an output operation. cout prints the required value on system's console.
    19global supportIt doesn't support global scope. Java is a strict object oriented language and global scope is not available. Using packages, it supports across package scope though.It supports global scope as well as namespace scope.
    20struct/union supportIt doesn't support structures and unions.It supports structures and unions.
    21goto keywordIt doesn't have the 'goto' keyword. But same functionality is achivable using label. A break/continue statement can jump to a labelled statement location.It supports the 'goto' keyword. Using goto keyword, we can jump to any labelled location.
    22pass by value/referenceIt supports Pass by Value method only. Even object reference is technically passed to a method as value.It supports Pass by Value and pass by reference methods. In case of pass by reference, pointer or & notation is required.
    23Memory ManagementIt performs object management automatically using garbage collector. Developers are not required to do memory allocation for objects or deallocate them when objects are not in use. Garbage Collector service automatically detects and frees up the space. Due to GC service, memory leaks are very less possible in Java.It performs object management manually with the help of ‘new' and ‘delete'. Developers have to take measures to ensure memory is properly allocated/deallocated to prevent memory leaks.
  • Data Types

    Fortran provides five intrinsic data types, however, you can derive your own data types as well. The five intrinsic types are −

    • Integer type
    • Real type
    • Complex type
    • Logical type
    • Character type

    Integer Type

    The integer types can hold only integer values. The following example extracts the largest value that can be held in a usual four byte integer −

    program testingInt
    implicit none
    
       integer :: largeval
       print *, huge(largeval)
       
    end program testingInt

    When you compile and execute the above program it produces the following result −

    2147483647
    

    Note that the huge() function gives the largest number that can be held by the specific integer data type. You can also specify the number of bytes using the kind specifier. The following example demonstrates this −

    Live Demo

    program testingInt
    implicit none
    
       !two byte integer
       integer(kind = 2) :: shortval
       
       !four byte integer
       integer(kind = 4) :: longval
       
       !eight byte integer
       integer(kind = 8) :: verylongval
       
       !sixteen byte integer
       integer(kind = 16) :: veryverylongval
       
       !default integer 
       integer :: defval
    
        
    print *, huge(shortval) print *, huge(longval) print *, huge(verylongval) print *, huge(veryverylongval) print *, huge(defval) end program testingInt

    When you compile and execute the above program, it produces the following result −

    32767
    2147483647
    9223372036854775807
    170141183460469231731687303715884105727
    2147483647
    

    Real Type

    It stores the floating point numbers, such as 2.0, 3.1415, -100.876, etc.

    Traditionally there are two different real types, the default real type and double precision type.

    However, Fortran 90/95 provides more control over the precision of real and integer data types through the kind specifier, which we will study in the chapter on Numbers.

    The following example shows the use of real data type −

    Live Demo

    program division   
    implicit none  
    
       ! Define real variables   
       real :: p, q, realRes 
       
       ! Define integer variables  
       integer :: i, j, intRes  
       
       ! Assigning  values   
       p = 2.0 
       q = 3.0    
       i = 2 
       j = 3  
       
       ! floating point division
       realRes = p/q  
       intRes = i/j
       
       print *, realRes
       print *, intRes
       
    end program division  

    When you compile and execute the above program it produces the following result −

    0.666666687    
    0
    

    Complex Type

    This is used for storing complex numbers. A complex number has two parts, the real part and the imaginary part. Two consecutive numeric storage units store these two parts.

    For example, the complex number (3.0, -5.0) is equal to 3.0 – 5.0i

    We will discuss Complex types in more detail, in the Numbers chapter.

    Logical Type

    There are only two logical values: .true. and .false.

    Character Type

    The character type stores characters and strings. The length of the string can be specified by len specifier. If no length is specified, it is 1.

    For example,

    character (len = 40) :: name  
    name = “Zara Ali”

    The expression, name(1:4) would give the substring “Zara”.

    Implicit Typing

    Older versions of Fortran allowed a feature called implicit typing, i.e., you do not have to declare the variables before use. If a variable is not declared, then the first letter of its name will determine its type.

    Variable names starting with i, j, k, l, m, or n, are considered to be for integer variable and others are real variables. However, you must declare all the variables as it is good programming practice. For that you start your program with the statement −

    implicit none
    

    This statement turns off implicit typing.

  • Features

    Java programming language was initially developed to work on embedded systems, settop boxes, television. So by requirements, it was initially designed to work on varied platforms. Over the period of multiple years, Java evolved to become one of the most popular language used to develop internet based applications.

    Java is a feature rich language and with every new version, it is continously evolving. It is widely used across billions of devices. Following are the main features of the Java language –

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

    Object Oriented

    In Java, everything is an Object. Java can be easily extended since it is based on the Object model. As a language that has the Object-Oriented feature, Java supports the following fundamental concepts of OOPs −

    • Polymorphism
    • Inheritance
    • Encapsulation
    • Abstraction
    • Classes
    • Objects
    • Instance
    • Method
    • Message Passing

    Platform Independent

    Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by the Java Virtual Machine (JVM) on whichever platform it is being run on.

    Java is designed in Write Once, Run Anywhere (WORA) way. Code written in Java is not directly dependent on the type of machine it is running. A code is Java is compiled in ByteCode which is platform independent. Java Virtual Machine, JVM can understand the byte code. Java provides platform specific JVMs. It is the responsibility of platform specific JVM to interpret the byte code correctly thus developers are free to write code without worrying about platforms like windows, linux, unix, Mac etc. This feature makes Java a platform neutral language.

    As byte code can be distributed over the web and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on. It makes java code highly portable and useful for application running on multiple platforms.

    Simple

    Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.

    Java is very easy to learn. It inherits many features from C, C++ and removes complex features like pointers, operator overloading, multiple inheritance, explicit memory allocation etc. It provides automatic garbage collection. With a rich set of libraries with thousands of useful functions, Java makes developers life easy.

    Secure

    With Java’s secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.

    Java is by design highly secure as it is not asking developers to interact with underlying system memory or operation system. Bytecode is secure and several security flaws like buffer overflow, memory leak are very rare. Java exception handling mechanism allows developers to handle almost all type of error/exceptions which can happen during program execution. Automatic garbage collection helps in maintaining the system memory space utilization in check.

    Architecture-neutral

    Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system.

    Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system. With advancement in processor architectures or machine specific processors, java code remains independent of any specific requirement of a processor. As java is an open standard, even a specific JVM can be prepared for a custom architecture. As in today’s time, we’ve JVM available for almost all popular platforms, architectures, java code is completely independent. For example, a java program created in Windows machine can run on linux machine without any code modification.

    Portable

    Being architecture-neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler in Java is written in ANSI C with a clean portability boundary, which is a POSIX subset.

    Due to this portability, java was an instant hit since inception. It was particulary useful for internet based application where platforms varied from place to place and same code base can be used across multiple platform. So collaboration between developers was easy across multiple locations.

    Robust

    Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking. Automatic garbage collection, strong memory management, no pointers, no direct access to system memory, exception handling, error handling are some of the key features which makes Java a Robust, strong language to rely on.

    Multithreaded

    With Java’s multithreaded feature it is possible to write programs that can perform many tasks simultaneously. This design feature allows the developers to construct interactive applications that can run smoothly.

    A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.

    By definition, multitasking is when multiple processes share common processing resources such as a CPU. Multithreading extends the idea of multitasking into applications where you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel. The OS divides processing time not only among different applications, but also among each thread within an application.

    Multi-threading enables you to write in a way where multiple activities can proceed concurrently in the same program.

    Interpreted

    Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light-weight process.

    JVM sits in between the javac compiler and the underlying hardware, the javac (or any other compiler) compiler compiles Java code in the Bytecode, which is understood by a platform specific JVM. The JVM then compiles the Bytecode in binary using JIT (Just-in-time) compilation, as the code executes.

    High Performance

    With the use of Just-In-Time compilers, Java enables high performance. JVM uses JIT compiler to improves the execution time of the program. Below are some general optimizations that are done by the JIT compilers

    • Method inlining
    • Dead code elimination
    • Heuristics for optimizing call sites
    • Constant folding
  • Basic Syntax

    A Fortran program is made of a collection of program units like a main program, modules, and external subprograms or procedures.

    Each program contains one main program and may or may not contain other program units. The syntax of the main program is as follows −

    program program_name
    implicit none      
    
    ! type declaration statements      
    ! executable statements  
    
    end program program_name

    A Simple Program in Fortran

    Let’s write a program that adds two numbers and prints the result −

    program addNumbers
    
    ! This simple program adds two numbers
       implicit none
    
    ! Type declarations
       real :: a, b, result
    
    ! Executable statements
       a = 12.0
       b = 15.0
       result = a + b
       print *, 'The total is ', result
    
    end program addNumbers

    When you compile and execute the above program, it produces the following result −

    The total is 27.0000000    
    

    Please note that −

    • All Fortran programs start with the keyword program and end with the keyword end program, followed by the name of the program.
    • The implicit none statement allows the compiler to check that all your variable types are declared properly. You must always use implicit none at the start of every program.
    • Comments in Fortran are started with the exclamation mark (!), as all characters after this (except in a character string) are ignored by the compiler.
    • The print * command displays data on the screen.
    • Indentation of code lines is a good practice for keeping a program readable.
    • Fortran allows both uppercase and lowercase letters. Fortran is case-insensitive, except for string literals.

    Basics

    The basic character set of Fortran contains −

    • the letters A … Z and a … z
    • the digits 0 … 9
    • the underscore (_) character
    • the special characters = : + blank – * / ( ) [ ] , . $ ‘ ! ” % & ; < > ?

    Tokens are made of characters in the basic character set. A token could be a keyword, an identifier, a constant, a string literal, or a symbol.

    Program statements are made of tokens.

    Identifier

    An identifier is a name used to identify a variable, procedure, or any other user-defined item. A name in Fortran must follow the following rules −

    • It cannot be longer than 31 characters.
    • It must be composed of alphanumeric characters (all the letters of the alphabet, and the digits 0 to 9) and underscores (_).
    • First character of a name must be a letter.
    • Names are case-insensitive

    Keywords

    Keywords are special words, reserved for the language. These reserved words cannot be used as identifiers or names.

    The following table, lists the Fortran keywords −

    The non-I/O keywords
    allocatableallocateassignassignmentblock data
    callcasecharactercommoncomplex
    containscontinuecycledatadeallocate
    defaultdodouble precisionelseelse if
    elsewhereend block dataend doend functionend if
    end interfaceend moduleend programend selectend subroutine
    end typeend whereentryequivalenceexit
    externalfunctiongo toifimplicit
    ininoutintegerintentinterface
    intrinsickindlenlogicalmodule
    namelistnullifyonlyoperatoroptional
    outparameterpausepointerprivate
    programpublicrealrecursiveresult
    returnsaveselect casestopsubroutine
    targetthentypetype()use
    WhereWhile
    The I/O related keywords
    backspacecloseendfileformatinquire
    openprintreadrewindWrite
  • History

    History of Java

    Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems’ Java platform (Java 1.0 [J2SE]). History of even naming of the Java is very interesting. It went under many names.

    Java Name History

    GreenTalk

    James Gosling was leading a team named as ‘Green’ team. Target of this team was to create a new project which can. Initially C++ was the original choice to develop the project. James Gosling wanted to enhance C++ to achieve the target but due to high memory usage, that idea was rejected and team started with a new language initially named as GreenTalk. The file extension used as .gt. Later this language was termed as Oak and finally to Java.

    Oak

    James Gosling renamed language to Oak. There was an Oak tree in front of his office. James Gosling used this name as Oak represents solidarity and Oak tree is the national tree of multiple countries like USA, France, Romania etc. But Oak technologies already had Oak as a trademark and James team had to brainstrom another title for the language.

    Finally Java

    Team put multiple names like DNA, Silk, Ruby and Java. Java was finalized by the team. James Gosling tabled Java title based on type of espresso coffee bean. Java is an island in Indonesia where new coffee was discovered termed as Java coffee. As per James Gosling, Java was among the top choice along with Silk. Finally Java was selected as it was quite unique and represented the essence of being dynamic,revolutionary and fun to say.

    Sun released the first public implementation as Java 1.0 in 1995. It promised Write Once, Run Anywhere (WORA), providing no-cost run-times on popular platforms.

    On 13 November, 2006, Sun released much of Java as free and open source software under the terms of the GNU General Public License (GPL).

    On 8 May, 2007, Sun finished the process, making all of Java’s core code free and open-source, aside from a small portion of code to which Sun did not hold the copyright.

    The latest release of the Java Standard Edition is Java SE 21. With the advancement of Java and its widespread popularity, multiple configurations were built to suit various types of platforms. For example: J2EE for Enterprise Applications, J2ME for Mobile Applications.

    Java Versions History

    Over the period of nearly 30 years, Java has seen many minor and major versions. Following is a brief explaination of versions of java till date.

    Sr.No.VersionDateDescription
    1JDK Beta1995Initial Draft version
    2JDK 1.023 Jan 1996A stable variant JDK 1.0.2 was termed as JDK 1
    3JDK 1.119 Feb 1997Major features like JavaBeans, RMI, JDBC, inner classes were added in this release.
    4JDK 1.28 Dec 1998Swing, JIT Compiler, Java Modules, Collections were introduced to JAVA and this release was a great success.
    5JDK 1.38 May 2000HotSpot JVM, JNDI, JPDA, JavaSound and support for Synthetic proxy classes were added.
    6JDK 1.46 Feb 2002Image I/O API to create/read JPEG/PNG image were added. Integrated XML parser and XSLT processor (JAXP) and Preferences API were other important updates.
    7JDK 1.5 or J2SE 530 Sep 2004Various new features were added to the language like foreach, var-args, generics etc.
    8JAVA SE 611 Dec 20061. notation was dropped to SE and upgrades done to JAXB 2.0, JSR 269 support and JDBC 4.0 support added.
    9JAVA SE 77 Jul 2011Support for dynamic languages added to JVM. Another enhancements included string in switch case, compressed 64 bit pointers etc.
    10JAVA SE 818 Mar 2014Support for functional programming added. Lambda expressions,streams, default methods, new date-time APIs introduced.
    11JAVA SE 921 Sep 2017Module system introduced which can be applied to JVM platform.
    12JAVA SE 1020 Mar 2018Unicode language-tag extensions added. Root certificates, threadlocal handshakes, support for heap allocation on alternate memory devices etc were introduced.
    13JAVA SE 115 Sep 2018Dynamic class-file constants,Epsilon a no-op garbage collector, local-variable support in lambda parameters, Low-overhead heap profiling support added.
    14JAVA SE 1219 Mar 2019Experimental Garbage Collector,Shenandoah: A Low-Pause-Time Garbage Collector, Microbenchmark Suite, JVM Constants API added.
    15JAVA SE 1317 Sep 2019Feature added – Text Blocks (Multiline strings), Enhanced Thread-local handshakes.
    16JAVA SE 1417 Mar 2020Feature added – Records, a new class type for modelling, Pattern Matching for instanceof, Intuitive NullPointerException handling.
    17JAVA SE 1515 Sep 2020Feature added – Sealed Classes, Hidden Classes, Foreign Function and Memory API (Incubator).
    18JAVA SE 1616 Mar 2021Feature added as preview – Records, Pattern Matching for switch, Unix Domain Socket Channel (Incubator) etc.
    19JAVA SE 1714 Sep 2021Feature added as finalized – Sealed Classes, Pattern Matching for instanceof, Strong encapsulation of JDK internals by default. New macOS rendering pipeline etc.
    20JAVA SE 1822 Mar 2022Feature added – UTF-8 by Default, Code Snippets in Java API Documentation, Vector API (Third incubator), Foreign Function, Memory API (Second Incubator) etc.
    21JAVA SE 1920 Sep 2022Feature added – Record pattern, Vector API (Fourth incubator), Structured Concurrency (Incubator) etc.
    22JAVA SE 2021 Mar 2023Feature added – Scoped Values (Incubator), Record Patterns (Second Preview), Pattern Matching for switch (Fourth Preview),Foreign Function & Memory API (Second Preview) etc.
    22JAVA SE 2119 Sep 2023Feature added – String Templates (Preview), Sequenced Collections, Generational ZGC, Record Patterns, Pattern Matching for switch etc.
  • Overview

    Java programming language was originally developed by Sun Microsystems which was initiated by James Gosling and released in 1995 as core component of Sun Microsystems’ Java platform (Java 1.0 [J2SE]).

    The latest release of the Java Standard Edition is Java SE 8. With the advancement of Java and its widespread popularity, multiple configurations were built to suit various types of platforms. For example: J2EE for Enterprise Applications, J2ME for Mobile Applications.

    The new J2 versions were renamed as Java SE, Java EE, and Java ME respectively. Java is guaranteed to be Write Once, Run Anywhere.

    Java is −

    • Object Oriented − In Java, everything is an Object. Java can be easily extended since it is based on the Object model.
    • Platform Independent − Unlike many other programming languages including C and C++, when Java is compiled, it is not compiled into platform specific machine, rather into platform independent byte code. This byte code is distributed over the web and interpreted by the Virtual Machine (JVM) on whichever platform it is being run on.
    • Simple − Java is designed to be easy to learn. If you understand the basic concept of OOP Java, it would be easy to master.
    • Secure − With Java’s secure feature it enables to develop virus-free, tamper-free systems. Authentication techniques are based on public-key encryption.
    • Architecture-neutral − Java compiler generates an architecture-neutral object file format, which makes the compiled code executable on many processors, with the presence of Java runtime system.
    • Portable − Being architecture-neutral and having no implementation dependent aspects of the specification makes Java portable. Compiler in Java is written in ANSI C with a clean portability boundary, which is a POSIX subset.
    • Robust − Java makes an effort to eliminate error prone situations by emphasizing mainly on compile time error checking and runtime checking.
    • Multithreaded − With Java’s multithreaded feature it is possible to write programs that can perform many tasks simultaneously. This design feature allows the developers to construct interactive applications that can run smoothly.
    • Interpreted − Java byte code is translated on the fly to native machine instructions and is not stored anywhere. The development process is more rapid and analytical since the linking is an incremental and light-weight process.
    • High Performance − With the use of Just-In-Time compilers, Java enables high performance.
    • Distributed − Java is designed for the distributed environment of the internet.
    • Dynamic − Java is considered to be more dynamic than C or C++ since it is designed to adapt to an evolving environment. Java programs can carry extensive amount of run-time information that can be used to verify and resolve accesses to objects on run-time.

    Hello World using Java Programming

    Just to give you a little excitement about Java programming, I’m going to give you a small conventional C Programming Hello World program, You can try it using Demo link.

    publicclassMyFirstJavaProgram{/* This is my first java program.
    
    * This will print 'Hello World' as the output
    */publicstaticvoidmain(String&#91;]args){System.out.println("Hello World");// prints Hello World}}</code></pre>

    History of Java

    James Gosling initiated Java language project in June 1991 for use in one of his many set-top box projects. The language, initially called 'Oak' after an oak tree that stood outside Gosling's office, also went by the name 'Green' and ended up later being renamed as Java, from a list of random words.

    Sun released the first public implementation as Java 1.0 in 1995. It promised Write Once, Run Anywhere (WORA), providing no-cost run-times on popular platforms.

    On 13 November, 2006, Sun released much of Java as free and open source software under the terms of the GNU General Public License (GPL).

    On 8 May, 2007, Sun finished the process, making all of Java's core code free and open-source, aside from a small portion of code to which Sun did not hold the copyright.

    Tools You Will Need

    For performing the examples discussed in this tutorial, you will need a Pentium 200-MHz computer with a minimum of 64 MB of RAM (128 MB of RAM recommended).

    You will also need the following softwares −

    • Linux 7.1 or Windows xp/7/8 operating system
    • Java JDK 8
    • Microsoft Notepad or any other text editor

    This tutorial will provide the necessary skills to create GUI, networking, and web applications using Java.

  • Environment Setup

    Setting up Fortran in Windows

    G95 is the GNU Fortran multi-architechtural compiler, used for setting up Fortran in Windows. The windows version emulates a unix environment using MingW under windows. The installer takes care of this and automatically adds g95 to the windows PATH variable.

    You can get the stable version of G95 from here

    installer setup
    mini installer setup

    AD

    https://delivery.adrecover.com/recover.html?siteId=18107&dataDogLoggingEnabled=false&dataDogLoggingVersion=1

    How to use G95

    During installation, g95 is automatically added to your PATH variable if you select the option “RECOMMENDED”. This means that you can simply open a new Command Prompt window and type “g95” to bring up the compiler. Find some basic commands below to get you started.

    Sr.NoCommand & Description
    1g95 –c hello.f90Compiles hello.f90 to an object file named hello.o
    2g95 hello.f90Compiles hello.f90 and links it to produce an executable a.out
    3g95 -c h1.f90 h2.f90 h3.f90Compiles multiple source files. If all goes well, object files h1.o, h2.o and h3.o are created
    4g95 -o hello h1.f90 h2.f90 h3.f90Compiles multiple source files and links them together to an executable file named ‘hello’

    Command line options for G95

    -c Compile only, do not run the linker.
    -o Specify the name of the output file, either an object file or the executable.
    

    Multiple source and object files can be specified at once. Fortran files are indicated by names ending in “.f”, “.F”, “.for”, “.FOR”, “.f90”, “.F90”, “.f95”, “.F95”, “.f03” and “.F03”. Multiple source files can be specified. Object files can be specified as well and will be linked to form an executable file.

  • Overview

    Fortran, as derived from Formula Translating System, is a general-purpose, imperative programming language. It is used for numeric and scientific computing.

    Fortran was originally developed by IBM in the 1950s for scientific and engineering applications. Fortran ruled this programming area for a long time and became very popular for high performance computing, because.

    It supports −

    • Numerical analysis and scientific computation
    • Structured programming
    • Array programming
    • Modular programming
    • Generic programming
    • High performance computing on supercomputers
    • Object oriented programming
    • Concurrent programming
    • Reasonable degree of portability between computer systems

    AD

    https://delivery.adrecover.com/recover.html?siteId=18107&dataDogLoggingEnabled=false&dataDogLoggingVersion=1

    Facts about Fortran

    • Fortran was created by a team, led by John Backus at IBM in 1957.
    • Initially the name used to be written in all capital, but current standards and implementations only require the first letter to be capital.
    • Fortran stands for FORmula TRANslator.
    • Originally developed for scientific calculations, it had very limited support for character strings and other structures needed for general purpose programming.
    • Later extensions and developments made it into a high level programming language with good degree of portability.
    • Original versions, Fortran I, II and III are considered obsolete now.
    • Oldest version still in use is Fortran IV, and Fortran 66.
    • Most commonly used versions today are : Fortran 77, Fortran 90, and Fortran 95.
    • Fortran 77 added strings as a distinct type.
    • Fortran 90 added various sorts of threading, and direct array processing.
  • HTML DOM

    Every webpage resides inside a browser window which can be considered as an object.

    Document object represents the HTML document that is displayed in that window. The Document object has various properties that refer to other objects which allow access to and modification of document content.

    The way a document content is accessed and modified is called the Document Object Model, or DOM. The Objects are organized in a hierarchy. This hierarchical structure applies to the organization of objects in a Web document.

    • Window − Top of the hierarchy. It is the outmost element of the object hierarchy.
    • Document − Each HTML document that gets loaded into a window becomes a document object. The document contains the contents of the page.
    • Elements − represent the content on a web page. Examples include the text boxes, page title etc.
    • Nodes − are often elements, but they can also be attributes, text, comments, and other DOM types.

    Here is a simple hierarchy of a few important DOM objects −

    HTML DOM

    Dart provides the dart:html library to manipulate objects and elements in the DOM. Console-based applications cannot use the dart:html library. To use the HTML library in the web applications, import dart:html −

    import 'dart:html';
    

    Moving on, we will discuss some DOM Operations in the next section.

    Finding DOM Elements

    The dart:html library provides the querySelector function to search for elements in the DOM.

    Element querySelector(String selectors);
    

    The querySelector() function returns the first element that matches the specified group of selectors. “selectors should be string using CSS selector syntax as given below

    var element1 = document.querySelector('.className'); 
    var element2 = document.querySelector('#id'); 
    

    Example: Manipulating DOM

    Follow the steps given below, in the Webstorm IDE −

    Step 1 − File NewProject → In the location, provide the project name as DemoWebApp.

    Demowebapp

    Step 1 − In the section “Generate sample content”, select SimpleWebApplication.

    Create

    It will create a sample project, DemoWebApp. There is a pubspec.yaml file containing the dependencies which need to be downloaded.

    name: 'DemoWebApp' 
    version: 0.0.1 
    description: An absolute bare-bones web app. 
    
    #author: Your Name <[email protected]> 
    #homepage: https://www.example.com  
    environment:   
       sdk: '>=1.0.0 <2.0.0'  
    dependencies:   
       browser: '>=0.10.0 <0.11.0'   dart_to_js_script_rewriter: '^1.0.1'  
    transformers: 
    - dart_to_js_script_rewriter 

    If you are connected to Web, then these will be downloaded automatically, else you can right-click on the pubspec.yaml and get dependencies.

    Pub Get Dependencies

    In the web folder, you will find three files: Index.html, main.dart, and style.css

    Index.html

    <!DOCTYPE html>   
    <html> 
       <head>     
    
      &lt;meta charset = "utf-8"&gt;     
      &lt;meta http-equiv = "X-UA-Compatible" content = "IE = edge"&gt;     
      &lt;meta name = "viewport" content = "width = device-width, initial-scale = 1.0"&gt;
      &lt;meta name = "scaffolded-by" content = "https://github.com/google/stagehand"&gt;
      &lt;title&gt;DemoWebApp&lt;/title&gt;     
      &lt;link rel = "stylesheet" href = "styles.css"&gt;     
      &lt;script defer src = "main.dart" type = "application/dart"&gt;&lt;/script&gt;
      &lt;script defer src = "packages/browser/dart.js"&gt;&lt;/script&gt; 
    </head> <body>
      &lt;h1&gt;
         &lt;div id = "output"&gt;&lt;/div&gt; 
      &lt;/h1&gt;  
    </body> </html>

    Main.dart

    import 'dart:html';  
    void main() {   
       querySelector('#output').text = 'Your Dart web dom app is running!!!.'; 
    } 

    Run the index.html file; you will see the following output on your screen.

    Demo Web App

    Event Handling

    The dart:html library provides the onClick event for DOM Elements. The syntax shows how an element could handle a stream of click events.

    querySelector('#Id').onClick.listen(eventHanlderFunction); 
    

    The querySelector() function returns the element from the given DOM and onClick.listen() will take an eventHandler method which will be invoked when a click event is raised. The syntax of eventHandler is given below −

    void eventHanlderFunction (MouseEvent event){ } 
    

    Let us now take an example to understand the concept of Event Handling in Dart.

    TestEvent.html

    <!DOCTYPE html> 
    <html> 
       <head> 
    
      &lt;meta charset = "utf-8"&gt; 
      &lt;meta http-equiv = "X-UA-Compatible" content = "IE = edge"&gt; 
      &lt;meta name = "viewport" content = "width = device-width, initial-scale = 1.0"&gt; 
      &lt;meta name = "scaffolded-by" content ="https://github.com/google/stagehand"&gt; 
      &lt;title&gt;DemoWebApp&lt;/title&gt; 
      &lt;link rel = "stylesheet" href = "styles.css"&gt; 
      &lt;script defer src = "TestEvent.dart" type="application/dart"&gt;&lt;/script&gt; 
      &lt;script defer src = "packages/browser/dart.js"&gt;&lt;/script&gt; 
    </head> <body>
      &lt;div id = "output"&gt;&lt;/div&gt; 
      &lt;h1&gt; 
         &lt;div&gt; 
            Enter you name : &lt;input type = "text" id = "txtName"&gt; 
            &lt;input type = "button" id = "btnWish" value="Wish"&gt; 
         &lt;/div&gt; 
      &lt;/h1&gt; 
      &lt;h2 id = "display"&gt;&lt;/h2&gt; 
    </body> </html>

    TestEvent.dart

    import 'dart:html'; 
    void main() { 
       querySelector('#btnWish').onClick.listen(wishHandler); 
    }  
    void wishHandler(MouseEvent event){ 
       String name = (querySelector('#txtName')  as InputElement).value; 
       querySelector('#display').text = 'Hello Mr.'+ name; 
    }

    Output

    Output
  • Unit Testing

    Unit Testing involves testing every individual unit of an application. It helps the developer to test small functionalities without running the entire complex application.

    The Dart external library named “test” provides a standard way of writing and running unit tests.

    Dart unit testing involves the following steps −

    Step 1: Installing the “test” package

    To installing third-party packages in the current project, you will require the pubspec.yaml file. To install test packages, first make the following entry in the pubspec.yaml file −

    dependencies: 
    test:
    

    After making the entry, right-click the pubspec.yaml file and get dependencies. It will install the “test” package. Given below is a screenshot for the same in the WebStorm Editor.

    Unit Testing

    Packages can be installed from the command line too. Type the following in the terminal −

    pub get
    

    Step 2: Importing the “test” package

    import "package:test/test.dart";
    

    Step 3 Writing Tests

    Tests are specified using the top-level function test(), while test assertions are made using the expect() function. For using these methods, they should be installed as a pub dependency.

    Syntax

    test("Description of the test ", () {  
       expect(actualValue , matchingValue) 
    });
    

    The group() function can be used to group tests. Each group’s description is added to the beginning of its test’s descriptions.

    Syntax

    group("some_Group_Name", () { 
       test("test_name_1", () { 
    
      expect(actual, equals(exptected)); 
    }); test("test_name_2", () {
      expect(actual, equals(expected)); 
    }); })

    Example 1: A Passing Test

    The following example defines a method Add(). This method takes two integer values and returns an integer representing the sum. To test this add() method −

    Step 1 − Import the test package as given below.

    Step 2 − Define the test using the test() function. Here, the test() function uses the expect() function to enforce an assertion.

    import 'package:test/test.dart';      
    // Import the test package 
    
    int Add(int x,int y)                  
    // Function to be tested { 
       return x+y; 
    }  
    void main() { 
       // Define the test 
       test("test to check add method",(){  
    
      // Arrange 
      var expected = 30; 
      
      // Act 
      var actual = Add(10,20); 
      
      // Asset 
      expect(actual,expected); 
    }); }

    It should produce the following output −

    00:00 +0: test to check add method 
    00:00 +1: All tests passed! 
    

    Example 2: A Failing Test

    The subtract() method defined below has a logical mistake. The following test verifies the same.

    import 'package:test/test.dart'; 
    int Add(int x,int y){ 
       return x+y; 
    }
    int Sub(int x,int y){ 
       return x-y-1; 
    }  
    void main(){ 
       test('test to check sub',(){ 
    
      var expected = 10;   
      // Arrange 
      
      var actual = Sub(30,20);  
      // Act 
      
      expect(actual,expected);  
      // Assert 
    }); test("test to check add method",(){
      var expected = 30;   
      // Arrange 
      
      var actual = Add(10,20);  
      // Act 
      
      expect(actual,expected);  
      // Asset 
    }); }

    Output − The test case for the function add() passes but the test for subtract() fails as shown below.

    00:00 +0: test to check sub 
    00:00 +0 -1: test to check sub 
    Expected: <10> 
    Actual: <9> 
    package:test  expect 
    bin\Test123.dart 18:5  main.<fn> 
       
    00:00 +0 -1: test to check add method 
    00:00 +1 -1: Some tests failed.  
    Unhandled exception: 
    Dummy exception to set exit code. 
    #0  _rootHandleUncaughtError.<anonymous closure> (dart:async/zone.dart:938) 
    #1  _microtaskLoop (dart:async/schedule_microtask.dart:41)
    #2  _startMicrotaskLoop (dart:async/schedule_microtask.dart:50) 
    #3  _Timer._runTimers (dart:isolate-patch/timer_impl.dart:394) 
    #4  _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:414) 
    #5  _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148) 
    

    Grouping Test Cases

    You can group the test cases so that it adds more meaning to you test code. If you have many test cases this helps to write much cleaner code.

    In the given code, we are writing a test case for the split() function and the trim function. Hence, we logically group these test cases and call it String.

    Example

    import "package:test/test.dart"; 
    void main() { 
       group("String", () { 
    
      test("test on split() method of string class", () { 
         var string = "foo,bar,baz"; 
         expect(string.split(","), equals(&#91;"foo", "bar", "baz"])); 
      }); 
      test("test on trim() method of string class", () { 
         var string = "  foo "; 
         expect(string.trim(), equals("foo")); 
      }); 
    }); }

    Output − The output will append the group name for each test case as given below −

    00:00 +0: String test on split() method of string class 
    00:00 +1: String test on trim() method of string class 
    00:00 +2: All tests passed