Apex vs Java. Ethnus Codemithra article cover.

What is Apex and how it differs from Java

Codemithra Team

Codemithra Team

Apex looks like Java at first glance. Salesforce's own Trailhead guide to Apex calls it a language with "Java-like syntax" built on "familiar Java idioms". But Apex is a separate, hosted language. It runs only inside the Salesforce Platform, with database access and per-transaction limits built into the language itself. Your Java knowledge of classes, interfaces and control flow carries over. The execution model, the database access style and the per-transaction rules do not.

Apex vs Java. Ethnus Codemithra article cover.

What actually carries over from Java

Apex is object-oriented in the same way Java is. Trailhead states plainly that "Apex supports classes, interfaces, and inheritance". If you already think in classes, interfaces and inheritance, that structure still applies in Apex.

The block syntax is familiar too. Curly braces, semicolons, if and for statements, and method signatures all read the way they do in Java. Salesforce frames Apex as built on "familiar Java idioms," not as an unrelated language. You do not need to relearn your instinct for structuring a program.

Concrete syntax and behaviour differences

The differences start small, but they catch a Java developer off guard. Java treats myAccount and MyAccount as two different names. Apex does not. Trailhead confirms that "Apex is a case-insensitive language". A variable and a type that differ only in case can clash in Apex. That never happens in Java.

The bigger differences are structural. The table below lists the five that matter most when you move from writing Java to writing Apex.

Apex vs Java, at a glance. Java is case-sensitive: Apex is case-insensitive. JVM, on any machine: Hosted only on the Salesforce Platform. JDBC or an ORM library: Inline SOQL and DML in the language. None at language level: Governor limits: 100 sync SOQL, 150 DML, 200 trigger records. No built-in requirement to deploy: Platform enforces 75% Apex coverage before deploy
Aspect Java Apex
Case sensitivity Case-sensitive Case-insensitive
Where it runs Any machine with a JVM Hosted, saved, compiled and run on the Salesforce Platform
Database access A separate driver or ORM, such as JDBC or Hibernate SOQL and DML embedded directly in the language
Per-transaction limits None at the language level Governor limits: up to 100 synchronous SOQL queries and 150 DML statements per transaction
Deployment test-coverage gate No built-in requirement to compile or run At least 75 percent of Apex code must pass test coverage before deployment

Look closely at the database row. In Java, reading a record means opening a connection and writing SQL as a string. You map the result back into objects yourself, or you configure an ORM to do it. In Apex, a SOQL query sits inside square brackets as part of the code itself. For example: Account[] accts = [SELECT Name, Phone FROM Account]. Trailhead's page on querying records with SOQL notes that "you can embed SOQL queries in your Apex code and get results in a straightforward fashion."

Data manipulation works the same way. Statements such as insert, update, upsert, delete, undelete and merge are part of the language, not library calls. Trailhead's guide to DML points out that Apex removes "additional setup to connect to data sources" that other languages need.

Why Apex has governor limits at all

Governor limits are the part of Apex with no real Java equivalent. Trailhead's module on bulk design patterns explains that "Apex runs in a multitenant environment". The limits make sure "runaway code doesn't monopolize resources on the multitenant platform". Many organisations run their code on the same shared Salesforce infrastructure at the same time. No single transaction gets to run unchecked.

Two figures are worth remembering. Synchronous Apex allows up to 100 SOQL queries and up to 150 DML statements in one transaction. A second Trailhead page on execution context repeats the same figures independently. That same page adds that an Apex trigger "can receive up to 200 records at once". A Java web handler processes one request at a time. It has no such ceiling to plan around. Apex code does.

Why Apex enforces limits that Java does not. Shared infrastructure: Many organisations run their Apex code on the same Salesforce servers at once. Then One transaction fires: A trigger or class executes inside a single Apex transaction. Then Runtime checks limits: The platform checks the transaction against governor limits as it runs: up to 100 synchronous SOQL queries, 150 DML statements. Then Batches, not single records: A trigger can receive up to 200 records at once, so code written for one record fails against a real batch.

A minimal code comparison

The same task, fetching a customer's phone number, looks different in each language. The Java side below is a short JDBC-style sketch, not a complete program.

// Java, illustrative JDBC-style call
String sql = "SELECT phone FROM accounts WHERE name = ?";
PreparedStatement stmt = connection.prepareStatement(sql);
stmt.setString(1, "Acme");
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
    String phone = rs.getString("phone");
}
// Apex, inline SOQL, no separate connection setup
Account[] accts = [SELECT Name, Phone FROM Account WHERE Name = 'Acme'];
if (!accts.isEmpty()) {
    String phone = accts[0].Phone;
}

Writing records shows the same contrast. A bulk-safe Apex insert acts on a list. It does not loop through one record at a time:

// Apex, bulk-safe DML on a list of records
List<Account> accountsToUpdate = new List<Account>();
for (Account acc : [SELECT Id, Rating FROM Account WHERE Rating = null]) {
    acc.Rating = 'Warm';
    accountsToUpdate.add(acc);
}
update accountsToUpdate;

These snippets are teaching examples. They illustrate the syntax difference, not a specific Ethnus lab exercise.

The practical habit Apex requires that Java web code doesn't

A trigger can receive up to 200 records in one call. So Apex trigger code has to assume a batch from the first line, not a single record. Place a SOQL query or DML statement inside a loop over the trigger's records, and it runs once per record. With 200 records, that can burn through the 100-query or 150-DML ceiling before the transaction finishes.

Bulkified code avoids this. Move queries and DML statements outside the loop. Collect the work into lists, then run one query and one DML statement against the whole batch. Trailhead describes this style as code that "can process large numbers of records efficiently and run within governor limits". A Java servlet handling one HTTP request rarely needs this discipline. It is not routinely handed 200 records inside a single method call. Apex trigger code is.

Try this today: take any Apex trigger sample with a query or DML statement inside a loop. Rewrite it so the query runs once before the loop. Run the DML statement once after the loop, on a list. That single change separates code that works on one test record from code that survives a 200-record data load.

Testing is a deployment gate, not just good practice

In Java, you can compile and run code with zero test coverage. Nothing in the language stops you. Apex is different. Trailhead's module on Apex testing states that "at least 75% of Apex code must be covered by tests, and all those tests must pass". It adds that every trigger needs "some coverage". Salesforce's own help documentation confirms the same figures for a production deploy. That figure is at least 75 percent unit test coverage, with "at least one line of test coverage" on every trigger.

Salesforce enforces this before code reaches production. It is not a suggestion. A Java project can add a coverage check to its build pipeline. A team has to configure that check itself. Apex works differently. The Salesforce Platform checks the 75 percent threshold and the per-trigger coverage directly, at the point of deployment.

Where this fits an Ethnus learning path

Say you already have Java fundamentals, for example from Ethnus's JaWEsome course. It runs "160+ Hours" and covers Core Java topics such as "Datatypes (with memory allocation), Variables, Operators". A second module covers object-oriented programming: classes, encapsulation, packages, inheritance and polymorphism. That syntax groundwork carries straight into Apex. What JaWEsome does not cover is the Salesforce-specific half: SOQL, DML, governor limits and the deployment test-coverage gate above.

The Codemithra courses page describes its Salesforce Developer course as "authorised by Salesforce". It lists the course at ₹35,999. The listing shows 654 students enrolled and a 4.6 rating. For a reader who already writes Java, this is the natural next step. It builds on your object-oriented instincts. It then adds Apex's hosted execution model, inline SOQL and DML, and its governor limits and coverage rules.

Conclusion

Apex reads like Java. Classes, interfaces, inheritance and familiar block syntax all carry over directly. What does not carry over is the execution model. Apex is case-insensitive, runs only on the Salesforce Platform, and embeds SOQL and DML directly in the language. It also enforces governor limits on every transaction and blocks production deployment below 75 percent test coverage. Bulk-safe code and the coverage gate separate "code that looks like Java" from code built for a multitenant platform.

Start with Ethnus's Salesforce Developer course if you already have Java fundamentals and want to build on them directly. Start with JaWEsome first if your Java is still developing.

Frequently asked questions

Is Apex a version of Java?

No. Apex uses Java-like syntax and idioms, but it is a separate language. Salesforce saves, compiles and runs it on its own platform, not on a general-purpose JVM, according to Trailhead.

Can I run Apex code outside Salesforce?

No. Apex is hosted. Salesforce saves, compiles and executes it on the server, the Salesforce Platform. It does not run as a standalone program the way a Java application does.

What happens if my Apex trigger only handles one record at a time?

It can pass a quick test and still fail once real data arrives. A trigger can receive up to 200 records in one call. A query or DML statement placed inside a per-record loop can then exceed the transaction's governor limits.

Do I need 100 percent test coverage to deploy Apex code?

No. The requirement is at least 75 percent of Apex code covered by passing tests. Every trigger needs some coverage too, before deployment to production.

Should I learn Java before learning Apex?

It helps. Apex follows familiar Java idioms for its structure and block syntax. Existing Java fundamentals cut down what you need to learn about basic syntax. You can then focus on Apex-specific ideas such as SOQL, DML and governor limits.

About the Author

Read More

Ethnus User Agreement

I agree to submit my personally identifiable information to Ethnus, who may use it to communicate regarding their events, courses, and other services through various media including phone calls, text messages, email, and social media. I also agree with Ethnus' Privacy Policy and Terms of Service.

I agree with Ethnus sharing my personal data, including email address, with Salesforce family of companies, who may contact me for sales and marketing purposes and as described in Salesforce's Privacy Statement.

Privacy Policy

This Privacy Notice describes how we collect and use your personal information in relation to Ethnus websites, applications, products, services, events, and experiences that reference this Privacy Notice (together, "Ethnus Offerings").

This Privacy Notice does not apply to the "content" processed, stored, or hosted by our customers using Ethnus Offerings in connection with an Ethnus account. This Privacy Notice also does not apply to any products, services, websites, or content that are offered by third parties or have their own privacy notice.

Personal Information We Collect

We collect your personal information in the course of providing Ethnus Offerings to you.

Here are the types of information we gather:

        a) Information You Give Us: We collect any information you provide in relation to Ethnus Offerings. Click here to see examples of information you give us. Example: Name, email, phone, etc.

        b) Automatic Information: We automatically collect certain types of information when you interact with Ethnus Offerings. Example: IP address, location, browser identity, etc.

        c) Information from Other Sources: We might collect information about you from other sources, including service providers, partners, and publicly available sources. Example: marketing analytics, keywords, etc.

How We Use Personal Information

We use your personal information to operate, provide, and improve Ethnus Offerings. Our purposes for using personal information include:

        a) Provide Ethnus Offerings: We may use your personal information to provide and deliver Ethnus Offerings and process transactions related to Ethnus Offerings, including registrations, subscriptions, purchases, and payments.

        b) Measure, Support, and Improve Ethnus Offerings: We use your personal information to measure use of, analyze the performance of, fix errors in, provide support for, improve, and develop Ethnus Offerings.

        c) Recommendations and Personalization: We use your personal information to recommend Ethnus Offerings that might be of interest to you, identify your preferences, and personalize your experience with Ethnus Offerings.

        d) Comply with Legal Obligations: In certain cases, we have a legal obligation to collect, use, or retain your personal information.

        e) Communicate with You: We use your personal information to communicate with you in relation to Ethnus Offerings via different channels (e.g., by phone, email, chat) and to respond to your requests.

        f) Marketing: We use your personal information to market and promote Ethnus Offerings. We might display interest-based ads for Ethnus Offerings.

        g) Purposes for Which We Seek Your Consent: We may also ask for your consent to use your personal information for a specific purpose that we communicate to you.

Cookies

To enable our systems to recognize your browser or device and to provide Ethnus Offerings, we use cookies.

How We Share Personal Information

Information about our customers is an important part of our business and we are not in the business of selling our customers' personal information to others. We share personal information only as described below and with Ethnus Consultancy Services Private Limited, . and its affiliates that are either subject to this Privacy Notice or follow practices at least as protective as those described in this Privacy Notice.

Transactions Involving Third Parties: We make available to you services, software, training, and content provided by third parties for use on or through Ethnus Offerings. You can tell when a third party is involved in your transactions, and we share information related to those transactions with that third party. For example, you can order services, software, and content from sellers using the Authorized Training Partner's marketplace and we provide those sellers information to facilitate your subscription, purchases, or support.

Other than as set out above, you will receive notice when personal information about you might be shared with third parties, and you will have an opportunity to choose not to share the information.

How We Secure Information

        a) We protect the security of your information during transmission to or from websites, applications, products, or services by using encryption protocols and software.

        b) We maintain physical, electronic, and procedural safeguards in connection with the collection, storage, and disclosure of personal information.

Internet Advertising and Third Parties

Ethnus Offerings may include third-party advertising and links to other websites and applications. Third party advertising partners may collect information about you when you interact with their content, advertising, or services. For more information about third-party advertising, including interest-based ads, please read our Interest-Based Ads notice.

Access and Choice

You have choices about the collection and use of your personal information. Many Ethnus Offerings include settings that provide you with options as to how your information is being used. You can choose not to provide certain information, but then you might not be able to take advantage of certain Ethnus Offerings.

        a) Communications: If you do not want to receive promotional messages from us, please unsubscribe or adjust your communication preferences in the emails.

        b) Advertising: If you don't want to see interest-based ads, please adjust your Advertising Preferences.

        c) Browser and Devices: The Help feature on most browsers and devices will tell you how to prevent your browser or device from accepting new cookies, how to have the browser notify you when you receive a new cookie, or how to disable cookies altogether.

Children's Personal Information

We don't provide Ethnus Offerings for purchase by children. If you're under 18, you may use Ethnus Offerings only with the involvement of a parent or guardian.

Retention of Personal Information

We keep your personal information to enable your continued use of Ethnus Offerings, for as long as it is required in order to fulfill the relevant purposes described in this Privacy Notice, as may be required by law (including for tax and accounting purposes), or as otherwise communicated to you. How long we retain specific personal information varies depending on the purpose for its use, and we may delete your personal information in accordance with applicable law.

Contacts, Notices, and Revisions

If you have any concern about privacy at Ethnus, you may also contact us at the addresses below:

Ethnus Consultancy Services Pvt Ltd,

SST Chambers, No.151/17/1 Second Floor, 36th Cross Rd, 5th Block, Jayanagar, Bengaluru, Karnataka 560041

Or, email us at [email protected]

Or call us at: +91 - 8929 334 324

You will find the updated contact information on our website: www.ethnus.com/contact/

If you interact with Ethnus Offerings on behalf of or through your organization, then your personal information may also be subject to your organization's privacy practices, and you should direct privacy inquiries to your organization.

Our business changes constantly, and our Privacy Notice may also change. You should check our website frequently to see recent changes. You can see the date on which the latest version of this Privacy Notice was posted. Unless stated otherwise, our current Privacy Notice applies to all personal information we have about you and your account. We stand behind the promises we make, however, and will never materially change our policies and practices to make them less protective of personal information collected in the past without informing affected customers and giving them a choice.

Terms & Conditions

This Privacy and Security Policy is provided for the benefit of customers and clients of Ethnus Consultancy Services Private Limited. ("Ethnus") as well as other consumers and parties who use Ethnus and/or its website(s), particularly codemithra.com ("Website", "www.codemithra.com", "Codemithra" or "Ethnus Codemithra"), and/or applications ("Apps") (collectively, "Ethnus Services" or "Ethnus Platform").

Since Ethnus serves several different audiences, customers find it helpful to read the Terms of Use that apply specifically to them based upon the purpose for which they use Ethnus. For this reason, we link to three separate agreements below for employer customers, job seeker customers, and staffing customers, respectively.

For your convenience, we define each of these audiences that Ethnus serves as follows:

"Employer Customer" means an entity using Ethnus Services that is seeking to hire an individual as an employee and/or independent contractor to be employed by it directly.

"Job Seeker Customer" means an individual using Ethnus Services who is seeking to be employed as an employee or independent contractor by an employer.

"Staffing Customer" means a staffing company using Ethnus Services that provides staffing services to their own Staffing Clients.

So long as your use of the Ethnus website and services remains within the scope of the particular audience or customer for which you began using Ethnus (e.g. a job seeker does not use Ethnus as an employer, or an employer does not use Ethnus as a job seeker), the complete Terms of Use applicable to your use of the Ethnus website and services is contained within the applicable Terms of Use linked below.

Employer Terms of Use

The following Terms of Use apply to any Ethnus Employer Customer seeking to hire employees or independent contractors for its own business. If you seek to find employees or independent contractors for the benefit of your clients (and not yourself), you need to review the Terms of Use specifically for our Ethnus Staffing Customers accessible at www.Codemithra.com/terms/staffing.

Ethnus, Inc. ("Ethnus") provides online services through which employers and staffing companies seeking employees and independent contractors can efficiently and effectively review and interview candidates. Ethnus provides these services and its suite of features and products through its Apps and Website (collectively, "Ethnus Services") subject to these terms of use ("Terms of Use") and the agreements incorporated herein.

Your privacy is very important to us. We designed our accompanying Privacy and Security Policy to provide important disclosures about how your information will be used by Ethnus in providing you Ethnus Services. These Terms of Use expressly incorporate our Privacy and Security Policy.

Please read these Terms of Use and our Privacy and Security Policy carefully before using any of the diverse Ethnus Services. By visiting the Website, installing any of the Apps, and/or using any of the Ethnus Services, you shall have affirmed your agreement to these Terms of Use.

1. Definitions

2. Modifications - Will Ethnus ever modify these Terms of Use?

3. Ethnus Services - What are the Ethnus Services?

4. Video Content and Services - How and when do you record videos?

5. Pricing, Payments, and Billing - How and when will I be billed for Ethnus Services?

6. Objectionable Content - What if I find content to be objectionable?

7. Customer Conduct

8. Intellectual Property

9. DMCA Policy

10. Reserved for Future Use

11. Resale of Services

12. Indemnification

13. Disclaimer of Warranties

14. Third Party Links and Products

15. Limitations of Liability

16. Exclusions and Limitations

17. General Terms

1. Definitions

"Consumer" means any individual or entity that uses any of the Ethnus Services. Where applicable, the term "Consumer" shall encompass all Ethnus Customers.

"Content" means all material, whether publicly posted or privately transmitted, available on or through any of the Ethnus Services.

"Customer" means, for purposes of this Terms of Use, You, a Job Seeker Customer.

"Customer Content" means any Content uploaded to and/or created through the Ethnus Services by a Ethnus Customer.

"Employer Customer" means an entity using Ethnus Services that is seeking to hire an individual as an employee and/or independent contractor to be employed by it directly.

"GDPR" means the European Union's General Data Protection Regulation.

"Job Seeker Customer" means an individual using Ethnus Services who is seeking to be employed as an employee or independent contractor by an employer.

"Profile Video" means a promotional video created by a Job Seeker Customer to promote themselves as a candidate employee and/or independent contractor. It is not an interview. The Job Seeker Customer completes this independently and on their own.

"Software" means any necessary software used in connection with the Ethnus Services.

"Ethnus Account" means an account associated with a Ethnus Customer who uses or has used Ethnus Services.

"Ethnus Content" means any Content excluding Customer Content and Video Content in which Ethnus does not participate.

"Ethnus Customer" means any person who uses or has used Ethnus Services including, but not limited to, Employer Customers, Job Seeker Customers, and Staffing Customers.

"Ethnus Services" means the suite of features, products and services offered through Ethnus, its Apps, its App Services, the Website, and the Website Services.

"Ethnus Trademarks" means any trademarks, tradenames, logos, and other commercial designs of Ethnus or licensed to Ethnus, whether or not formal registration exists including, but not limited to, "Ethnus."

"Staffing Clients" means third-party employer clients of Staffing Customers.

"Staffing Customer" means a staffing company using Ethnus Services that provides staffing services to their own Staffing Clients.

"Strategic Partners" means those trusted partners that Ethnus employs, engages, or retains to perform functions and/or provide services on its behalf.

"Sub Accounts" means subsidiary accounts created for or by an Employer Customer or Staffing Customer ("such as a consultant group or employer") under its primary account.

"Username" means the valid email address provided by each Ethnus Customer to be used as their username or login identification.

"Video Content" means any video content created by or associated with any Ethnus Customer accessible on and through Ethnus Services including, but not limited to, Profile Videos, Video Questions, Video Interviews, and Welcome Videos.

"Video Interview" means an interview completed through Ethnus Services using a video or "web" camera that an Employer Customer or Staffing Customer requests a Job Seeker Customer complete. A Video Interview may involve a Job Seeker Customer alone or with other participants from an Employer Customer or Staffing Customer. A Video Interview may be pre-recorded by a Job Seeker in response to questions or occur live at which time it would be recorded.

"Video Question" means a question recorded in video and audio that can be sent to potential employee and independent contractor candidates by an Employer Customer or Staffing Customer.

"Website" means all of the content, information and services (in any format whatsoever) accessible through the World Wide Web at the domain name Codemithra.com.

"Website Services" means the services provided by Ethnus through the website at the domain name Codemithra.com, hire.li, and any of our other websites that may be used from time to time