Skip to main content

Posts

Showing posts with the label Java Basics

Data types in Java

Not everything in Java is an object. There is a special group of data types (also known as primitive types) that will be used quite often in programming. For performance reasons, the designers of the Java language decided to include these primitive types. Java determines the size of each primitive type. These sizes do not change from one operating system to another. This is one of the key features of the language that makes Java so portable. Java defines eight primitive types of data: byte, short, int, long, char, float, double, and boolean. 1) primitive data types 2) non-primitive data types Types Size Default Range Example boolean 1 bit false NA boolean b = true; Char 16 bits \u0000 \u0000 to \uFFFF char c = 'A'; Byte 8 bits 0 -128 to 127 byte b = 60; Short 16 bits ...

My first java program

To write a Java program we have to create a class . -> To create a class, right click on the package (Make sure you should right click on package,because you are creating class inside a package). -> Go to New . -> Click on Class .   -> In New Java Class window, enter class name in Name text box. -> If you want main method in your class click on Finish or uncheck on public static void main(String[] args) check box then click on  Finish  . -> Now write your java program. -> To run your program click on Run menu. Go to Run As , click on Java Application . -> Output will display in Console .

How to create package inside a project?

What Is a Package? A package is a namespace that organizes a set of related classes and interfaces. Conceptually you can think of packages as being similar to different folders on your computer. You might keep HTML pages in one folder, images in another, and scripts or applications in yet another. Because software written in the Java programming language can be composed of hundreds or thousands of individual classes, it makes sense to keep things organized by placing related classes and interfaces into packages. -> Right click on the Project (Make sure you should right click on project, because you are creating package inside the project). -> Go to New. -> Click on Package. -> In New Java Package window, enter package name in Name text box. -> Now click on Finish . -> Now you can see the package inside the project at Project Explorer area. Now your package is ready.

How to create Project in eclipse?

-> After open the new workspace, eclipse displaces welcome page . Close the welcome page.  Eclipse welcome page -> Now right click on Project Explorer area at left side of eclipse.   -> Go to  New , click on Project .   -> In New Project window, click on Java Project . -> Now click on Next . -> In New Java Project window, enter your project name in Project name text box. Now click on Finish . -> After click on Finish, in Open Associated Perspective? window click Yes or No . After that Make sure your perspective should be either Java or Java EE . Here i am using Java EE Perspective.   -> Here if you click Yes it opens Java Perspective, if you click No it opens Java EE Perspective. Because default Perspective is Java EE. -> We can change Perspective by clicking on Java, Java EE icons at top right. You have created project successfully. 

How to create workspace in eclipse?

We have to create workspace to save our java files. -> Double click on the eclipse. -> You can choose any workspace using browse button . -> Click on OK after select the workspace. -> Now eclipse editor will launch to write scripts.

How to download and open Eclipse editor?

Eclipse is an integrated development environment (IDE). It contains a base workspace and an extensible plug-in system for customizing the environment. Written mostly in Java, Eclipse can be used to develop applications. Eclipse is a platform that has been designed from the ground up for building integrated web and application development tooling. By design, the platform does not provide a great deal of end user functionality by itself. The value of the platform is what it encourages: rapid development of integrated features based on a plug-in model. Download the latest version of the eclipse from here . After download, extract the files. Now in eclipse folder click on eclipse application to open the eclipse.  Eclipse is not a .exe file.

How to install Java?

Download the latest version of the Java JDK from here .   Click on Accept License and choose 32-bit or 64-bit for windows. Double-click on the install file and click on next up to install the java. Now open command prompt window , type "java -version" and press enter.   Java installed but we should set the Environment Variables. How to set Environment Variables?  Right click on My Computer -> Click on Properties In Property window click on Advanced system settings .   In System Properties window click on Environment Variables .   In Environment Variables window, click on path in System variables section.   Now click on Edit. Careful not to delete anything in this box. At the end of the text box, add a semi-colon if there is not one already, and add "C:\Program Files (x86)\Java\jdk1.8.0_05\bin\;" to the text box. This is assuming you did not change the file path of the installat...

Why java is platform independent?

 Java programming language provides platform independence, what does it mean ? It means same java program can be run on any platform or operating system e.g. Windows, Linux or Solaris without any change. This is the great benefit for some one coming from platform dependent programming language like C or C++ whose code needs to be ported for every single platform because they use native libraries which differ in every platform. Now question comes how Java achieve platform independence, what makes Java programs running on every platform without any change ? This is one of the most basis question java programmer ask when it start learning java programming language. if you read further you will come to know about byte code and Java virtual machine which together provides platform independence to Java. For those who don't know Java is both compiler and interpreter language. When you compile a Java program it creates .class file which is collection of byte code, these byte code are not...