Java Programming

Java Programming


When you start learning a new language, you fear a lot thinking how much trouble to face and concentration is required, as this is the impression left by C/C++ while you learnt. Remember one thing, Java Designers always aim only two things while developing the language – how to make language simple to learn and practice and how to increase the performance. You believe this when you start learning Java programming.

Java comes with many features like Platform-independent, Multithreaded and Internet-based etc. Java is easy to practice due to non-support of pointers. Developer need not bother about memory management as is implicit in Java. For this reason, Java does not include functions like sizeof(), malloc(), calloc() and free() etc. Java does not have Destructors but Constructors exist.

Java Programming constructs include Classes, Interfaces, Methods, Constructors and Variables like a House constructs are Bricks, Cement and Sand etc.

The basic unit of Java programming is class. All the code you write should be placed within the class declaration only. That is, outside the class you are not allowed to write anything. The class declaration starts with a open brace and ends with a close brace.

See the following code on Java programming. Then we will discuss further.

Java ProgrammingOutput Screenshot on Java Programming

To compile a program, Java does not require main() method. But to execute, main() is required. As I want to compile and execute the above program, I included main(). The code includes two variables, one constructor, one method and finally main(). Observe, the whole code in included within the open and close braces of the class which Java demands.

import java.lang.*;

It is equivalent to include statement of C-lang. java.lang is known as package equivalent to a header file of C-lang. A package contains classes and interfaces. The classes we use of this package in our code are String and System.

Student std1 = new Student();

std1 is known as object of Student class. Infact, an object in Java is a handle to access the constructs of the class. With std1, the method display() is called. It comes with two parameters of n1 and m1. The method parameters of a method are always treated as local variables as in C/C++. The local variables are assigned to instance variables name and marks. When assigned, the instance variables (known as global variables in C/C++) gets values and can be used from any part of the class. Infact, they are used in main().

Here, I discussed very briefly withtout explaining keywords used, syntax of creating an object, encapsulation, process of compilation and execution etc. Go through the following links in the same order to land smoothly in Java.

Following links give you an easy understanding of coding in Java. The examples are precise, easy and answer to the point.

1. OOPS concepts Tutorial
2. Java Example Compilation Execution
3. Java Local Instance Variables
4. Data Binding Data Hiding Encapsulation

Leave a Reply

Your email address will not be published. Required fields are marked *