we will learn how to write the simple program of java. We can write a simple hello java program easily after installing the JDK.
To create a simple java program, you need to create a class that contains the main method. Let's understand the requirement first.
For executing any java program, you need to
Install the JDK if you don't have installed it, download the JDK and install it.
Set path of the jdk/bin directory.
Create the java program
Compile and run the java program
Hello World Example
class Simplex{
publicstaticvoid main(String args[]){
System.out.println("Hello Java world");
}
}
Note - here class is a keyword and Simplex is a class name. publicstaticvoid main is a main function of program here exection of java program starts.System.out.println method used to print output or value on the console.
For run this program save this file with class name.java
There are many differences and similarities between the C++ programming language and java. A list of top differences between C++ and Java are given below
1.Pointers
Java: Java does not support pointers, templates, pointer overloading, unions, etc.
C++: C++ does support pointers, structures, unions, templates, operator overloading, or pointers arithmetic.
2. Support Destructors
Java: Java doesn’t support destructors; it has an automatic garbage collection system.
C++: It supports destructors; it gets invoked when an object is destroyed.
3. Conditional Compilation and Inclusion
Java: It doesn’t support conditional compilation and inclusion.
C++: These are the major features of C++.
4. Thread Support
Java: It has built-in supports threads in Java. There is a thread class in Java, inherit to create a new thread override the run method.
C++: C++ doesn't have built-in support for threads. It relies on third-party libraries for thread support
5. Default Arguments
Java: Java does not support default arguments. There is no (::) in Java. The strategy definitions should dependably happen inside a class, so there is no requirement for scope determination there either.
C++: C++ supports default arguments. C++ has scope resolution (::), which utilize and characterize a strategy outside a class to get to a worldwide variable inside from the degree where a neighborhood variable additionally exists with a similar name.
Java: JJava doesn't support multiple inheritances through class. It can be achieved by interfaces in java.
C++: C++ supports different inheritance. The keyword virtual utilizes to determine ambiguities amid various legacy if there is any.
8. Exception Handling
Java: Exception handling is different because there are no destructors. In Java, try/catchmust define if the function declares that it may throw an exception.
C++: While in C++, you may exclude the attempt/get regardless of whether the capacity throws an exemption.
9. Method Overloading and Operator Overloading
Java: Java hasmethod overloading but no operator overloading. The classString does use the and++= operators to concatenate strings and expressionsString use automatic type conversion, but that’s a special built-in case.
C++: C++ supports both technique over-loading and administrator over-loading.
10.Call by Value and Call by reference
java: Java supports call by value only. There is no call by reference in java
C++: C++ supports both calls by value and call by reference
Conclusion
In this tutorial, we learned about the basic differences in C++ and Java. We explore each factor of Java and C++. Furthermore, if you have any additional questions or comments, feel free to leave a note below!
Java is a high level, robust, object-oriented and secure programming language.
It enables programmers to write computer instructions using English-based commands instead of having to write in numeric codes. It’s known as a high-level language because it can be read and written easily by humans.
Java is: –
Concurrent where you can execute many statements instead of sequentially executing it.
Class-based and an object-oriented programming language.
Independent programming language that follows the logic of “Write once, Run anywhere” i.e. the compiled code can run on all platforms which supports java.
In simple words, it is a computing platform where you can develop applications. History Of Java
In the early 90s, Java, which originally went by the name Oak and then Green, was created by a team led by James Gosling for Sun Microsystems, a company now owned by Oracle foundation.
Java was originally designed for use on digital mobile devices, such as cellphones. However, when Java 1.0 was released to the public in 1996, its main focus had shifted to use on the internet, providing interactivity with users by giving developers a way to produce animated web pages.
However, there have been many updates since version 1.0, like J2SE 1.3 in 2000, J2SE 5.0 in 2004, Java SE 8 in 2014, and Java SE 10 in 2018.
Over the years, Java has evolved as a successful language for use both on and off the internet.
Java is also used as the programming language for many different software programs, games, and add-ons. Some examples of the more widely used programs written in Java or that use Java include the Adobe Creative suite, Eclipse, Lotus Notes, Minecraft, OpenOffice, Runescape, and Vuze
Features of Java
Java is a general-purpose programming language developed with the aim to bring portability and a higher level of security. Other than these two main java features, there are many other features of Java that make it such a unique and popular language. They are following
1) Simple
Java is easy to learn and its syntax is quite simple, clean and easy to understand.The confusing and ambiguous concepts of C++ are either left out in Java or they have been re-implemented in a cleaner way.
Eg : Pointers and Operator Overloading are not there in java but were an important part of C++.
2) Object Oriented
In java everything is Object which has some data and behaviour. Java can be easily extended as it is based on Object Model.
3) Robust
Java makes an effort to eliminate error prone codes by emphasizing mainly on compile time error checking and runtime checking. But the main areas which Java improved were Memory Management and mishandled Exceptions by introducing automatic Garbage Collector and Exception Handling.
4) Platform Independent
Unlike other programming languages such as C, C++ etc which are compiled into platform specific machines. Java is guaranteed to be write-once, run-anywhere language.
On compilation Java program is compiled into bytecode. This bytecode is platform independent and can be run on any machine, plus this bytecode format also provide security. Any machine with Java Runtime Environment can run Java Programs.
5) Secure
When it comes to security, Java is always the first choice. With java secure features it enable us to develop virus free, temper free system. Java program always runs in Java runtime environment with almost null interaction with system OS, hence it is more secure.
6) Multi Threading
Java multithreading feature makes it possible to write program that can do many tasks simultaneously. Benefit of multithreading is that it utilizes same memory and other resources to execute multiple threads at the same time, like While typing, grammatical errors are checked along.
7) Architectural Neutral
Compiler generates bytecodes, which have nothing to do with a particular computer architecture, hence a Java program is easy to intrepret on any machine.
8) Portable
Java Byte code can be carried to any platform. No implementation dependent features. Everything related to storage is predefined, example: size of primitive data types
9) High Performance
Java is an interpreted language, so it will never be as fast as a compiled language like C or C++. But, Java enables high performance with the use of just-in-time compiler.