SlideShare a Scribd company logo
Syntax Comparison of Golang with C and Java - Mindbowser
Syntax
C Java Go
Extension .c .java .go
VM Needed Not needed JVM is there to
convert java files
to class files
Not needed
Compiler TurboC javac gc
Program
Execution
Starts from
main() function
Starts from
public static void
main(String[ ]
args)
starts from
func main() and
should be in
package main
Syntax
C Java Go
Variable
Declaration
int a; float b;
int a,b,c;
Initialization
int a=25;
char c=’a’;
int a; float b; a int
var c string
var a,b,c float
Initialization
var o,p int=34,65
k=45.67 (type of variable
auto judged by
compiler)
Shorthand notation
a:=30 (only inside
function)
Data Types bytes,short,int,long,
double,float,char,void
Primitive
bytes,short,int,long
,double,float,
boolean,char
uint, int,float32,...,
complex, byte,rune
C Java Go
Constant const int LEN=10 final int PI=3.14 const LEN int=10
Operators All operators like
Arithmetic,Logical,
Bitwise etc. are
same
All operators like
Arithmetic,Logical,
Bitwise etc. are
same
All operators like
Arithmetic,Logical,
Bitwise etc. are
same
Decision Making
Statements
(If else)
if(i>5){
flag=true
}
else{
flag=false
}
if(i>5){
flag=true
}
else{
flag=false
}
if i>5{
flag=true
}else{
flag=false
}
Syntax
C Java Go
Switch Case switch(i){
case 1: ……
break;
.
.
default:.....
break ;
}
switch(i){
case 1: ……
break;
.
.
default:.....
break ;
}
Expression switch
switch marks{
case 90: grade==’A’
case 50,60,70:grade==’C .
default: fmt.Println(“Invalid”)
}
Type switch
var x interface{}
switch x.(type){
case int:
fmt.Println(“x is int”)
default:
fmt.Println(“I don’t know”)
}
Syntax
C Java Go
For loop for(i=1;i<5;i++){
……...
}
for(i=1;i<5;i++){
…………..
}
for i:=0;i<5;i++{
………..
}
for key,val:=range
numbers{
…………..
}
While Loop while(i<10){
i++;
}
while(i<10){
i++;
}
for sum<100{
sum+=sum
}
Syntax
C Java Go
Function Declaration
int sum(int,int)
int sum(int x,int y){
……………
return
}
Calling
int add;
add=sum(10,20)
-Supports pass by
value and reference
Define method
public int sum(int
a,int b){
…………..
return
}
-Only pass by value
func sum(no int)
(int){
……
return ..
}
-Both pass by value
and reference
Function
Overloading
No Yes No
Syntax
C Java Go
Variadic Functions No printMax(10,20,30)
public static void
printMax(double…
numbers){
……...
}
func sum(num
...int) int{
…..
….
}
Ex. Println() is
implemented in
“fmt”
package
func Println(a
...interface{})(n
int,err error)
String char greet[6]={
‘h’,’e’,’l’,’l’,’o’,’0’
}
String s=new
String(“Hello”)
var
greeting=”Hello”
Syntax
C Java Go
String Functions strcpy(str1, str2)
strcat(str1,str2)
strlen(s1)............
str.length()
str.concat(str2)
str.compareTo(str2
)
String is made up
of runes. Rune is
UTF Format (A-
’65’,a-’97’)
len(str)
strings.join(str1,str
2)
Arrays Fixed size data
structure
Declaration
int array[10];
Accessing Elements
int value=array[10]
Declaration
int[ ] numbers
Creation
numbers=new
int[10]
Declaration
var number [10]int
Initialization
Var bal=[10]
int{...............}
Syntax
C Java Go
Slice There is no growable
data structure
java.util.Collection
package provides
dynamic growable
array. E.g List,Set,Map
etc
Growable data
structure
Declaration
var numbers []int
Creation
numbers=make([
]int,5,5)
5 len, 5 is capacity
append(),copy()
Default value - nil
Map There is no map data
structure in C
Key, Value pair
Map m=new
HashMap()
Map[key] value
Default value is nil
Syntax
C Java Go
Map - m.put(“Zero”,1)
put( )
get( )
ForEach to iterate
over collection and
array
var dictionary=map
[string] int
dictionary[“Zero”]=1
Create using make
var dict=make(map
[string] int)
Range -> to iterate over
slice,map
for key,val:=range values
{
……...
}
Syntax
C Java Go
Struct / Class Collection of fields and
methods
struct book{
int id;
char name[50];
char author[50];
}book;
//Access members
struct book book1;
strcpy(book1.id,400)
Java does not have
struct but have
class
class Books{
int id;
String name;
String author;
void display(){
…………...
}
}
Books b=new
Book();
b.name=”Vision”
Go have struct to
hold data in
variables.
type struct Book{
id int;
name string;
}
func(book3 *Book)
display() {
…………..
}
book1:=new(Book)
var book2 Book;
book2.name=”Go”
Syntax
C Java Go
Embedding It is like inheritance
in Java
class A {
….
}
Class B extends A
{
...
}
type Person struct{
Name string
}
func (per *Person)
speak(){
……..
}
type Mobile struct{
Person
Model String
}
Mob:=new(Mobile)
mob.Person.speak(
)
Syntax
C Java Go
Pointer Direct address of
memory location
int *a
a=&b;
NULL pointer
Always assign null
value to pointer
variable when you
don’t know exact
address to assign
int *a=NULL;
Java does not
support pointer
var a *int
var fp *float32
a=&p
NIL pointer
var *p int=nil
Syntax
C Java Go
Interface C does not have
interface concept
-Collection of only abstract
methods (from java 8 it
supports static methods
also)
-Classes implements
interface
public interface Animal{
public void eat();
public void sleep();
}
public class Monkey extends
Animal{
………..
}
-Provides method
signatures
type Shape
interface {
area() float64
}
type square struct{
side float64
}
func(sq Square)area( )
float64 {
return sq.side*sq.side
}
Same method signature
is implemented
Syntax
C Java Go
Go has empty interface which is like
object class in java. An empty
interface can hold any type of
value.
fmt.Println(a ...interface{ })
Type Casting Convert variable from
one to another data type
(type) expression
int sum=5,count=2;
Double d=(double)
sum/count
Widening
byte->short->int->float->
long->double
float=10
Narrowing
double->float->long->int-
>short->byte
int a=(float)10.40
var i int=10
var f float64=6.44
fmt.Println(float64(i))
fmt.Println(int(f))
Syntax
C Java Go
Error Handling -No direct support for error
handling
But it returns error no.
perror() and strerror() used to
display text message associated
with error no
int dividend=20;
int divisor=0;
int quotient;
if(divisor==0){
fprintf(stderr,”Divide by zero”);
exit(-1);
}
Exception Handling
-Exception is problem
arises during program
execution.
Checked/Unchecked Ex.
try{
……
}
catch(Exception ex){
……..
}
finally{
……..
}
No try/catch mechanism.
Instead it is having
defer,panic,recover
concepts.
-Provides error interface
type error interface{
Error() string
}
Normally function
returns error as last
return value. Use
errors.New() for
specifying error msg.
Syntax
C Java Go
Concurrency /
Multithreading
Doesn’t have
support.
Java have multithreading
concept for simultaneous
execution of different
tasks at same time.
We need to extends
Thread class or Runnable
interface and then
implement run( ) and write
your code
start(),run(),join(),sleep(),...
Here, we use
goroutines for
concurrent
execution.
To make function
as goroutine just
append go in front
of your function.
Two goroutines are
communicating
using channel
concept
Syntax
Thank You!
Drop us an email if you any doubts contact@mindbowser.com

More Related Content

DOCX
Bc0037
PPTX
C++11: Feel the New Language
PPTX
C++ theory
PDF
Modern C++
PPTX
C Theory
PPT
Strings in c
PPTX
PPT
Gentle introduction to modern C++
Bc0037
C++11: Feel the New Language
C++ theory
Modern C++
C Theory
Strings in c
Gentle introduction to modern C++

What's hot (20)

PPT
Project Lambda - Closures after all?
PDF
Generic programming and concepts that should be in C++
PPTX
String in c programming
PPT
Strings
PPT
Computer Programming- Lecture 5
PDF
C++11 & C++14
PDF
CBSE Question Paper Computer Science with C++ 2011
PPT
Input and output in C++
DOCX
Type header file in c++ and its function
PPTX
DOC
String in c
PPTX
Managing I/O & String function in C
PDF
Generic Programming
PPTX
ODP
Clojure basics
PPTX
C++ Presentation
PPTX
02. Primitive Data Types and Variables
PPTX
C++ 11 Features
PDF
Resource wrappers in C++
PDF
Scala categorytheory
Project Lambda - Closures after all?
Generic programming and concepts that should be in C++
String in c programming
Strings
Computer Programming- Lecture 5
C++11 & C++14
CBSE Question Paper Computer Science with C++ 2011
Input and output in C++
Type header file in c++ and its function
String in c
Managing I/O & String function in C
Generic Programming
Clojure basics
C++ Presentation
02. Primitive Data Types and Variables
C++ 11 Features
Resource wrappers in C++
Scala categorytheory
Ad

Similar to Syntax Comparison of Golang with C and Java - Mindbowser (20)

PPTX
Golang workshop - Mindbowser
PDF
Golang and Eco-System Introduction / Overview
PPTX
Go Programming Language (Golang)
PDF
Go Java, Go!
PDF
Go Java, Go!
PPTX
Go Java, Go!
PPTX
Comparing Golang and understanding Java Value Types
PPTX
Should i Go there
PDF
Go Lang Tutorial
PPTX
Lab2_AdvancedGoConceptswithgo_foundationofgolang_.pptx
PDF
Introduction to Programming in Go
PPTX
Go programming introduction
PPT
Introduction to Go ProgrammingLanguage.ppt
PDF
Golang online course
PDF
Introduction to go language programming
PPTX
The Go Programing Language 1
PDF
Golang
PPTX
Introduction to Go
ODP
Ready to go
PPTX
Golang basics for Java developers - Part 1
Golang workshop - Mindbowser
Golang and Eco-System Introduction / Overview
Go Programming Language (Golang)
Go Java, Go!
Go Java, Go!
Go Java, Go!
Comparing Golang and understanding Java Value Types
Should i Go there
Go Lang Tutorial
Lab2_AdvancedGoConceptswithgo_foundationofgolang_.pptx
Introduction to Programming in Go
Go programming introduction
Introduction to Go ProgrammingLanguage.ppt
Golang online course
Introduction to go language programming
The Go Programing Language 1
Golang
Introduction to Go
Ready to go
Golang basics for Java developers - Part 1
Ad

More from Mindbowser Inc (20)

PPTX
Healthcare Technology Survey 2023
PPTX
Top DevOps Trends And Statistics You Need To Know In 2023
PPTX
How To Achieve Project Success With Your Outsourced Team?
PPTX
Data Science Consulting: From Idea To Deployment
PPTX
Understanding The Difference Between RPO And Staff Augmentation
PPTX
Top 5 Benefits Of IT Staff Augmentation For Modern Businesses
PPTX
How To Select The Right Software Architecture For Your Healthcare Product?
PDF
Agile Scrum Mastery: Learn How To Bring Complex Projects To life!
PDF
A Guide To Minimum Viable Architecture Points For Any Startup
PDF
Benefits and challenges of ehr
PDF
What To Choose Between - Native App And Hybrid Mobile App
PDF
7 Secret Reasons To Choose An Outsourced Agency?
PDF
How We Thrill Customers?
PDF
Benefits and Challenges of EHR
PDF
20 Tools That Any Non Tech Founder Can Use To Manage Their Tech Product Devel...
PDF
Get Ready For What's New In Insurance Technology Trends For 2021
PDF
10 top mobile app development trends to look out for in 2021
PDF
How To Ensure Quality With Automation
PDF
15 Questions To Answer Before Building Your Website
PDF
10 growth strategies for a telehealth platform
Healthcare Technology Survey 2023
Top DevOps Trends And Statistics You Need To Know In 2023
How To Achieve Project Success With Your Outsourced Team?
Data Science Consulting: From Idea To Deployment
Understanding The Difference Between RPO And Staff Augmentation
Top 5 Benefits Of IT Staff Augmentation For Modern Businesses
How To Select The Right Software Architecture For Your Healthcare Product?
Agile Scrum Mastery: Learn How To Bring Complex Projects To life!
A Guide To Minimum Viable Architecture Points For Any Startup
Benefits and challenges of ehr
What To Choose Between - Native App And Hybrid Mobile App
7 Secret Reasons To Choose An Outsourced Agency?
How We Thrill Customers?
Benefits and Challenges of EHR
20 Tools That Any Non Tech Founder Can Use To Manage Their Tech Product Devel...
Get Ready For What's New In Insurance Technology Trends For 2021
10 top mobile app development trends to look out for in 2021
How To Ensure Quality With Automation
15 Questions To Answer Before Building Your Website
10 growth strategies for a telehealth platform

Recently uploaded (20)

PDF
Machine learning based COVID-19 study performance prediction
PDF
Advanced IT Governance
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
NewMind AI Weekly Chronicles - August'25 Week I
Machine learning based COVID-19 study performance prediction
Advanced IT Governance
Advanced methodologies resolving dimensionality complications for autism neur...
Dropbox Q2 2025 Financial Results & Investor Presentation
20250228 LYD VKU AI Blended-Learning.pptx
Network Security Unit 5.pdf for BCA BBA.
The Rise and Fall of 3GPP – Time for a Sabbatical?
GamePlan Trading System Review: Professional Trader's Honest Take
Review of recent advances in non-invasive hemoglobin estimation
Advanced Soft Computing BINUS July 2025.pdf
Diabetes mellitus diagnosis method based random forest with bat algorithm
Mobile App Security Testing_ A Comprehensive Guide.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Unlocking AI with Model Context Protocol (MCP)
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
NewMind AI Weekly Chronicles - August'25 Week I

Syntax Comparison of Golang with C and Java - Mindbowser

  • 2. Syntax C Java Go Extension .c .java .go VM Needed Not needed JVM is there to convert java files to class files Not needed Compiler TurboC javac gc Program Execution Starts from main() function Starts from public static void main(String[ ] args) starts from func main() and should be in package main
  • 3. Syntax C Java Go Variable Declaration int a; float b; int a,b,c; Initialization int a=25; char c=’a’; int a; float b; a int var c string var a,b,c float Initialization var o,p int=34,65 k=45.67 (type of variable auto judged by compiler) Shorthand notation a:=30 (only inside function) Data Types bytes,short,int,long, double,float,char,void Primitive bytes,short,int,long ,double,float, boolean,char uint, int,float32,..., complex, byte,rune
  • 4. C Java Go Constant const int LEN=10 final int PI=3.14 const LEN int=10 Operators All operators like Arithmetic,Logical, Bitwise etc. are same All operators like Arithmetic,Logical, Bitwise etc. are same All operators like Arithmetic,Logical, Bitwise etc. are same Decision Making Statements (If else) if(i>5){ flag=true } else{ flag=false } if(i>5){ flag=true } else{ flag=false } if i>5{ flag=true }else{ flag=false } Syntax
  • 5. C Java Go Switch Case switch(i){ case 1: …… break; . . default:..... break ; } switch(i){ case 1: …… break; . . default:..... break ; } Expression switch switch marks{ case 90: grade==’A’ case 50,60,70:grade==’C . default: fmt.Println(“Invalid”) } Type switch var x interface{} switch x.(type){ case int: fmt.Println(“x is int”) default: fmt.Println(“I don’t know”) } Syntax
  • 6. C Java Go For loop for(i=1;i<5;i++){ ……... } for(i=1;i<5;i++){ ………….. } for i:=0;i<5;i++{ ……….. } for key,val:=range numbers{ ………….. } While Loop while(i<10){ i++; } while(i<10){ i++; } for sum<100{ sum+=sum } Syntax
  • 7. C Java Go Function Declaration int sum(int,int) int sum(int x,int y){ …………… return } Calling int add; add=sum(10,20) -Supports pass by value and reference Define method public int sum(int a,int b){ ………….. return } -Only pass by value func sum(no int) (int){ …… return .. } -Both pass by value and reference Function Overloading No Yes No Syntax
  • 8. C Java Go Variadic Functions No printMax(10,20,30) public static void printMax(double… numbers){ ……... } func sum(num ...int) int{ ….. …. } Ex. Println() is implemented in “fmt” package func Println(a ...interface{})(n int,err error) String char greet[6]={ ‘h’,’e’,’l’,’l’,’o’,’0’ } String s=new String(“Hello”) var greeting=”Hello” Syntax
  • 9. C Java Go String Functions strcpy(str1, str2) strcat(str1,str2) strlen(s1)............ str.length() str.concat(str2) str.compareTo(str2 ) String is made up of runes. Rune is UTF Format (A- ’65’,a-’97’) len(str) strings.join(str1,str 2) Arrays Fixed size data structure Declaration int array[10]; Accessing Elements int value=array[10] Declaration int[ ] numbers Creation numbers=new int[10] Declaration var number [10]int Initialization Var bal=[10] int{...............} Syntax
  • 10. C Java Go Slice There is no growable data structure java.util.Collection package provides dynamic growable array. E.g List,Set,Map etc Growable data structure Declaration var numbers []int Creation numbers=make([ ]int,5,5) 5 len, 5 is capacity append(),copy() Default value - nil Map There is no map data structure in C Key, Value pair Map m=new HashMap() Map[key] value Default value is nil Syntax
  • 11. C Java Go Map - m.put(“Zero”,1) put( ) get( ) ForEach to iterate over collection and array var dictionary=map [string] int dictionary[“Zero”]=1 Create using make var dict=make(map [string] int) Range -> to iterate over slice,map for key,val:=range values { ……... } Syntax
  • 12. C Java Go Struct / Class Collection of fields and methods struct book{ int id; char name[50]; char author[50]; }book; //Access members struct book book1; strcpy(book1.id,400) Java does not have struct but have class class Books{ int id; String name; String author; void display(){ …………... } } Books b=new Book(); b.name=”Vision” Go have struct to hold data in variables. type struct Book{ id int; name string; } func(book3 *Book) display() { ………….. } book1:=new(Book) var book2 Book; book2.name=”Go” Syntax
  • 13. C Java Go Embedding It is like inheritance in Java class A { …. } Class B extends A { ... } type Person struct{ Name string } func (per *Person) speak(){ …….. } type Mobile struct{ Person Model String } Mob:=new(Mobile) mob.Person.speak( ) Syntax
  • 14. C Java Go Pointer Direct address of memory location int *a a=&b; NULL pointer Always assign null value to pointer variable when you don’t know exact address to assign int *a=NULL; Java does not support pointer var a *int var fp *float32 a=&p NIL pointer var *p int=nil Syntax
  • 15. C Java Go Interface C does not have interface concept -Collection of only abstract methods (from java 8 it supports static methods also) -Classes implements interface public interface Animal{ public void eat(); public void sleep(); } public class Monkey extends Animal{ ……….. } -Provides method signatures type Shape interface { area() float64 } type square struct{ side float64 } func(sq Square)area( ) float64 { return sq.side*sq.side } Same method signature is implemented Syntax
  • 16. C Java Go Go has empty interface which is like object class in java. An empty interface can hold any type of value. fmt.Println(a ...interface{ }) Type Casting Convert variable from one to another data type (type) expression int sum=5,count=2; Double d=(double) sum/count Widening byte->short->int->float-> long->double float=10 Narrowing double->float->long->int- >short->byte int a=(float)10.40 var i int=10 var f float64=6.44 fmt.Println(float64(i)) fmt.Println(int(f)) Syntax
  • 17. C Java Go Error Handling -No direct support for error handling But it returns error no. perror() and strerror() used to display text message associated with error no int dividend=20; int divisor=0; int quotient; if(divisor==0){ fprintf(stderr,”Divide by zero”); exit(-1); } Exception Handling -Exception is problem arises during program execution. Checked/Unchecked Ex. try{ …… } catch(Exception ex){ …….. } finally{ …….. } No try/catch mechanism. Instead it is having defer,panic,recover concepts. -Provides error interface type error interface{ Error() string } Normally function returns error as last return value. Use errors.New() for specifying error msg. Syntax
  • 18. C Java Go Concurrency / Multithreading Doesn’t have support. Java have multithreading concept for simultaneous execution of different tasks at same time. We need to extends Thread class or Runnable interface and then implement run( ) and write your code start(),run(),join(),sleep(),... Here, we use goroutines for concurrent execution. To make function as goroutine just append go in front of your function. Two goroutines are communicating using channel concept Syntax
  • 19. Thank You! Drop us an email if you any doubts [email protected]