top of page
Search
  • Writer's pictureHarshit Sharma

INTRODUCTION TO JAVA

“Java refers to a number of computer software products and specifications from Sun Microsystems (the Java™ technology) that together provide a system for developing and deploying cross-platform applications. Java syntax borrows heavily from C and C++ but it eliminates certain low-level constructs such as pointers and has a very simple memory model where every object is allocated on the heap and all variables of object types are references.

OOP is a particular style of programming that involves a particular way of designing solutions to particular problems. Most modern programming languages, including Java, support this paradigm. When speaking about OOP one has to mention:

 Inheritance

 Modularity

 Polymorphism

 Encapsulation (binding code and its data)


The Java Development Kit – JDK

In order to get started in Java programming, one needs to get a recent copy of the Java JDK. This can be obtained for free by downloading it from the Sun Microsystems website, http://java.sun.com/ Once you download and install this JDK you are ready to get started. You need a text editor as well and Microsoft’s Notepad (standard with all Windows versions) suits fine.


My first Java program

Open your text editor and type the following lines of code:

/* My first program Version 1 */

public class Example1 { public static void main (String args [])

{ System.out.println ("My first Java program");

}

}


In java every line of code that actually can run needs to be inside a class.

Public:anyone can access it

Save the file as Example1.java2. The name of the program has to be similar to the filename. Programs are called classes. Please note that Java is case-sensitive. You cannot name a file “Example.java” and then in the program you write “public class example”. It is good practice to insert comments at the start of a program to help you as a programmer understand quickly what the particular program is all about. This is done by typing “/*” at the start of the comment and “*/” when you finish. The predicted output of this program is:

In order to get the above output we have to first compile the program and then execute the compiled class. The applications required for this job are available as part of the JDK:

· javac.exe – compiles the program

 java.exe – the interpreter used to execute the compiled program


In order to compile and execute the program we need to switch to the command prompt. On Windows systems this can be done by clicking Start>Run>cmd


At this point one needs some basic DOS commands in order to get to the directory (folder), where the java class resides:

 cd\ (change directory)

 cd\[folder name] to get to the required folder/directory


When you get to the required destination you need to type the following: c:\[folder name]\javac Example1.java The above command will compile the java file and prompt the user with any errors. If the compilation is successful a new file containing the bytecode is generated: Example1.class To execute the program, we invoke the interpreter by typing: c:\[folder name]\java Example1 The result will be displayed in the DOS window.,

1 view0 comments

Recent Posts

See All

Commentaires


Post: Blog2_Post
bottom of page