Home Education Java Programming FREE | Basics

Java Programming FREE | Basics

According to Oracle, Java runs on 3 Billion devices worldwide. Java is actually the most used and most loved Programming language for the mobile and desktop apps and game developments. Every Programming language needs to be practiced a lot.

Do you know What is Programming?

What you can find here:

  1. What is Java?
  2. History of JAVA Programming
  3. How to download and run Java?
  4. How do Java programs work?
  5. Structure of Java Program
  6. Java Programming in more details
  7. Conclusion
  8. QnA

What is Java?

Learn Java Programming

History of JAVA Programming

In 1991, James Gosling and his team developed Java at Sun Microsystems, Inc. The main reason behind the motivation of James and his team was that languages like C/C++ were developed for specific hardware types and cannot run its program in devices with different specifications. That’s why Java language is also known for the portability.

Java history

The scope of Java in today’s world 

Java is the most used programming language all over the world. The Oracle claims that Java is running on more than 3 billion devices, and it’s 100% true because if you look around yourself then probably most of the electronic devices nearby you are programmed in Java language. The android apps, games, scientific applications, web servers, application servers, web applications, desktop GUI applications, etc. are developed from Java. See it’s everywhere.

The average salary of a Java developer is $40000. 

How to download and run Java?

To run Java programs on your device, you need to download two software,

  1. JDK ( Java Development Kit )
  2. Eclipse or any other IDE that supports JAVA.

To download Java go to Oracle’s official website and download the latest version of JDK for your supporting Operating System.

To download Eclipse, goto Eclipse website and download the eclipse.exe installer for your system.

After downloading, install the JAVA JDK and Eclipse respectively. To write and run programs you have to use Eclipse software and save the programs using the .java extension.

How do Java programs work?

The Java platform(that environment in which it runs its program) has two components:

  1. JVM ( Java Virtual Machine )
  2. Java API ( Java Application Programming Interface )

Let’s look into deep:

  1. JVM

The JVM is the base of the Java platform. The phrase “write once run anywhere” is said because of the JVM. When you write a code and compile it, then the Java compiler compiles the code into bytecode, which is interpreted by a suitable JVM. The interpreter parses and runs each Java bytecode instructions and runs it. The compilation by the JVM is done once and the interpretation of the program occurs each time on execution.

  1. Java API

The Java API is a large collection of ready-made programs that provide many useful capabilities, such as GUI( Graphical User Interface )components, event handling, I/O, networking, etc.

The package that holds all the Java files is called JDK ( Java Development Kit ).

Structure of Java Program

The Structure of a Java program is also called as Syntax of Java code, which you have to remember always. 

The structure of Java has 3 sections.

Package Declaration (optional)
Class Definition and Main Method
Functions (optional)

Java programming in more details

Some keywords and datatypes are as same as in the C language. The main change is the structure of the Java Programming language.

java programming tutorial

Let’s see.

//First Program of Java
public class HelloWorld
{
 public static void main(String[] args)
 {
  System.out.println(“HELLO”);
 }
}

Let’s discuss Class, before understanding the above code.

What are the ‘class’ and ‘objects’?

Let’s take an example first. The ‘car’ is a class and the Ferrari, Audi, Honda are the objects. Got it. No!, the classes are the template of objects, and the objects are the instance of the class.

If you don’t get it, don’t worry as you see the examples you will understand.

Now, let’s get back to our first code.

The first word of the first line is public which states that the members(keywords and functions) are accessible outside the class or in other words, the members are accessible to other classes.

We are going to see more access modifiers(keywords like public, private, protected) below.

The next word class is the keyword of java, which states that you are creating a class with a name HelloWorld.

Note: The class name always starts with a capital alphabet. You can use two words also like me, Hello World = HelloWorld.

The 2nd line start brace( { ) shows that the further statements are of the class.

In the 3rd line public static void main(String[] args), the public keyword is the access modifier keyword that we talked above, the static is also a keyword that saves unnecessary wastage of memory, the main keyword is the Java main method which is the start of the code and the void keyword shows that the main method not going to return any value. The String[] args stores the Java command-line argument.

The start brace( { ) after the main method shows the compiler that the code of the main method is between the start( { ) and the end( } ) brace.

The next line, System.out.println is the print statement for Java, in the above code, it is going to print HELLO.

The last two end braces( } ) shows that the main method and the class ends.

What are Access Modifiers?- Java programming

There are 3 access modifiers in Java.

Public, Private, Protected.

Access modifiers used with Members( variables, functions, objects) and classes.

  1. Public

If a class member is “public” then it will be accessible from anywhere. The member variable or method can be accessed globally.

  1. Private

If a class member is “private” then it will be accessible only inside the same class.

  1. Protected

If a class member is “protected” then it will be accessible only to the classes in the same package and to the subclasses.

How to get Input from the console?

There are several classes that are provided by Java already, that can be used to get input from the console.

BufferedReader

The BufferedReader is a class that is in-built in Java. We are going to get input from the system’s device i.e Keyboard, so, we have to specify it. Thus we have to use System.in objects.

Let’s understand by an example:

InputStreamReader isr =new InputStreamReader(System.in);

BufferedReader br = new BufferedReader(isr);

OR

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

Both the above statements are same.

BufferedReader and InpurStreamReader are constructors, a new keyword, to create constructors and objects. The isr and br are the variables that you can rename.

To read a string we will use the readLine method of the BufferedReader object.

String str = br.readline();

 
To input something other than String (int, float, etc) we have to convert the input(readLine) to that data type, i.e. we will use a parse function.

Note: To use the Input, we have to use I/O classes.

java access modifiers

Example:

//Console Based Input Output
import java.io.*;
public class ReadNumbers
{
 public static void main( String[] args) throws IOException
 {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  int num, sum=0, n, i;
  System.out.println(“How many nos:”);
  n= Integer.parseInt(br.readline());
  for(i=0;i<n;i++)
  {
   sum= sum+i;
  } 
  System.out.println(“Sum =” +sum);
 }
}

Here we used the BufferedReader in which we accept a number n and print the sum of all integers until that n occurs. Ex. if I enter 4 then the sum will be of 0+1+2+3+4 =10.

You can see I use parseInt because we have to convert the String to an integer so that we can perform the addition.

So, basically parse is the keyword and the next word that we attach is the data type.

Scanner

It is the easiest way to get input but it’s not efficient. It uses tokens to store the data of Input.

Below are the methods of this class that we can use in our program.

  1. hasNext():
  2. String next():
  3. boolean nextBoolean():
  4. byte nextByte():
  5. double nextDouble():
  6. float nextFloat():
  7. int nextInt():
  8. String nextLine():
  9. void close():

Example:

//Getting input with Scanner class:
import java.io.*;
Import java.util.Scanner;
class ScannerTest
{
 public static void main(String args[])
 {
  Scanner sc = new Scanner(System.in);
  System.out.println(“Enter your roll no and name:”);
  int rollno=sc.nextInt();
  String name = sc.next();
  System.out.println(“Rollno: “+rollno+” Name:”+name);
  sc.close();
 }
}

Conclusion

Here’s how you will going to code in Java. Again it’s just a percent, so, keep learning and practicing.

Btw, to learn Android App development you have to download Android Studio from Google’s Developer site and start by gaining knowledge of Android Apps structure on Android Developer’s official website.

FAQ

Q1. Is Java Programming software free?

Yes. It’s totally free.

Q2. What we can do with Java Programming?

We can develop Android apps, games, etc.

Q3. Is Java Programming hard?

Yes. But you can learn easily if you try and practice.

Q4. How much time should it take to learn full Java?

It’s up to you. You are able to learn most in just 2 months of regular practice, or it can take a year. You have to practice a lot of examples if you want to learn fast.

Q5. What’s the average salary of a Java developer in India?

It’s around 6 lakhs if you have 1/2 years of experience.

You completed the basics, it’s an achievement. Let’s get started with examples:- Java Examples & Functions for beginners

RELATED ARTICLES

How an Emergency Line of Credit Can Aid Your Financial Situation?

Whenever there is a financial emergency, people want quick funds to deal with the emergency. In order to cater to this, banks...

Things That Are Harming Your Credit Score

A credit score is a vital parameter to getting the best loan offers. A score of 630 or above is good enough...

The 10 Most Common Mistakes Made When Applying for a Business Loan

A business loan can be extremely useful for your business venture. Whether you are looking to obtain a working capital loan or...

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

How an Emergency Line of Credit Can Aid Your Financial Situation?

Whenever there is a financial emergency, people want quick funds to deal with the emergency. In order to cater to this, banks...

Things That Are Harming Your Credit Score

A credit score is a vital parameter to getting the best loan offers. A score of 630 or above is good enough...

The 10 Most Common Mistakes Made When Applying for a Business Loan

A business loan can be extremely useful for your business venture. Whether you are looking to obtain a working capital loan or...

Top Trading Techniques & Strategies Traders Should Know

There are a number of effective trading tactics you will come across when trading on the financial markets...

Recent Comments