Java is a good choice for a students first General-purpose programming language. It is easy to use and it is a Class based, Object-Oriented Language. Over 3 billion devices worldwide are running Java as it can be used for many purposes such as Desktop Software Application, Web Applications, Game Development etc.
In this article we are going to learn the basics of how to code in Java.
‘Hello World’ program:
Consider the following simple Hello world program.
This is a Java ‘Class’ named Hello. Class is a blueprint for a object. Each Java program must have a class whose name is same as the name of the file. In this case the name of the file is ‘Hello.java’.
The class begins with a Java keyword ‘public’. It is an Access modifier. The four access levels are as follows:
Accessible to the package, default modifier, no keyword used.
Accessible to the class, ‘private’ keyword.
Accessible to the world, ‘public’ keyword.
Accessible to the package and derived sub-classes, ‘protected’ keyword.
The ‘main’ is invoked when the program is executed, we can call other methods of the class from the ‘main’ method. The ‘main’ method accepts an array of strings.
There is only a single statement in our ‘main’ function. It prints the text ‘Hello World’ onto the console. ‘System’ is Java class from the core library, ‘out’ is an object and ‘println’ is a method that prints the argument provided onto the console. Which in our case is “Hello World”.
Comments in Java:
We can write single line comments using ‘//’ and multi-line comments by enclosing the comment between /* and */.
There are two datatypes in Java:
Primitive Data Types.
Reference/Object Data Types.
Primitive Data Types:
There are 8 datatypes supported by Java.
We can use these datatypes to declare variables in the following way:
Conditionals allow for decision making. Certain pieces of code to be only executed if a certain condition is true, if it is false a different set of statements would be executed.
Below is a Example of a simple java script program that uses if-else conditional:
We can also use a switch conditional. A sample Java script program is as Follows:
Loops allow for executing a Java statement or set of statements multiple times.
A sample program utilizing the For loop is as follows:
A sample program using While loops to calculate the factorial of a number:
What do you need to code in Java?
In order to write and run a Java program, you need to install a software program called Java SE Development Kit (or JDK for short, and SE means Standard Edition). Basically, a JDK contains: JRE(Java Runtime Environment): is the core of the Java platform that enables running Java programs on your computer.
Is it easy to learn Java?
2. Java is Easy to Learn: Java is quite easy to learn and can be understood in a short span of time as it has a syntax similar to English. You can also learn from GeeksforGeeks Java Tutorials.
Where do you write Java code?
You write the actual code for your programmes in a text editor. (In NetBeans, there’s a special area for you to write code.) The code is called source code, and is saved with the file extension . java.
How can I teach myself Java?
Top tips for Learning Java Programming
Learn the Basics. As with anything, knowing the basics about Java is the best place to start.
Practice Coding. To use the old cliché, practice makes perfect.
Set Your Algorithm Carefully.
Trace Your Codes on Paper.
Read Sources on Java Programming Regularly.
Can I learn Java in 15 Days?
The best you can hope for in a 15 day adventure into Java is a familiarity with the libraries .. an understanding of the packages .. a means of deployment and the capability of writing small to medium functional pieces of code. Thats ok .. for 15 days you’ll have crammed a lot in to be able to do that.
Can I learn Java in 3 months?
Yes, Learning java in 3 months is possible. Although, it would require a lot of time to master it but at least in three months you can get good knowledge about Java SE. I would suggest invest more than three months and try to make a small project using java, this is how you can actually learn it.
How quickly can I learn Java?
On average, becoming a confident Java programmer takes about 1–2 years, considering you spend 2–3 hours per day practicing coding. Familiarising yourself with the language to the point where you can edit someone else’s code or write basic apps can take as little as four months.
Can I learn Java per month?
Java programming is one of the mostly used programming languages. To become a successful Java developer, the only way is to do the practice of all basics and advanced concepts of it. If we follow the following learning path, we can learn Java in one month only.
Can I learn Java same day?
First of all I must say you cannot learn something like java or any programming language in one day. If you have any prior knowledge in any programming language you should already know that. But if you want to learn it really fast what you can do is start watching a series of online tutorials.
How can I learn Java in one hour?
Can I learn Java in a week?
Learning programming is a long process, so basically it is impossible to learn JAVA programming within a week with no prior knowledge of programming. if you really want to learn to program then it will take time and need dedication as you aren’t familiar with the basics. steps to learn to program: learn basic syntax.
Which programming language should I learn first?
Python. Python is always recommended if you’re looking for an easy and even fun programming language to learn first. Rather than having to jump into strict syntax rules, Python reads like English and is simple to understand for someone who’s new to programming.