---
title: "Comparison of java"  
description: "As java and c# is the advance version of C++. So, most of the syntax is same as C++. But there is some variation which we are dealing in this article."  
author: "Ailsa Singh"  
published: 2016-10-04  
updated: 2018-03-16  
canonical: https://www.mindstick.com/blog/11212/comparison-of-java  
category: "java"  
tags: ["java"]  
reading_time: 3 minutes  

---

# Comparison of java

As java and c# is the [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams) [version](https://www.mindstick.com/articles/12845/things-to-remember-while-migrating-odoo-to-a-better-version) of [C++](https://www.mindstick.com/blog/745/array-in-c-plus-plus). So, most of the syntax is same as C++. But there is some [variation](https://www.mindstick.com/articles/157260/variation-between-web-designer-and-web-developer) which we are dealing in this article.

**Following are the [difference](https://www.mindstick.com/articles/157114/good-news-or-bad-news-and-the-difference-is) in the syntax for the java:**

How to see the output in java?

\

Java syntax : System.out.println("Hello Java")

C# syntax : console.writeline(“Hello C#”)

C++ syntax : cout << “Hello C++”

C syntax : printf(“Hello”)

**How to take [input from the user](https://www.mindstick.com/forum/158952/what-are-the-different-methods-for-reading-input-from-the-user-in-python)?**

**Java:**

Taking a [string](https://www.mindstick.com/articles/1527/string-split-in-c-sharp) input

**str1=System.console().readLine();**\
\
How to take the [integer](https://answers.mindstick.com/qa/113667/write-code-for-roman-to-integer) input

**int a=Integer.parseInt(System.console().readLine()**

**C#**

Taking a string input

## String str1 =console.readline();

Taking an integer input:

**Int num1= [Convert](https://www.mindstick.com/forum/2093/configurationmanager-appsettings-convert-n-to-n-why) (ToInt32 (console.readline());**

C++

Taking a string input

For a single word.

```
string str1;
cin >> str1;
```

\

but for C++ spaces means extraction hence for entire line we need to write

\

following codes.

For this we need to declare the [standard](https://www.mindstick.com/articles/23223/naming-convention-or-coding-standard) header.

\

```
#include <string> String str1;getline (cin,mystr);
Converting to INT or Float
Int num1 ;
stringstream(str1) >> num1
float num2;
stringstream(str1) >> num2
```

## \

## \

## Taking integer as an input

\

Taking a string input

```
int num1;cin >> num2;C programmingChar s = getchar(); Taking a interger input Int num1;scanf(“/d”,&num1); Here is the small program
for the taking an input from the user and output            import java.io.*; class Demo1 { public static void
main(String args[]) {int a, b,c;String str1;System.out.println("Program
start") ;System.out.println("Enter
the string");str1=System.console().readLine();System.out.println("Enter
the 1st number \n");a=Integer.parseInt(System.console().readLine());//converting
char input to int System.out.println("Enter
the 2nd number \n")  ;b=Integer.parseInt(System.console().readLine());
//converting char input to intc=a+b;System.out.println("output
of string is : "+str1);System.out.println("output
of number is : "+c);}}
```

\

![Comparison of java](https://www.mindstick.com/blogs/35f06378-31c3-48e3-8b25-a5173531c7c9/images/d605604f-a36c-4975-a681-209cc20b106d.png)\

\

## Array input

## Java

**\**

Declaration for an array can be done as follows:

```
dataType[] array1;dataType array1[]; Giving limit to the array, by this syntaxdataType[] array1 = new dataType[arraySize];
```

## C#

## \

Declaration for an array can be done as follows:

datatype[] arrayName;

Giving limit to the array, by this syntax

\

dataType[] array1 = new dataType[arraySize];

**Note :** dataType array1[]; (Note : This method is not used in C# it will give

\

compiler error.)

## C++

**\**

Declaration for an array can be done as follows:

\

datatypetype arrayName [ arraySize ];

datatype[] arrayName; (Note : This method is not used in C++ it will give

\

compiler error.)

## C

**\**

Declaration for an array can be done as follows:

\

datatypetype arrayName [ arraySize ];

datatype[] arrayName; (Note : This method is not used in C++ it will give

\

compiler error.)

**Here is the small program in java to access array list.**

\

```
import java.io.*;

class Demo2 {

public static void main(String args[])
		{
			int[] num1=new int[5];
			int i;

			System.out.println("Program start") ;
			for (i=0;i<5;i++)
			{
			System.out.println("Enter the number ");
			num1[i]=Integer.parseInt(System.console().readLine());
			}
			for (int real : num1 )
			{
			System.out.println(real);
			}
		}
}
```

\

![Comparison of java](https://www.mindstick.com/blogs/35f06378-31c3-48e3-8b25-a5173531c7c9/images/478d291a-797a-4dac-b741-da43f2c45baf.png)\

---

Original Source: https://www.mindstick.com/blog/11212/comparison-of-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
