Introduction to JAVA

Introduction to JAVA

In this tutorial you will learn: 1. Setting up the Programming Environment 2. Setting up IDE 3. Basic JAVA Overview 4. Basic JAVA console Program Before starting coding you need to first setup the environment for coding. For that first go to Google and download JAVA development kit (JDK). Using this link. Download JDK After downloading you simply need to install the JDK. To check if JDK has been installed you simply need to open CMD by first opening RUN (windows+r) and then typing CMD. In CMD you simply need to write Java then press ENTER. If you see some output then you are on the right track do the same step by writing Javac if you see some output then JDK has been successfully installed. After installing JDK simply download ECLIPSE using this link Download Eclipse IDE for JAVA Devlopers Now open eclipse and create your workspace and you are good to go. Basic JAVA Overview: The first thing that you need to learn are the basic data types which are same in java like in other programming languages. • Data types: 1. Int stands for integer e.g int x =5; 2. Float stands for float e.g int y = 4.5; 3. Char stands for char e.g int c = ‘m’; 4. Double stands for double e.g double d = 4.222233 5. String stands for Strings e.g String s = “MyJAVA”; • Class, Object and Methods These are 3 basic things that you need to learn in order to learn any object oriented language and Java is an object oriented programming language. What is a class and what are its attributes and methods? A set or category of things having some property or attribute in common and differentiated from others by kind, type, or quality. A class contains attributes, methods and a main function (optional) For example: Student is a class Student_name, age, id will be its attributes and  getData(), getAge(), setAge() will be its methods Now Student s1 this will be an object of the student class. Each object will have specific attributes and methods. Basic Java console program: Open Eclipse > Workspace File > new > java project File > new > class (Name it MyJava) Write the following program
  1. import java.util.*;
  2. public class MyJava
  3. {
  4. /** To demonstrate the basic structure of a Java program
  5. */
  6. public static void main ( String args [ ] )
  7. {
  8. /* I am inside main . Execution always starts from
  9. method main in Java applications */
  10. System.out.println ( "Hello JAVA" ) ;
  11. }
  12. }
Note: The name of your public class should be the same as your class name. First thing you need is the import statement which will include many of java functions in your program. You can read more about java.util in oracle documentation. Write the main method as is for now you will understand more about it when we will study methods. Now inside the main is where you will write all your code. Any code here will be the output of your program. Println(“”); is a function which can print any string you pass inside it.Which in this case is simply Hello JAVA. output We will learn more coding from next tutorials. If you have any questions or want to learn programming from me simply add me on Skype Username: mkprogrammer2121

Add new comment