Core Java Basics

                 ——————————- Good Luck Friends ———————————————

Blog is Absolutely for freshers 

Working model of Java Environment;-

2

 

What is Java?

1) Java is a programming language which is used for developing so many applications and programs in various industry.

2)  it’s an Object Oriented Programming Language (oop’s).

3) Java is also a platform Independent language ie you can write code in one OS and can run same compiled code in another OS.

4)  Java supports millions library classes which you can be imported while coding. These libraries provide billions of methods and these methods help programmer to develop a well optimized and readable code.

5) Introduced by james gosling in sun Microsystems

6) JAVA is not a acronym, it is just a word

7) It was released on 1996 in the name of OAK

8) The next name is green, this name also not popular

9) Finally they named it as JAVA

10) in 2010 oracle bought sun Microsystems.

 

JDK Download link;-

http://www.oracle.com/technetwork/java/javase/downloads/index.html

Download and install it.

 

Java logo ;-  

sd1
The logo is coffee cup and saucer
 

 

Note:

Free software:

              We just download and use it and we can’t modify the coding

Open source:

               User can modify the coding with the rules mentioned in license.

 

What is JDK? 

JDK (Java Development Kit)

1)      Java Developer Kit contains tools needed to develop the Java programs

2)      Tools—JVM(Java Virtual Machine), JRE(Java Runtime Environment ), library files, java, javac , bin(binary)

 

How to check if Java is available in your system?

Open CMD prompt – Type “java -version” then press Enter key.

3

ERROR: if java not installed

          Java can’t be recognized as internal or external command.

 Reason: java is not installed or path is not set

To set environment path:

Environment variable PATH should be set to point to where the java binaries have been installed.

Open java bin folder in the installed path, copy the path then go to my computer—right click  system properties—advanced system settings—-environment variables—select path in system variables and click on edit then put semicolon(;) and paste it.then  check the same.  (Open CMD prompt – Type “java -version” then press Enter key.)

 

To write program: 

a)      Use editor s/w

Notepad, notepad++, textpad, editplus

b)      IDE (integrated development environment)

Jdeveloper, Netbeans, Eclipse, intelliJ idea

 

How Software works on hardware:-

1

High Level Languages

The term programming language usually refers to high-level languages

1)      HLL stands for High Level Language

2)      The language which human can understand

Machine Language
The lowest-level programming language

Machine languages are the only languages understood by computers.

  0,1s – just binary’s.

Assembly Language(mnemonic code)

low-level programming language

intel 8085,8086,8088  – these are micro precessors, Ex Mov a,b

 

 

JVM (Java Virtual Machine)
As we all aware when we compile a Java file, output is not an ‘exe’ but it’s a ‘.class’ file. ‘.class’ file consists of Java byte codes which are understandable by JVM. Java Virtual Machine interprets the byte code into the machine code

Note:

The programs written in java has to be saved in a file with the extension .(dot)java. This file is known as code. Source code(.java file) is fed to java compiler. The java compiler converts the source code into an executable format known as the byte code. The byte codes are saved in a file with extension .(dot)class.

   The class files (.class) are automatically generated by the java a compiler. The JVM understands only byte code hence where ever JVM is available class files can be executed.

Java c                compilation= Javac javafilename.java

Java                   execution= Java classfilename

The source code written inside java file are converted into byte code (class file)  using by a command javac.the javac command is available in the bin folder where java is installed.

Syntax:              C:\Javac Demo.java

Command  javafilename

After compilation the class file are generated in the default location where source code is available. The class file can be executed by using a command java.this command also in bin folder.

Syntax:               C:\Java Demo

Command  classfilename

Note: while running the class file dot(.)class extension should not be specified.

CLASS;-

Class is a template. It contains/fields and methods

Syntax:              Class Name{

                                    Body of the class

                                    }

Methods (perform an operation)

Variables(stores information)

4

Definition for class;-

Class can be defined as a blueprint/template to create an object. A class specifies the design of an instance of the class.

Object:

It states what data an object can hold and way it can behave.

Scope of Objects:

• Java objects don’t have the same lifetimes as primitives.
• When you create a Java object using new, it hangs around past the end of the scope.
• Here, the scope of name s is delimited by the {}s but the String object hangs around  until GC (Garbage collector)
{

String s = new String(“a string”);

} /* end of scope */

 

Members of class:

Variables:

There are properties of the class or object we are going to create.

Ex: if we creating the class called ear then they have property like model,color,seats,category etc..

In a simplified way it can said as variables which holds values.

Methods:

Behavior of the action that can be performed by the object or a class.

Technical:

A method is a code which is referred to name and can be called [invoked] at any point in a program simply by utilizing the methods’s name. Method can return a value. It represents the behavior of the class or object.

Program:

Class Demo{

                        public static void main(string args[])

{

function(”java”+”and”+”selenium”)

}

}

+ operator is known as concatenation operator which is used to join any two string or variable values.

  • Class names must begin with a letter an underscores or a dollar sign.
  • Class name may contain only letters,digits,underscores and /or dollar signs.
  • Class names cannot use reserved words it cannot have space between words.
  • Class names cannot have space between words.

Java comments:

Comments are used for identification purpose of the program and the programmer.

Single line comment =//

// This kind is to the end of the line or text is the format for single line commenting.

Multi line comment=/*         */

/* This kind of comment can span multiple lines */

Documentation comment=/** it is on top of pgm.

/**
* This kind of comment is a special
* ‘javadoc’ style comment
*/

Sample Project Folder; Using Eclipse 

5

 

 

 

After creating a java project from Eclipse then what happens?

Let’s discuss about the Project folder from eclipse workspace. 

6

.java file contains original source code writtern by user.

.class file contains bytecode , this can be understood by JVM

Example: 

Consider the following Java code:

.java file (below code presents in .java file)

outer:
for (int i = 2; i < 1000; i++) {
for (int j = 2; j < i; j++) {
if (i % j == 0)
continue outer;
}
System.out.println (i);
}

byte code for the above program:

0: iconst_2
1: istore_1
2: iload_1
3: sipush 1000
6: if_icmpge 44
9: iconst_2
10: istore_2
11: iload_2
12: iload_1
13: if_icmpge 31
16: iload_1
17: iload_2
18: irem
19: ifne 25
22: goto 38
25: iinc 2, 1
28: goto 11
31: getstatic #84;       
34: iload_1
35: invokevirtual #85;   
38: iinc 1, 1
41: goto 2
44: return

for more info https://en.wikipedia.org/wiki/Java_bytecode

What is Package ?

  •  To group a related class and interface into one unit 
  • To resolve the name conflicts between class names

Major usage of Packages;-

Importing classes from one into another package, to reusing the existing functions.

import is a keyword in java.

How to import a class using package name:

single class import:

    import  packageName.className ;

Include all the classes in package:

import  packageName.*;

How do you say java is platform independent?

             Ans:    Compile into class file anywhere(any machine) and run it on any machine which has JVM.

 

will update soon—>

WordPress.com.

Up ↑