Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Summary

Summary Java Basics with Codes

Rating
-
Sold
-
Pages
73
Uploaded on
03-03-2022
Written in
2021/2022

Java Basics with Codes. Very useful for beginners.

Institution
Course

Content preview

JAVA Object oriented programing language
Platform independent ( can run on any os)

RAM - Temporary Memory
JVM ( Java Virtual Machine ) - RAM has special area to execute java program
JVM has - > Heap Memory : Place where objects are created
- > Stack Memory : Reference to the object which is stored. Variables are also stored in it.




Object - It is an Instance of class ( Real implementation of class)
Object is created in the heap memory in jvm of ram
Object reference is created in stack memory of jvm of RAM

State of Object - At a particular time what data is holded by object
Behavior of object - What all it can do, the functions of object




Create an object :
Trainer t = new Trainer (nage, 1000, hyderabad ) - syntax
{class} {constructor}

Constructor :Constructor will go to class and check the number of variables, data type and how much
memory is required and give information to new operator
Initialize variables when creating objects. { to assign value to variables }




New : new operator will allocate memory for objects in heap .
t : reference variable { reference to object } . To invoke functionality of objects.
Stored in stack memory.

Dot operator - t.allskills();
To invoke functionalities of objects


Object have State and Behavior

,State : At a time what data object is holding
Behavior : Functionalities of object { what all it do }




output


Sample.java class file is created . And 1st phase is compilation phase, command used is javac
Sample.java. Os search for javac files.
And it will generate class file (Sample.class) - in form of byte code {low level language}
This compiled Sample.class file we can execute in any OS (windows,linux,mac…)- Platform
independent
And next is executional phase , byte code line by line will be interpreted (line by line execution
of code to convert code to machine code )



Data Types
Variable : Name to reserved memory location at which some value is stored.
Based on datatype, it will be decided :
● How much memory will be allocated
● Which type of value can be store

Data Types : define the kind of value the variables can hold. Based on data type memory will be
allocated
Primitive Types :




–classes

-data types




Signed Number : can store both positive and negative number and 0
2^8 = 256 -> [ -128 to 127]
Unsigned Number : can store only non negative number
Eg : 0, 62, 827

,2^8 = 256 -> [ 0 to 255]

Memory Occupy by data types :
Int - 32 bit, char - 16 bit, double - 64, long - 64 , short - 16, byte - 8, float - 8 , boolean - 1 bit



Coding
First program
package firstprogram;

public class firstprogram {

public static void main(String args[]) {
System.out.println("Welcome to java training");
}
}




2 class in same package
If classes are in same package :




package firstprogram;
public class secondprogram {

int i = 10;
public void test() { //create test method
System.out.println(i);
}

public static void main(String args[]) {
secondprogram s = new secondprogram(); //call method by create instance
s.test();
}

}

, Different Package
If Custom class is in different package :

Test :
package package1;
import package2.Custom; // import custom class from package2
public class Test {
public static void main(String args[]) {
Sample s = new Sample(); //call method by create instance
s.test(); 1.
Custom c = new Custom(); 3.
c.verify();
}
}

Sample :
package package1;

public class Sample{
int i = 10;
public void test() { 2.
System.out.println(i);
}
}

Custom :
package package2;

public class Custom {
public void verify() { 4.
System.out.println("this is verify method");
}
}


Global Variables
Global Variables - Variables which are declared inside class but outside method
Local Variables - Variables which are declared inside method

Global variables may or may not be initialized
Local variables must be initialized. Else error.

package com.thirddatatypes;
public class sample{
int i = 10;
int j; // not assigning any value to j, but printing value default 0 { global variable }

public void test() { //method

Written for

Course

Document information

Uploaded on
March 3, 2022
Number of pages
73
Written in
2021/2022
Type
SUMMARY

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
aardra

Also available in package deal

Get to know the seller

Seller avatar
aardra amrita
Follow You need to be logged in order to follow users or courses
Sold
3
Member since
4 year
Number of followers
3
Documents
3
Last sold
3 year ago

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions