Discovering C# with Console
In this tutorial, we will learn how to write a simple “Hello World!” program in C#. This will get you familiar with the basic syntax and requirements of a C# program.
The “Hello World!” program is often the first program we see when we dive into a new language. It simply prints Hello World! on the output screen
he purpose of this program is to get us familiar with the basic syntax and requirements of a programming language.
“Hello World”
using System;
namespace HelloWorld
{
class Hello {
static void Main(string[] args)
{
//Hello comment block
Console.WriteLine("Hello World!");
}
}
}
Note: This is the default setup when creating a new application within the request solution.
Now you may run the application, press F5 and the output should be: “Hello World!”
Understanding the “Hello World” program and how it works
- //Hello comment block
- // – represents the start of a comment section in C#. No worries comment sections/blocks are not executed by the C# compiler. (Consider when reading or using comments for better communicating with developers. To learn more about comments)
- namespace HelloWorld {…}
- is used to define the application namespace. So the example above namespace is called “HelloWorld”
- the perfect way to see namespace is like a container that will consist of methods, classes, and even other namespaces. (To learn more about namespace)
- class Hello {…}
- reflecting on the above example the class is created with the name – Hello in C#. C# is an object-oriented language and is mandatory for program execution.
- static void Main(string[], args){…}
- ‘Main()‘ this a method within the class of “Hello”. During the execution of a C# application, it will start with the ‘Main()‘
- Console.WriteLine(“Hello World”);
- to keep it short just remember in console application this will print the text to the user screen.
Tackling Hello World differently
// Hello World! program
namespace HelloWorld
{
class Hello {
static void Main(string[] args)
{
System.Console.WriteLine("Hello World!");
}
}
}
The above code is another way to execute the ‘Hello World’ program. Please take note with the two codes, the orignal code we began with and the code from above, the first difference is the missing “using System;”. Second difference to notice is the adding of the “System” before Console.WriteLine
Don’t worry more on this is another post.
Take away
- ‘Main()’ method must be inside the class definition
- Every C# program has to have a class definition
- Most importantly the execution begins within the ‘Main()’ method
So let’s keep it simple as a newbie this is an excellent introduction to C#. If anything within this post is hard to comprehend, don’t worry in the beginning I was the same way as well. As you progress with your read and research everything will begin to fall in place.
- Published in .NET & .NET Core, C#, Language, Programming Languages
Java Or Kotlin Language: Deciding Which Option to Use for Android Development
If my math is not wrong Java has been around for over 20+ years now and has no intention of going away. It holds a supreme position in the list of most popular programming languages following the C and C++ =, setting the highest usability record with millions of developers and systems.
Random Fact:
James Gosling, Mike Sheridan, and Patrick Naughton initiated the Java language back in 1991. Java has been the primary language for Android app development along with a few of its companions: Scala, Groovy and stepping up is Kotlin.
Kotlin Background
Let first you will need to understand what exactly is Kotlin so it is considered as statically typed programming language that runs on JVM(Java Virtual Machine) and JavaScript. It is developed by JetBrains and open-source community. The ‘Kotlin’ name came from Kotlin Island located near Saint Petersburg. It is supported by leading IDEs and compatible with Java 6 or Java 8. Kotlin is described as a general-purpose language and introduces functional features to support Java interoperability. The Kotlin project was born out of the aspiration for heightened productivity. The goal was to improve the coding experience in a way that was both practical and effective.
A central focus of Kotlin is to enable mixed-language projects. Kotlin also introduces improved syntax, as well as concise expressions and abstractions. Using Kotlin with Java reduces excessive boilerplate code, which is a huge win for Android developers. Kotlin came when Android development needed a more modern language to add to the qualities of java and aid in mobile development. This allows developers to not only easily update old Java apps to Kotlin, but also carry on their old work in Java to Kotlin.
Here’s a brief example Kotlin language
package hello
fun main() {
println("Hello World")
}
It’s that simple! Kotlin uses developer-friendly coding structures and norms that are easy-to-understand and use. When considering this example from the develops’ perspective, you will be able to understand why Kotlin is loved by developers around the world. It is concise, effective, and faster compared to Java.
Is Java Dead?
Based on the group that I program with it appears that Java is currently in the area with us developers. Java is a reputable programming language with vast open-source tools and libraries to help developers. With that said, no language is without fault and even Java is subject to complications that can make a developer’s job tedious. If anything the objective for Kotlin is to supposedly introduce solutions to the common programming headaches and improve the Java ecosystem as a whole.
Strict Trial And Error
Kotlin has some milage under itself and has become a more stable and congruous development option especially within the Android Studio IDE. Some developers seem to believe that Kotlin will oust Java for Android development in future years. Other reviewers seem to believe Kotlin and Java should be coexisting without one outweighing the other.
This is a quality Java is not known for; however, readability should always take priority over concision. Yes, the succinct nature of Kotlin simplifies a developer’s job and mitigates the risk for error, but Kotlin doesn’t practice concision for concision’s sake. So let’s take the example below and compare the difference in the languages presents.
public class MathLife {
public static double calculate () throws Exception {
switch(op) {
case "add":
return a + b;
case "subtract":
return a - b;
case "multiply":
return a * b;
case "divide":
return a / b;
default:
throw new Exception();
}
}
}
Above is a simple calculator function written in Java. For comparison, here is the same calculator in Kotlin:
fun calculate(a: Double, op: String, b: Double): Double {
when (op) {
"add" -> return a + b
"subtract" -> return a - b
"multiply" -> return a * b
"divide" -> return a / b
else -> throw Exception()
}
}
It may not seem like much, but the Kotlin version of this calculator is written in half the lines of code it took to program the function in Java. Brevity is a crucial factor in productivity. Writing large projects becomes easier when a developer is given more power for every line of code. A key observation here is Kotlin does not overlook comprehension for the sake of brevity. The syntax is concise, readable and still substantial.
The Winner: Java or Kotlin
In all fairness, chances are that you have been taught, learn and embraced Java. Switching to Kotlin at a time can be a bit of shock, so it is important to do this transition slowly to make sure you understand. having said that, Kotlin is the new official language and owing to its modern nature, it will become widely adopted in the future, so learning it and starting development with it right now would be a good idea. Understand java will continue to be a popular language for several years to come and isn’t likely to be entirely replaced. So take your time and make the switch gently.
At the end of the day, it’s all about what you feel comfortable with. As stated previously to be a true blood Androidian, you will need to have a working knowledge of the language Java. But if you already do have that then the Kotlin language of the future, so you might as well spend some time getting accustomed to it.
- Published in Android, Java, Kotlin, Language, Programming Languages


